From e6eb1b2ae1c38b335ff4755d35a33a0ca4450454 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 19 May 2018 07:33:34 +0900 Subject: Clean up --- src/server/api/endpoints/channels.ts | 58 ------------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 src/server/api/endpoints/channels.ts (limited to 'src/server/api/endpoints/channels.ts') diff --git a/src/server/api/endpoints/channels.ts b/src/server/api/endpoints/channels.ts deleted file mode 100644 index ceef4b9cb9..0000000000 --- a/src/server/api/endpoints/channels.ts +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; import ID from '../../../cafy-id'; -import Channel, { pack } from '../../../models/channel'; - -/** - * Get all channels - * - * @param {any} params - * @param {any} me - * @return {Promise} - */ -module.exports = (params, me) => new Promise(async (res, rej) => { - // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).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'); - } - - // Construct query - const sort = { - _id: -1 - }; - const query = {} as any; - if (sinceId) { - sort._id = 1; - query._id = { - $gt: sinceId - }; - } else if (untilId) { - query._id = { - $lt: untilId - }; - } - - // Issue query - const channels = await Channel - .find(query, { - limit: limit, - sort: sort - }); - - // Serialize - res(await Promise.all(channels.map(async channel => - await pack(channel, me)))); -}); -- cgit v1.2.3-freya