Browse Source

Add attrbiute 'picture' to includes, use TEXT rather than STRING data type

sbkwgh 7 years ago
parent
commit
65910ef0c3
5 changed files with 10 additions and 10 deletions
  1. 1 1
      migrations/20171203220305-add-picture-column.js
  2. 3 3
      models/post.js
  3. 4 4
      models/thread.js
  4. 1 1
      models/user.js
  5. 1 1
      routes/category.js

+ 1 - 1
migrations/20171203220305-add-picture-column.js

@@ -3,7 +3,7 @@
 module.exports = {
   up: (queryInterface, Sequelize) => {
     return queryInterface.addColumn('users', 'picture', {
-      type: Sequelize.STRING
+      type: Sequelize.TEXT
     })
   },
 

+ 3 - 3
models/post.js

@@ -53,12 +53,12 @@ module.exports = (sequelize, DataTypes) => {
 				let models = sequelize.models
 
 				return [
-					{ model: models.User, attributes: ['username', 'createdAt', 'id', 'color'] },
-					{ model: models.User, as: 'Likes', attributes: ['username', 'createdAt', 'id', 'color'] },
+					{ model: models.User, attributes: ['username', 'createdAt', 'id', 'color', 'picture'] },
+					{ model: models.User, as: 'Likes', attributes: ['username', 'createdAt', 'id', 'color', 'picture'] },
 					{ model: models.Thread, include: [models.Category]} ,
 					{
 						model: models.Post, as: 'Replies', include:
-						[{ model: models.User, attributes: ['username', 'id', 'color'] }]	
+						[{ model: models.User, attributes: ['username', 'id', 'color', 'picture'] }]	
 					}
 				]
 			},

+ 4 - 4
models/thread.js

@@ -101,7 +101,7 @@ module.exports = (sequelize, DataTypes) => {
 				let models = sequelize.models
 
 				return [
-					{ model: models.User, attributes: ['username', 'createdAt', 'color', 'updatedAt', 'id'] }, 
+					{ model: models.User, attributes: ['username', 'createdAt', 'color', 'picture', 'updatedAt', 'id'] }, 
 					models.Category,
 					{ 
 						model: models.Post, 
@@ -110,11 +110,11 @@ module.exports = (sequelize, DataTypes) => {
 						limit,
 						include: [
 							{ model: models.Thread, attributes: ['slug'] }, 
-							{ model: models.User, as: 'Likes', attributes: ['username', 'createdAt', 'id', 'color'] },
-							{ model: models.User, attributes: ['username', 'createdAt', 'id', 'color'] }, 
+							{ model: models.User, as: 'Likes', attributes: ['username', 'createdAt', 'id', 'color', 'picture'] },
+							{ model: models.User, attributes: ['username', 'createdAt', 'id', 'color', 'picture'] }, 
 							{
 								model: models.Post, as: 'Replies', include:
-								[{ model: models.User, attributes: ['username', 'id', 'color'] }]	
+								[{ model: models.User, attributes: ['username', 'id', 'color', 'picture'] }]	
 							}
 						]
 					}

+ 1 - 1
models/user.js

@@ -61,7 +61,7 @@ module.exports = (sequelize, DataTypes) => {
 			defaultValue: false
 		},
 		picture: {
-			type: DataTypes.STRING,
+			type: DataTypes.TEXT,
 			validate: {
 				isString (val) {
 					if(typeof val !== 'string') {

+ 1 - 1
routes/category.js

@@ -37,7 +37,7 @@ router.get('/:category', async (req, res) => {
 				where: {},
 				include: [
 					Category,
-					{ model: User, attributes: ['username', 'createdAt', 'id', 'color'] }, 
+					{ model: User, attributes: ['username', 'createdAt', 'id', 'color', 'picture'] }, 
 					{
 						model: Post, limit: 1, order: [['id', order]], include:
 						[{ model: User, attributes: ['username', 'id'] }]