From 5ce9aab310a1e9577ee9770254ea6be3dd81dfaa Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 14:50:17 +0900 Subject: [PATCH 01/14] Feat: add search user api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 키워드로 유저아이디를 검색하는 api 구현 --- backend/controller/index.js | 7 +++--- backend/controller/search/index.js | 38 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 backend/controller/search/index.js diff --git a/backend/controller/index.js b/backend/controller/index.js index 58be8507..46d0c499 100644 --- a/backend/controller/index.js +++ b/backend/controller/index.js @@ -1,9 +1,8 @@ import express from 'express' +import searchRouter from './search' + const router = express.Router() -/* GET home page. */ -router.get('/', function (req, res, next) { - res.json({ success: true }) -}) +router.use('/search', searchRouter) module.exports = router diff --git a/backend/controller/search/index.js b/backend/controller/search/index.js new file mode 100644 index 00000000..1ed0c5ba --- /dev/null +++ b/backend/controller/search/index.js @@ -0,0 +1,38 @@ +const express = require('express') +const router = express.Router() + +const { ChannelConfig } = require('../../model/ChannelConfig') +const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') + +/* POST /api/search/uesr search user */ +router.post('/user', async (req, res, next) => { + try { + const keyword = req.body.keyword + const channelId = req.body.channelId + const workspaceId = req.body.workspaceId + + const userInfo = await WorkspaceUserInfo.find( + { + $or: [ + { fullName: new RegExp(keyword, 'i') }, + { displayName: new RegExp(keyword, 'i') }, + ], + workspaceId: workspaceId, + }, + { displayName: 1, profileUrl: 1, isActive: 1 }, + ).exec() + const existMember = await ChannelConfig.find( + { + workspaceUserInfoId: { $in: userInfo.map(el => el._id) }, + channelId: channelId, + }, + { _id: 1 }, + ) + + res.status(200).json({ success: true, result: { userInfo, existMember } }) + } catch (err) { + next(err) + } +}) + +module.exports = router From 0075f7c672a2d076314c4a9e5333f9ca85f798ed Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:07:48 +0900 Subject: [PATCH 02/14] Fix: fix typo in workspaceUserInfo model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit workspaceUserInfo 모델의 오타를 수정했습니다. --- backend/model/WorkspaceUserInfo.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/model/WorkspaceUserInfo.js b/backend/model/WorkspaceUserInfo.js index b63a9b15..2aa49bd3 100644 --- a/backend/model/WorkspaceUserInfo.js +++ b/backend/model/WorkspaceUserInfo.js @@ -40,7 +40,7 @@ const workspaceUserInfoSchema = mongoose.Schema( type: Schema.Types.ObjectId, ref: 'User', }, - workSpaceId: { + workspaceId: { type: Schema.Types.ObjectId, ref: 'Workspace', }, From 127c4bd581388b35eda7b7201e57c427b421d1d5 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:08:38 +0900 Subject: [PATCH 03/14] Fix: UserHistory model bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UserHistory의 모델 스키마를 수정 변경했습니다. --- backend/model/UserHistory.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/model/UserHistory.js b/backend/model/UserHistory.js index 309fd6c9..43811387 100644 --- a/backend/model/UserHistory.js +++ b/backend/model/UserHistory.js @@ -1,7 +1,7 @@ const mongoose = require('mongoose') const Schema = mongoose.Schema -const fileSchema = mongoose.Schema( +const userHistorySchema = mongoose.Schema( { userId: { type: Schema.Types.ObjectId, @@ -18,5 +18,5 @@ const fileSchema = mongoose.Schema( }, { timestamps: true }, ) -const File = mongoose.model('File', fileSchema) -module.exports = { File } +const UserHistory = mongoose.model('UserHistroy', userHistorySchema) +module.exports = { UserHistory } From 15292842596494f594cea1a1bdd14715621e9494 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:37:25 +0900 Subject: [PATCH 04/14] Feat: add channel list get api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채널 목록을 가져오는 api를 구현했습니다. --- backend/controller/channel/index.js | 46 +++++++++++++++++++++++++++++ backend/controller/index.js | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 backend/controller/channel/index.js diff --git a/backend/controller/channel/index.js b/backend/controller/channel/index.js new file mode 100644 index 00000000..6e98a6e1 --- /dev/null +++ b/backend/controller/channel/index.js @@ -0,0 +1,46 @@ +const express = require('express') +const router = express.Router() + +const { Channel } = require('../../model/Channel') +const { ChannelConfig } = require('../../model/ChannelConfig') + +/* GET /api/channle get channel list */ +router.get('/', async (req, res, next) => { + try { + const workspaceUserInfoId = req.query.workspaceUserInfoId + + const channelConfig = await ChannelConfig.find( + { + workspaceUserInfoId: workspaceUserInfoId, + }, + { channelId: 1, readChatId: 1, isMute: 1, notification: 1, sectionId: 1 }, + ).exec() + + const channel = await Channel.find( + { + _id: { $in: channelConfig.map(el => el.channelId) }, + }, + { _id: 1, title: 1, channelType: 1 }, + ).exec() + + const result = channel.map(el => { + let temp = {} + channelConfig.some(val => { + if (el._id.toString() == val.channelId.toString()) { + temp = { + ...JSON.parse(JSON.stringify(val)), + ...JSON.parse(JSON.stringify(el)), + } + return true + } + }) + return temp + }) + + res.status(200).json({ success: true, result: result }) + } catch (err) { + next(err) + } +}) + +module.exports = router diff --git a/backend/controller/index.js b/backend/controller/index.js index 46d0c499..6e86022d 100644 --- a/backend/controller/index.js +++ b/backend/controller/index.js @@ -1,8 +1,10 @@ import express from 'express' +import channelRouter from './channel' import searchRouter from './search' const router = express.Router() +router.use('/channel', channelRouter) router.use('/search', searchRouter) module.exports = router From 20a39d201fb46b452c844da73a01b981f62cb8a2 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:40:40 +0900 Subject: [PATCH 05/14] Feat: add channel header info get api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채널 헤더에 필요한 정보를 전달하는 api 구현 --- backend/controller/channel/index.js | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/backend/controller/channel/index.js b/backend/controller/channel/index.js index 6e98a6e1..7b2d09dc 100644 --- a/backend/controller/channel/index.js +++ b/backend/controller/channel/index.js @@ -1,8 +1,10 @@ const express = require('express') const router = express.Router() +const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') const { Channel } = require('../../model/Channel') const { ChannelConfig } = require('../../model/ChannelConfig') +const { Chat } = require('../../model/Chat') /* GET /api/channle get channel list */ router.get('/', async (req, res, next) => { @@ -43,4 +45,37 @@ router.get('/', async (req, res, next) => { } }) +/* GET /api/channle/{channelId}/info get channel header info */ +router.get('/:channelId/info', async (req, res, next) => { + try { + const channelId = req.params.channelId + + const pinned = await Chat.find({ pinned: true, channel: channelId }).exec() + const channelConfig = await ChannelConfig.find({ + channelId: channelId, + }).exec() + const workspaceUserInfo = await WorkspaceUserInfo.find({ + _id: { $in: channelConfig.map(el => el.workspaceUserInfoId) }, + }).exec() + + const channel = await Channel.find( + { + _id: channelId, + }, + { title: 1, topic: 1, channelType: 1 }, + ).exec() + const extraData = { + pinnedNum: pinned.length, + memberNum: workspaceUserInfo.length, + member: workspaceUserInfo, + } + + let result = { ...JSON.parse(JSON.stringify(channel[0])), ...extraData } + + res.status(200).json({ success: true, result }) + } catch (err) { + next(err) + } +}) + module.exports = router From 5809d39b23cd456f799e714a9047b70c2b5f9288 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:54:25 +0900 Subject: [PATCH 06/14] Feat: add invite user to channel post api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 유저를 채널에 초대하는 api를 구현했습니다. --- backend/controller/channel/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/backend/controller/channel/index.js b/backend/controller/channel/index.js index 7b2d09dc..9781752b 100644 --- a/backend/controller/channel/index.js +++ b/backend/controller/channel/index.js @@ -78,4 +78,29 @@ router.get('/:channelId/info', async (req, res, next) => { } }) +/* POST /api/channle/invite invite user to channel */ +router.post('/invite', async (req, res, next) => { + try { + const workspaceUserInfoId = req.body.workspaceUserInfoId + const channelId = req.body.channelId + + console.log(workspaceUserInfoId, channelId) + workspaceUserInfoId.forEach(el => { + const channelConfig = ChannelConfig({ + workspaceUserInfoId: el, + channelId: channelId, + isMute: false, + notification: 0, + sectionId: null, + }) + channelConfig.save() + }) + + res.status(200).json({ success: true }) + } catch (err) { + console.log(err) + next(err) + } +}) + module.exports = router From f96a1d0694086b5aa376dfbd005ab32710ec7b9e Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 15:58:27 +0900 Subject: [PATCH 07/14] Feat: add update channel mute option patch api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채널의 mute 옵션을 변경하는 api를 작성했습니다. --- backend/controller/channel/index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/controller/channel/index.js b/backend/controller/channel/index.js index 9781752b..647c5557 100644 --- a/backend/controller/channel/index.js +++ b/backend/controller/channel/index.js @@ -103,4 +103,25 @@ router.post('/invite', async (req, res, next) => { } }) +/* PATCH /api/channle/mute mute channel */ +router.patch('/mute', async (req, res, next) => { + try { + const workspaceUserInfoId = req.body.workspaceUserInfoId + const channelId = req.body.channelId + const isMute = req.body.isMute + + await ChannelConfig.updateOne( + { + workspaceUserInfoId: workspaceUserInfoId, + channelId: channelId, + }, + { isMute: isMute }, + ).exec() + + res.status(200).json({ success: true }) + } catch (err) { + next(err) + } +}) + module.exports = router From a6753f2bbbd86f334164e553e45e4b32b8171caf Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 18:31:32 +0900 Subject: [PATCH 08/14] Chore: separate channel contorller and router MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 채널의 라우터와 컨트롤러 파일을 분리했습니다. --- backend/controller/channel/channel.js | 122 ++++++++++++++++++++++++++ backend/controller/channel/index.js | 120 ++----------------------- 2 files changed, 127 insertions(+), 115 deletions(-) create mode 100644 backend/controller/channel/channel.js diff --git a/backend/controller/channel/channel.js b/backend/controller/channel/channel.js new file mode 100644 index 00000000..278b2f59 --- /dev/null +++ b/backend/controller/channel/channel.js @@ -0,0 +1,122 @@ +const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') +const { Channel } = require('../../model/Channel') +const { ChannelConfig } = require('../../model/ChannelConfig') +const { Chat } = require('../../model/Chat') + +/* GET /api/channle get channel list */ +const getChannelList = async (req, res, next) => { + try { + const workspaceUserInfoId = req.query.workspaceUserInfoId + + const channelConfig = await ChannelConfig.find( + { + workspaceUserInfoId: workspaceUserInfoId, + }, + { channelId: 1, readChatId: 1, isMute: 1, notification: 1, sectionId: 1 }, + ).lean() + + const channel = await Channel.find( + { + _id: { $in: channelConfig.map(el => el.channelId) }, + }, + { _id: 1, title: 1, channelType: 1 }, + ).lean() + + const result = channel.map(el => { + let temp = {} + channelConfig.some(val => { + if (el._id.toString() == val.channelId.toString()) { + temp = { ...val, ...el } + return true + } + }) + return temp + }) + + res.status(200).json({ success: true, result: result }) + } catch (err) { + next(err) + } +} + +const getChannelHeaderInfo = async (req, res, next) => { + try { + const channelId = req.params.channelId + + const pinned = await Chat.find({ pinned: true, channel: channelId }).exec() + const channelConfig = await ChannelConfig.find({ + channelId: channelId, + }).exec() + const workspaceUserInfo = await WorkspaceUserInfo.find({ + _id: { $in: channelConfig.map(el => el.workspaceUserInfoId) }, + }).exec() + + const channel = await Channel.find( + { + _id: channelId, + }, + { title: 1, topic: 1, channelType: 1 }, + ).exec() + const extraData = { + pinnedNum: pinned.length, + memberNum: workspaceUserInfo.length, + member: workspaceUserInfo, + } + + let result = { ...JSON.parse(JSON.stringify(channel[0])), ...extraData } + + res.status(200).json({ success: true, result }) + } catch (err) { + next(err) + } +} + +const inviteUser = (req, res, next) => { + try { + const workspaceUserInfoId = req.body.workspaceUserInfoId + const channelId = req.body.channelId + + workspaceUserInfoId.forEach(el => { + const channelConfig = ChannelConfig({ + workspaceUserInfoId: el, + channelId: channelId, + isMute: false, + notification: 0, + sectionId: null, + }) + channelConfig.save() + }) + + res.status(200).json({ success: true }) + } catch (err) { + console.log(err) + next(err) + } +} + +const muteChannel = async (req, res, next) => { + try { + const workspaceUserInfoId = req.body.workspaceUserInfoId + const channelId = req.body.channelId + const isMute = req.body.isMute + + await ChannelConfig.updateOne( + { + workspaceUserInfoId: workspaceUserInfoId, + channelId: channelId, + }, + { isMute: isMute }, + ).exec() + + res.status(200).json({ success: true }) + } catch (err) { + next(err) + } +} + +module.exports = { + getChannelList, + getChannelHeaderInfo, + inviteUser, + muteChannel, +} diff --git a/backend/controller/channel/index.js b/backend/controller/channel/index.js index 647c5557..a173dc40 100644 --- a/backend/controller/channel/index.js +++ b/backend/controller/channel/index.js @@ -1,127 +1,17 @@ const express = require('express') const router = express.Router() - -const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') -const { Channel } = require('../../model/Channel') -const { ChannelConfig } = require('../../model/ChannelConfig') -const { Chat } = require('../../model/Chat') +const channelController = require('./channel') /* GET /api/channle get channel list */ -router.get('/', async (req, res, next) => { - try { - const workspaceUserInfoId = req.query.workspaceUserInfoId - - const channelConfig = await ChannelConfig.find( - { - workspaceUserInfoId: workspaceUserInfoId, - }, - { channelId: 1, readChatId: 1, isMute: 1, notification: 1, sectionId: 1 }, - ).exec() - - const channel = await Channel.find( - { - _id: { $in: channelConfig.map(el => el.channelId) }, - }, - { _id: 1, title: 1, channelType: 1 }, - ).exec() - - const result = channel.map(el => { - let temp = {} - channelConfig.some(val => { - if (el._id.toString() == val.channelId.toString()) { - temp = { - ...JSON.parse(JSON.stringify(val)), - ...JSON.parse(JSON.stringify(el)), - } - return true - } - }) - return temp - }) - - res.status(200).json({ success: true, result: result }) - } catch (err) { - next(err) - } -}) +router.get('/', channelController.getChannelList) /* GET /api/channle/{channelId}/info get channel header info */ -router.get('/:channelId/info', async (req, res, next) => { - try { - const channelId = req.params.channelId - - const pinned = await Chat.find({ pinned: true, channel: channelId }).exec() - const channelConfig = await ChannelConfig.find({ - channelId: channelId, - }).exec() - const workspaceUserInfo = await WorkspaceUserInfo.find({ - _id: { $in: channelConfig.map(el => el.workspaceUserInfoId) }, - }).exec() - - const channel = await Channel.find( - { - _id: channelId, - }, - { title: 1, topic: 1, channelType: 1 }, - ).exec() - const extraData = { - pinnedNum: pinned.length, - memberNum: workspaceUserInfo.length, - member: workspaceUserInfo, - } - - let result = { ...JSON.parse(JSON.stringify(channel[0])), ...extraData } - - res.status(200).json({ success: true, result }) - } catch (err) { - next(err) - } -}) +router.get('/:channelId/info', channelController.getChannelHeaderInfo) /* POST /api/channle/invite invite user to channel */ -router.post('/invite', async (req, res, next) => { - try { - const workspaceUserInfoId = req.body.workspaceUserInfoId - const channelId = req.body.channelId - - console.log(workspaceUserInfoId, channelId) - workspaceUserInfoId.forEach(el => { - const channelConfig = ChannelConfig({ - workspaceUserInfoId: el, - channelId: channelId, - isMute: false, - notification: 0, - sectionId: null, - }) - channelConfig.save() - }) - - res.status(200).json({ success: true }) - } catch (err) { - console.log(err) - next(err) - } -}) +router.post('/invite', channelController.inviteUser) /* PATCH /api/channle/mute mute channel */ -router.patch('/mute', async (req, res, next) => { - try { - const workspaceUserInfoId = req.body.workspaceUserInfoId - const channelId = req.body.channelId - const isMute = req.body.isMute - - await ChannelConfig.updateOne( - { - workspaceUserInfoId: workspaceUserInfoId, - channelId: channelId, - }, - { isMute: isMute }, - ).exec() - - res.status(200).json({ success: true }) - } catch (err) { - next(err) - } -}) +router.patch('/mute', channelController.muteChannel) module.exports = router From f689ef4db4c1a3456a84be9a47625b5c4fef5c17 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 18:33:57 +0900 Subject: [PATCH 09/14] Chore: separate search contorller and router MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 검색 라우터와 컨트롤러의 파일을 분리했습니다. --- backend/controller/search/index.js | 34 ++------------------------- backend/controller/search/search.js | 36 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 32 deletions(-) create mode 100644 backend/controller/search/search.js diff --git a/backend/controller/search/index.js b/backend/controller/search/index.js index 1ed0c5ba..dff388ce 100644 --- a/backend/controller/search/index.js +++ b/backend/controller/search/index.js @@ -1,38 +1,8 @@ const express = require('express') const router = express.Router() - -const { ChannelConfig } = require('../../model/ChannelConfig') -const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') +const searchController = require('./search') /* POST /api/search/uesr search user */ -router.post('/user', async (req, res, next) => { - try { - const keyword = req.body.keyword - const channelId = req.body.channelId - const workspaceId = req.body.workspaceId - - const userInfo = await WorkspaceUserInfo.find( - { - $or: [ - { fullName: new RegExp(keyword, 'i') }, - { displayName: new RegExp(keyword, 'i') }, - ], - workspaceId: workspaceId, - }, - { displayName: 1, profileUrl: 1, isActive: 1 }, - ).exec() - const existMember = await ChannelConfig.find( - { - workspaceUserInfoId: { $in: userInfo.map(el => el._id) }, - channelId: channelId, - }, - { _id: 1 }, - ) - - res.status(200).json({ success: true, result: { userInfo, existMember } }) - } catch (err) { - next(err) - } -}) +router.post('/user', searchController.searchUser) module.exports = router diff --git a/backend/controller/search/search.js b/backend/controller/search/search.js new file mode 100644 index 00000000..142257a4 --- /dev/null +++ b/backend/controller/search/search.js @@ -0,0 +1,36 @@ +const { ChannelConfig } = require('../../model/ChannelConfig') +const { WorkspaceUserInfo } = require('../../model/WorkspaceUserInfo') + +const searchUser = async (req, res, next) => { + try { + const keyword = req.body.keyword + const channelId = req.body.channelId + const workspaceId = req.body.workspaceId + + const userInfo = await WorkspaceUserInfo.find( + { + $or: [ + { fullName: new RegExp(keyword, 'i') }, + { displayName: new RegExp(keyword, 'i') }, + ], + workspaceId: workspaceId, + }, + { displayName: 1, profileUrl: 1, isActive: 1 }, + ).exec() + const existMember = await ChannelConfig.find( + { + workspaceUserInfoId: { $in: userInfo.map(el => el._id) }, + channelId: channelId, + }, + { _id: 1 }, + ) + + res.status(200).json({ success: true, result: { userInfo, existMember } }) + } catch (err) { + next(err) + } +} + +module.exports = { + searchUser, +} From fe84a87b8389656d760e6d06fa826d7678ae8586 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 18:36:27 +0900 Subject: [PATCH 10/14] Chore : rename router to controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 라우터에서 컨트롤러로 이름을 변경했습니다. --- backend/controller/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/controller/index.js b/backend/controller/index.js index 6e86022d..73c74a46 100644 --- a/backend/controller/index.js +++ b/backend/controller/index.js @@ -1,10 +1,10 @@ import express from 'express' -import channelRouter from './channel' -import searchRouter from './search' +import channelCotroller from './channel' +import searchCotroller from './search' const router = express.Router() -router.use('/channel', channelRouter) -router.use('/search', searchRouter) +router.use('/channel', channelCotroller) +router.use('/search', searchCotroller) module.exports = router From abaa5d1712993209cd579ee98448bd28fa0f9137 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 18:39:52 +0900 Subject: [PATCH 11/14] Fix: merge DB data bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit db 검색후 나온 결과 데이터를 merge하면서 발생하는 오류를 수정했습니다. --- backend/controller/channel/channel.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/backend/controller/channel/channel.js b/backend/controller/channel/channel.js index 278b2f59..f5a80cb8 100644 --- a/backend/controller/channel/channel.js +++ b/backend/controller/channel/channel.js @@ -46,24 +46,24 @@ const getChannelHeaderInfo = async (req, res, next) => { const pinned = await Chat.find({ pinned: true, channel: channelId }).exec() const channelConfig = await ChannelConfig.find({ channelId: channelId, - }).exec() + }).lean() const workspaceUserInfo = await WorkspaceUserInfo.find({ _id: { $in: channelConfig.map(el => el.workspaceUserInfoId) }, - }).exec() + }).lean() - const channel = await Channel.find( + const channel = await Channel.findOne( { _id: channelId, }, { title: 1, topic: 1, channelType: 1 }, - ).exec() + ).lean() const extraData = { pinnedNum: pinned.length, memberNum: workspaceUserInfo.length, member: workspaceUserInfo, } - let result = { ...JSON.parse(JSON.stringify(channel[0])), ...extraData } + let result = { ...channel, ...extraData } res.status(200).json({ success: true, result }) } catch (err) { @@ -89,7 +89,6 @@ const inviteUser = (req, res, next) => { res.status(200).json({ success: true }) } catch (err) { - console.log(err) next(err) } } From c444e56a031a783df93942036d54bc3904bcaad3 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 18:44:29 +0900 Subject: [PATCH 12/14] Fix: search user bug fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이미 존재하는지 조회 후 리턴하는 값을 변경했습니다. --- backend/controller/search/search.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/controller/search/search.js b/backend/controller/search/search.js index 142257a4..e3bde492 100644 --- a/backend/controller/search/search.js +++ b/backend/controller/search/search.js @@ -16,14 +16,14 @@ const searchUser = async (req, res, next) => { workspaceId: workspaceId, }, { displayName: 1, profileUrl: 1, isActive: 1 }, - ).exec() + ).lean() const existMember = await ChannelConfig.find( { workspaceUserInfoId: { $in: userInfo.map(el => el._id) }, channelId: channelId, }, - { _id: 1 }, - ) + { _id: 0, workspaceUserInfoId: 1 }, + ).lean() res.status(200).json({ success: true, result: { userInfo, existMember } }) } catch (err) { From 97d14ffbf1be59046baf8d6241302a46528ea7df Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 19:00:04 +0900 Subject: [PATCH 13/14] Fix: change channelconfig data result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit channelconfig의 _id의 결과값이 리턴되지 않도록 변경했습니다. --- backend/controller/channel/channel.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/controller/channel/channel.js b/backend/controller/channel/channel.js index f5a80cb8..a46a0fc6 100644 --- a/backend/controller/channel/channel.js +++ b/backend/controller/channel/channel.js @@ -12,7 +12,14 @@ const getChannelList = async (req, res, next) => { { workspaceUserInfoId: workspaceUserInfoId, }, - { channelId: 1, readChatId: 1, isMute: 1, notification: 1, sectionId: 1 }, + { + _id: 0, + channelId: 1, + readChatId: 1, + isMute: 1, + notification: 1, + sectionId: 1, + }, ).lean() const channel = await Channel.find( From 66e558c736dd9fbe51dac96afbb14f6832c7ce54 Mon Sep 17 00:00:00 2001 From: Ryou_Changyu Date: Thu, 26 Nov 2020 19:48:10 +0900 Subject: [PATCH 14/14] Fix: update channel controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 리뷰를 반영해 채널 컨트롤러 코드 수정했습니다. --- backend/controller/channel/channel.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/backend/controller/channel/channel.js b/backend/controller/channel/channel.js index a46a0fc6..000468cb 100644 --- a/backend/controller/channel/channel.js +++ b/backend/controller/channel/channel.js @@ -30,17 +30,13 @@ const getChannelList = async (req, res, next) => { ).lean() const result = channel.map(el => { - let temp = {} - channelConfig.some(val => { - if (el._id.toString() == val.channelId.toString()) { - temp = { ...val, ...el } - return true - } - }) - return temp + const [currentConfig] = channelConfig.filter( + val => val.channelId.toString() === el._id.toString(), + ) + return { ...currentConfig, ...el } }) - res.status(200).json({ success: true, result: result }) + res.status(200).json({ success: true, result }) } catch (err) { next(err) } @@ -50,7 +46,7 @@ const getChannelHeaderInfo = async (req, res, next) => { try { const channelId = req.params.channelId - const pinned = await Chat.find({ pinned: true, channel: channelId }).exec() + const pinned = await Chat.find({ pinned: true, channel: channelId }) const channelConfig = await ChannelConfig.find({ channelId: channelId, }).lean() @@ -65,7 +61,7 @@ const getChannelHeaderInfo = async (req, res, next) => { { title: 1, topic: 1, channelType: 1 }, ).lean() const extraData = { - pinnedNum: pinned.length, + pinnedCount: pinned.length, memberNum: workspaceUserInfo.length, member: workspaceUserInfo, } @@ -86,7 +82,7 @@ const inviteUser = (req, res, next) => { workspaceUserInfoId.forEach(el => { const channelConfig = ChannelConfig({ workspaceUserInfoId: el, - channelId: channelId, + channelId, isMute: false, notification: 0, sectionId: null, @@ -108,11 +104,11 @@ const muteChannel = async (req, res, next) => { await ChannelConfig.updateOne( { - workspaceUserInfoId: workspaceUserInfoId, - channelId: channelId, + workspaceUserInfoId, + channelId, }, { isMute: isMute }, - ).exec() + ) res.status(200).json({ success: true }) } catch (err) {