From 06eabcbc636800c551e4ba602325d227ca463460 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 7 Mar 2018 01:54:56 +0900 Subject: wip --- src/api/models/othello-game.ts | 33 +++++++++++++++++++++++++++++++++ src/api/models/othello-session.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/api/models/othello-game.ts create mode 100644 src/api/models/othello-session.ts (limited to 'src/api/models') diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts new file mode 100644 index 0000000000..a6beaaf9c7 --- /dev/null +++ b/src/api/models/othello-game.ts @@ -0,0 +1,33 @@ +import * as mongo from 'mongodb'; +import deepcopy = require('deepcopy'); +import db from '../../db/mongodb'; + +const Game = db.get('othello_games'); +export default Game; + +export interface IGame { + _id: mongo.ObjectID; + created_at: Date; + black_user_id: mongo.ObjectID; + white_user_id: mongo.ObjectID; + logs: any[]; +} + +/** + * Pack an othello game for API response + * + * @param {any} game + * @return {Promise} + */ +export const pack = ( + game: any +) => new Promise(async (resolve, reject) => { + + const _game = deepcopy(game); + + // Rename _id to id + _game.id = _game._id; + delete _game._id; + + resolve(_game); +}); diff --git a/src/api/models/othello-session.ts b/src/api/models/othello-session.ts new file mode 100644 index 0000000000..0aa1d01e54 --- /dev/null +++ b/src/api/models/othello-session.ts @@ -0,0 +1,29 @@ +import * as mongo from 'mongodb'; +import deepcopy = require('deepcopy'); +import db from '../../db/mongodb'; + +const Session = db.get('othello_sessions'); +export default Session; + +export interface ISession { + _id: mongo.ObjectID; + code: string; + user_id: mongo.ObjectID; +} + +/** + * Pack an othello session for API response + * + * @param {any} session + * @return {Promise} + */ +export const pack = ( + session: any +) => new Promise(async (resolve, reject) => { + + const _session = deepcopy(session); + + delete _session._id; + + resolve(_session); +}); -- cgit v1.2.3-freya