diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-10-30 17:30:32 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-10-30 17:30:32 +0900 |
| commit | 77528f022d2e9f76298331b55303cfc42359c7af (patch) | |
| tree | 043b951c7ab28de28f2f4407b9eab6a0cd834019 /src/api/endpoints | |
| parent | i18n (diff) | |
| download | sharkey-77528f022d2e9f76298331b55303cfc42359c7af.tar.gz sharkey-77528f022d2e9f76298331b55303cfc42359c7af.tar.bz2 sharkey-77528f022d2e9f76298331b55303cfc42359c7af.zip | |
wip
Diffstat (limited to 'src/api/endpoints')
| -rw-r--r-- | src/api/endpoints/bbs/threads/create.ts | 29 |
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)); +}); |