This commit is contained in:
syuilo
2017-10-30 17:30:32 +09:00
parent 9aed3d21c9
commit 77528f022d
8 changed files with 149 additions and 12 deletions

View 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));
});