Sharkey/src/api/endpoints/othello/sessions/create.ts

19 lines
440 B
TypeScript
Raw Normal View History

2018-03-07 01:54:56 +09:00
import rndstr from 'rndstr';
import Session, { pack } from '../../../models/othello-session';
module.exports = (params, user) => new Promise(async (res, rej) => {
// 以前のセッションはすべて削除しておく
await Session.remove({
user_id: user._id
});
// セッションを作成
const session = await Session.insert({
user_id: user._id,
code: rndstr('a-z0-9', 3)
});
// Reponse
res(await pack(session));
});