hippofish/src/server/api/endpoints/channels/show.ts
2018-03-29 14:48:47 +09:00

30 lines
645 B
TypeScript

/**
* Module dependencies
*/
import $ from 'cafy';
import Channel, { IChannel, pack } from '../../models/channel';
/**
* Show a channel
*
* @param {any} params
* @param {any} user
* @return {Promise<any>}
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'channelId' parameter
const [channelId, channelIdErr] = $(params.channelId).id().$;
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));
});