summaryrefslogtreecommitdiff
path: root/src/api/endpoints/bbs/threads
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/bbs/threads')
-rw-r--r--src/api/endpoints/bbs/threads/create.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/api/endpoints/bbs/threads/create.ts b/src/api/endpoints/bbs/threads/create.ts
new file mode 100644
index 0000000000..71d61d8711
--- /dev/null
+++ b/src/api/endpoints/bbs/threads/create.ts
@@ -0,0 +1,29 @@
+/**
+ * Module dependencies
+ */
+import $ from 'cafy';
+import Thread from '../../../models/bbs-thread';
+import serialize from '../../../serializers/bbs-thread';
+
+/**
+ * Create a thread
+ *
+ * @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 thread
+ const thread = await Thread.insert({
+ created_at: new Date(),
+ user_id: user._id,
+ title: title
+ });
+
+ // Response
+ res(await serialize(thread));
+});