summaryrefslogtreecommitdiff
path: root/src/api/endpoints
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-31 23:11:22 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-31 23:11:22 +0900
commitf87ec61e96a8c1f070abefc6a3b5f7e68e24705d (patch)
treebf0c993b21462bab2845281049783bba081a5165 /src/api/endpoints
parentwip (diff)
downloadsharkey-f87ec61e96a8c1f070abefc6a3b5f7e68e24705d.tar.gz
sharkey-f87ec61e96a8c1f070abefc6a3b5f7e68e24705d.tar.bz2
sharkey-f87ec61e96a8c1f070abefc6a3b5f7e68e24705d.zip
wip
Diffstat (limited to 'src/api/endpoints')
-rw-r--r--src/api/endpoints/channels/show.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/api/endpoints/channels/show.ts b/src/api/endpoints/channels/show.ts
new file mode 100644
index 0000000000..8861e54594
--- /dev/null
+++ b/src/api/endpoints/channels/show.ts
@@ -0,0 +1,31 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import { default as Channel, IChannel } from '../../models/channel';
+import serialize from '../../serializers/channel';
+
+/**
+ * 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
+ res(await serialize(channel, user));
+});