2017-10-31 08:11:22 -06:00
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
|
|
|
import $ from 'cafy';
|
2018-02-03 22:52:33 -07:00
|
|
|
import Channel, { IChannel, pack } from '../../models/channel';
|
2017-10-31 08:11:22 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a channel
|
|
|
|
*
|
|
|
|
* @param {any} params
|
|
|
|
* @param {any} user
|
|
|
|
* @return {Promise<any>}
|
|
|
|
*/
|
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
|
|
// Get 'channel_id' parameter
|
|
|
|
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
|
|
|
if (channelIdErr) return rej('invalid channel_id param');
|
|
|
|
|
|
|
|
// Fetch channel
|
|
|
|
const channel: IChannel = await Channel.findOne({
|
|
|
|
_id: channelId
|
|
|
|
});
|
|
|
|
|
|
|
|
if (channel === null) {
|
|
|
|
return rej('channel not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize
|
2018-02-01 16:21:30 -07:00
|
|
|
res(await pack(channel, user));
|
2017-10-31 08:11:22 -06:00
|
|
|
});
|