From f9d0e9ae5cb8447e54afd3165d98383b8e6ab33b Mon Sep 17 00:00:00 2001 From: Troplo Date: Sun, 22 Nov 2020 17:48:11 +1100 Subject: [PATCH] 0.177-prerelease (UPGRADE FROM SEQUELIZE V3 to V5, REWRITE MODELS) --- controllers/conversation.js | 16 +- controllers/message.js | 6 +- controllers/user.js | 6 +- frontend/src/components/EmojiSelector.vue | 2 +- frontend/src/components/WallPost.vue | 11 - .../routes/AdminModerationReports.vue | 2 +- frontend/src/components/routes/UserWall.vue | 3 - models/Notification.js | 111 +++-- models/ban.js | 112 +++-- models/bannedUsernames.js | 3 +- models/category.js | 8 +- models/inventory.js | 14 +- models/ip.js | 39 +- models/item.js | 38 +- models/itemcategory.js | 11 +- models/log.js | 11 + models/poll_answer.js | 12 +- models/poll_question.js | 15 +- models/poll_vote.js | 17 +- models/post.js | 99 ++-- models/post_notification.js | 8 +- models/report.js | 51 +-- models/state.js | 2 +- models/team.js | 146 ++---- models/teamWall.js | 71 ++- models/team_invite.js | 41 +- models/team_member_role.js | 56 +-- models/team_members.js | 33 +- models/team_roles.js | 106 +---- models/thread.js | 165 ++++--- models/user.js | 431 ++++++++---------- models/userWall.js | 69 ++- package.json | 2 +- routes/UnbanRequest.js | 2 +- routes/admin.js | 4 +- routes/avatar.js | 2 +- routes/ban.js | 2 +- routes/category.js | 6 +- routes/log.js | 4 +- routes/marketplace.js | 2 +- routes/poll.js | 6 +- routes/post.js | 10 +- routes/report.js | 6 +- routes/search.js | 12 +- routes/team.js | 9 +- routes/team_admin.js | 2 +- routes/team_wall.js | 6 +- routes/thread.js | 8 +- routes/user.js | 4 +- routes/user_wall.js | 4 +- routes/userutils.js | 2 +- yarn.lock | 127 ++---- 52 files changed, 771 insertions(+), 1164 deletions(-) diff --git a/controllers/conversation.js b/controllers/conversation.js index 9f25ecb..11386c4 100644 --- a/controllers/conversation.js +++ b/controllers/conversation.js @@ -2,8 +2,8 @@ let Type = require('../lib/validation/type'); let validationError = require('../lib/errors/validationError'); let { User, - Conversation, - Message, + Conversation, + Message, UserConversation, Sequelize } = require('../models'); @@ -18,7 +18,7 @@ exports.create = async function (userIds, name) { let users; userIdsSet.forEach(id => { - userPromises.push(User.findById(id)); + userPromises.push(User.findByPk(id)); }); users = (await Promise.all(userPromises)).filter(user => user !== null); @@ -156,7 +156,7 @@ exports.get = async function (userId, conversationId, page) { offset = 0; } - let conversation = await Conversation.findById(conversationId, { + let conversation = await Conversation.findByPk(conversationId, { include: [ { model: User, @@ -191,7 +191,7 @@ exports.get = async function (userId, conversationId, page) { }; exports.getUserIds = async function (conversationId) { - let conversation = await Conversation.findById(conversationId, { + let conversation = await Conversation.findByPk(conversationId, { include: [{ model: User }] }); @@ -222,10 +222,10 @@ exports.updateLastRead = async function (conversationId, userId) { }; exports.updateName = async function (conversationId, userId, name) { - let conversation = await Conversation.findById(conversationId, { + let conversation = await Conversation.findByPk(conversationId, { include: [{ model: User }] }); - + if( !conversation || conversation.Users.find(u => u.id === userId) === undefined @@ -240,4 +240,4 @@ exports.updateName = async function (conversationId, userId, name) { }); return true; -}; \ No newline at end of file +}; diff --git a/controllers/message.js b/controllers/message.js index 75bdb2d..02793a6 100644 --- a/controllers/message.js +++ b/controllers/message.js @@ -10,7 +10,7 @@ let { Message, User, Conversation, Sequelize } = require('../models'); exports.create = async function (params) { let { content, userId, conversationId } = params; - let user = await User.findById(userId); + let user = await User.findByPk(userId); if(!user) { throw validationError({ message: 'User does not exist', @@ -18,7 +18,7 @@ exports.create = async function (params) { }); } - let conversation = await Conversation.findById(conversationId, { + let conversation = await Conversation.findByPk(conversationId, { include: [{ model: User, where: { id: userId } @@ -37,4 +37,4 @@ exports.create = async function (params) { await Conversation.update({ updatedAt: new Date() }, { where: { id: conversationId } }); return message; -} \ No newline at end of file +} diff --git a/controllers/user.js b/controllers/user.js index 42829a1..a52215b 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -11,7 +11,7 @@ exports.create = async function (username , password) { }; exports.get = async function (userId) { - let user = await User.findById(userId, { + let user = await User.findByPk(userId, { attributes: { exclude: ['hash'] } }); @@ -48,7 +48,7 @@ exports.getAllBeginningWith = async function (username) { } exports.login = async function (username, password) { - let user = await User.findById({ + let user = await User.findByPk({ where: { username } }); @@ -73,4 +73,4 @@ exports.login = async function (username, password) { }); } } -}; \ No newline at end of file +}; diff --git a/frontend/src/components/EmojiSelector.vue b/frontend/src/components/EmojiSelector.vue index 84248aa..2bb9549 100644 --- a/frontend/src/components/EmojiSelector.vue +++ b/frontend/src/components/EmojiSelector.vue @@ -47,7 +47,7 @@ '👶' , '👦' , '👧' , '👨' , '👩' , '👱‍♀️' , '👱' , '👴' , '👵' , '👲' , '👳‍♀️' , '👳' , '👮‍♀️' , '👮', '💁', '💁‍♂️', '🙅', '🙅‍♂️', '🙆', '🙆‍♂️', '🙋', '🙋‍♂️', '💃', '🕺', '👯', '👯‍♂️', '🚶‍♀️', '🚶', '🏃‍♀️' ]}, { title: 'animals', emojis: [ - '🐶' , '🐱' , '🐭' , '🐹' , '🐰' , '🦊' , '🐻' , '🐼' , '🐨' , '🐯' , '🦁' , '🐮' , '🐷' , '🐽' , '🐸' , '🐵' , '🙊' , '🙉' , '🙊' , '🐒' , '🐔' , '🐧' , '🐦' , '🐤' , '🐣' , '🐥' , '🦆' , '🦅' , '🦉' , '🦇' , '🐺' , '🐗' , '🐴' , '🦄' , '🐝' , '🐛' , '🦋' , '🐌' , '🐞' , '🐜' , '🕷' , '🐢' , '🐍' + '🐶' , '🐱' , '🐭' , '🐹' , '🐰' , '🦊' , '🐻' , '🐼' , '🐨' , '🐯' , '🦁' , '🐮' , '🐷' , '🐽' , '🐸' , '🐵' , '🙊' , '🙉', '🐒' , '🐔' , '🐧' , '🐦' , '🐤' , '🐣' , '🐥' , '🦆' , '🦅' , '🦉' , '🦇' , '🐺' , '🐗' , '🐴' , '🦄' , '🐝' , '🐛' , '🦋' , '🐌' , '🐞' , '🐜' , '🕷' , '🐢' , '🐍' ]}, ] } diff --git a/frontend/src/components/WallPost.vue b/frontend/src/components/WallPost.vue index 33b250c..cf6ef59 100644 --- a/frontend/src/components/WallPost.vue +++ b/frontend/src/components/WallPost.vue @@ -15,13 +15,6 @@ :class='{"post__remove_icon--show": showSelect && !post.removed}' @click.stop='toggleSelected' /> - -
-

Copy this URL to share the post

- -
- -
@@ -70,8 +63,6 @@