diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:20:40 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:54:41 +0900 |
| commit | 90f8fe7e538bb7e52d2558152a0390e693f39b11 (patch) | |
| tree | 0f830887053c8f352b1cd0c13ca715fd14c1f030 /src/api/models/othello-matching.ts | |
| parent | Implement remote account resolution (diff) | |
| download | sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.gz sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.bz2 sharkey-90f8fe7e538bb7e52d2558152a0390e693f39b11.zip | |
Introduce processor
Diffstat (limited to 'src/api/models/othello-matching.ts')
| -rw-r--r-- | src/api/models/othello-matching.ts | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/src/api/models/othello-matching.ts b/src/api/models/othello-matching.ts deleted file mode 100644 index 5cc39cae13..0000000000 --- a/src/api/models/othello-matching.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as mongo from 'mongodb'; -import deepcopy = require('deepcopy'); -import db from '../../db/mongodb'; -import { IUser, pack as packUser } from './user'; - -const Matching = db.get<IMatching>('othello_matchings'); -export default Matching; - -export interface IMatching { - _id: mongo.ObjectID; - created_at: Date; - parent_id: mongo.ObjectID; - child_id: mongo.ObjectID; -} - -/** - * Pack an othello matching for API response - */ -export const pack = ( - matching: any, - me?: string | mongo.ObjectID | IUser -) => new Promise<any>(async (resolve, reject) => { - - // Me - const meId: mongo.ObjectID = me - ? mongo.ObjectID.prototype.isPrototypeOf(me) - ? me as mongo.ObjectID - : typeof me === 'string' - ? new mongo.ObjectID(me) - : (me as IUser)._id - : null; - - const _matching = deepcopy(matching); - - // Rename _id to id - _matching.id = _matching._id; - delete _matching._id; - - // Populate user - _matching.parent = await packUser(_matching.parent_id, meId); - _matching.child = await packUser(_matching.child_id, meId); - - resolve(_matching); -}); |