diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-03-07 01:54:56 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-03-07 01:54:56 +0900 |
| commit | 06eabcbc636800c551e4ba602325d227ca463460 (patch) | |
| tree | bc521908347be88f42fc76798ea5c1985d1a47bf /src/api/models | |
| parent | v3999 (diff) | |
| download | sharkey-06eabcbc636800c551e4ba602325d227ca463460.tar.gz sharkey-06eabcbc636800c551e4ba602325d227ca463460.tar.bz2 sharkey-06eabcbc636800c551e4ba602325d227ca463460.zip | |
wip
Diffstat (limited to 'src/api/models')
| -rw-r--r-- | src/api/models/othello-game.ts | 33 | ||||
| -rw-r--r-- | src/api/models/othello-session.ts | 29 |
2 files changed, 62 insertions, 0 deletions
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<IGame>('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<any>} + */ +export const pack = ( + game: any +) => new Promise<any>(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<ISession>('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<any>} + */ +export const pack = ( + session: any +) => new Promise<any>(async (resolve, reject) => { + + const _session = deepcopy(session); + + delete _session._id; + + resolve(_session); +}); |