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