summaryrefslogtreecommitdiff
path: root/src/api/endpoints/channels/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-31 22:35:31 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-31 22:35:31 +0900
commit5efb52b9f563ae7d6b5383d054a6c21fee676b68 (patch)
tree96c4bf8ce8403e3a5dd75f10f7f3c1193cf2bbca /src/api/endpoints/channels/create.ts
parentFix indent (diff)
downloadmisskey-5efb52b9f563ae7d6b5383d054a6c21fee676b68.tar.gz
misskey-5efb52b9f563ae7d6b5383d054a6c21fee676b68.tar.bz2
misskey-5efb52b9f563ae7d6b5383d054a6c21fee676b68.zip
wip
Diffstat (limited to 'src/api/endpoints/channels/create.ts')
-rw-r--r--src/api/endpoints/channels/create.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/api/endpoints/channels/create.ts b/src/api/endpoints/channels/create.ts
new file mode 100644
index 0000000000..74b089dfc3
--- /dev/null
+++ b/src/api/endpoints/channels/create.ts
@@ -0,0 +1,29 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import Channel from '../../models/channel';
+import serialize from '../../serializers/channel';
+
+/**
+ * Create a channel
+ *
+ * @param {any} params
+ * @param {any} user
+ * @return {Promise<any>}
+ */
+module.exports = async (params, user) => new Promise(async (res, rej) => {
+ // Get 'title' parameter
+ const [title, titleErr] = $(params.title).string().range(1, 100).$;
+ if (titleErr) return rej('invalid title param');
+
+ // Create a channel
+ const channel = await Channel.insert({
+ created_at: new Date(),
+ user_id: user._id,
+ title: title
+ });
+
+ // Response
+ res(await serialize(channel));
+});