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