summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/channels/show.ts
blob: 1bba63d490930199d22457fb4359b6bc4d866aa4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
 * Module dependencies
 */
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Channel, { IChannel, pack } from '../../../../models/channel';

/**
 * Show a channel
 */
module.exports = (params, user) => new Promise(async (res, rej) => {
	// Get 'channelId' parameter
	const [channelId, channelIdErr] = $.type(ID).get(params.channelId);
	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));
});