wip
This commit is contained in:
parent
9aed3d21c9
commit
77528f022d
8 changed files with 149 additions and 12 deletions
29
src/api/endpoints/bbs/threads/create.ts
Normal file
29
src/api/endpoints/bbs/threads/create.ts
Normal file
|
|
@ -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));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue