diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-05-19 07:33:34 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-05-19 07:33:34 +0900 |
| commit | e6eb1b2ae1c38b335ff4755d35a33a0ca4450454 (patch) | |
| tree | f10a35f91071e36f787f77c242b127b7ad01c416 /src/server/api/endpoints/channels | |
| parent | Fix (diff) | |
| download | sharkey-e6eb1b2ae1c38b335ff4755d35a33a0ca4450454.tar.gz sharkey-e6eb1b2ae1c38b335ff4755d35a33a0ca4450454.tar.bz2 sharkey-e6eb1b2ae1c38b335ff4755d35a33a0ca4450454.zip | |
Clean up
Diffstat (limited to 'src/server/api/endpoints/channels')
| -rw-r--r-- | src/server/api/endpoints/channels/create.ts | 35 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/notes.ts | 74 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/show.ts | 26 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/unwatch.ts | 56 | ||||
| -rw-r--r-- | src/server/api/endpoints/channels/watch.ts | 54 |
5 files changed, 0 insertions, 245 deletions
diff --git a/src/server/api/endpoints/channels/create.ts b/src/server/api/endpoints/channels/create.ts deleted file mode 100644 index 0e3c9dc5ac..0000000000 --- a/src/server/api/endpoints/channels/create.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Channel from '../../../../models/channel'; -import Watching from '../../../../models/channel-watching'; -import { pack } from '../../../../models/channel'; - -/** - * Create a channel - */ -module.exports = async (params, user) => new Promise(async (res, rej) => { - // Get 'title' parameter - const [title, titleErr] = $.str.range(1, 100).get(params.title); - if (titleErr) return rej('invalid title param'); - - // Create a channel - const channel = await Channel.insert({ - createdAt: new Date(), - userId: user._id, - title: title, - index: 0, - watchingCount: 1 - }); - - // Response - res(await pack(channel)); - - // Create Watching - await Watching.insert({ - createdAt: new Date(), - userId: user._id, - channelId: channel._id - }); -}); diff --git a/src/server/api/endpoints/channels/notes.ts b/src/server/api/endpoints/channels/notes.ts deleted file mode 100644 index 463152e74a..0000000000 --- a/src/server/api/endpoints/channels/notes.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import { default as Channel, IChannel } from '../../../../models/channel'; -import Note, { pack } from '../../../../models/note'; - -/** - * Show a notes of a channel - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 1000, limitErr] = $.num.optional().range(1, 1000).get(params.limit); - if (limitErr) return rej('invalid limit param'); - - // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); - if (sinceIdErr) return rej('invalid sinceId param'); - - // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); - if (untilIdErr) return rej('invalid untilId param'); - - // Check if both of sinceId and untilId is specified - if (sinceId && untilId) { - return rej('cannot set sinceId and untilId'); - } - - // Get 'channelId' parameter - const [channelId, channelIdErr] = $.type(ID).get(params.channelId); - if (channelIdErr) return rej('invalid channelId param'); - - // Fetch channel - const channel: IChannel = await Channel.findOne({ - _id: channelId - }); - - if (channel === null) { - return rej('channel not found'); - } - - //#region Construct query - const sort = { - _id: -1 - }; - - const query = { - channelId: channel._id - } as any; - - if (sinceId) { - sort._id = 1; - query._id = { - $gt: sinceId - }; - } else if (untilId) { - query._id = { - $lt: untilId - }; - } - //#endregion Construct query - - // Issue query - const notes = await Note - .find(query, { - limit: limit, - sort: sort - }); - - // Serialize - res(await Promise.all(notes.map(async (note) => - await pack(note, user) - ))); -}); diff --git a/src/server/api/endpoints/channels/show.ts b/src/server/api/endpoints/channels/show.ts deleted file mode 100644 index 1bba63d490..0000000000 --- a/src/server/api/endpoints/channels/show.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import Channel, { IChannel, pack } from '../../../../models/channel'; - -/** - * Show a channel - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channelId' parameter - const [channelId, channelIdErr] = $.type(ID).get(params.channelId); - if (channelIdErr) return rej('invalid channelId param'); - - // Fetch channel - const channel: IChannel = await Channel.findOne({ - _id: channelId - }); - - if (channel === null) { - return rej('channel not found'); - } - - // Serialize - res(await pack(channel, user)); -}); diff --git a/src/server/api/endpoints/channels/unwatch.ts b/src/server/api/endpoints/channels/unwatch.ts deleted file mode 100644 index f7dddff461..0000000000 --- a/src/server/api/endpoints/channels/unwatch.ts +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import Channel from '../../../../models/channel'; -import Watching from '../../../../models/channel-watching'; - -/** - * Unwatch a channel - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channelId' parameter - const [channelId, channelIdErr] = $.type(ID).get(params.channelId); - if (channelIdErr) return rej('invalid channelId param'); - - //#region Fetch channel - const channel = await Channel.findOne({ - _id: channelId - }); - - if (channel === null) { - return rej('channel not found'); - } - //#endregion - - //#region Check whether not watching - const exist = await Watching.findOne({ - userId: user._id, - channelId: channel._id, - deletedAt: { $exists: false } - }); - - if (exist === null) { - return rej('already not watching'); - } - //#endregion - - // Delete watching - await Watching.update({ - _id: exist._id - }, { - $set: { - deletedAt: new Date() - } - }); - - // Send response - res(); - - // Decrement watching count - Channel.update(channel._id, { - $inc: { - watchingCount: -1 - } - }); -}); diff --git a/src/server/api/endpoints/channels/watch.ts b/src/server/api/endpoints/channels/watch.ts deleted file mode 100644 index 34243ff68b..0000000000 --- a/src/server/api/endpoints/channels/watch.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import Channel from '../../../../models/channel'; -import Watching from '../../../../models/channel-watching'; - -/** - * Watch a channel - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'channelId' parameter - const [channelId, channelIdErr] = $.type(ID).get(params.channelId); - if (channelIdErr) return rej('invalid channelId param'); - - //#region Fetch channel - const channel = await Channel.findOne({ - _id: channelId - }); - - if (channel === null) { - return rej('channel not found'); - } - //#endregion - - //#region Check whether already watching - const exist = await Watching.findOne({ - userId: user._id, - channelId: channel._id, - deletedAt: { $exists: false } - }); - - if (exist !== null) { - return rej('already watching'); - } - //#endregion - - // Create Watching - await Watching.insert({ - createdAt: new Date(), - userId: user._id, - channelId: channel._id - }); - - // Send response - res(); - - // Increment watching count - Channel.update(channel._id, { - $inc: { - watchingCount: 1 - } - }); -}); |