From 7602e8f9383be37c0f7d9359f862c366b7f2fa00 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 24 Apr 2018 18:13:06 +0900 Subject: cafy 5.xに移行 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/note-reaction.ts | 2 +- src/models/user-list.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/models') diff --git a/src/models/note-reaction.ts b/src/models/note-reaction.ts index 7891ebdf17..f78b0d9d01 100644 --- a/src/models/note-reaction.ts +++ b/src/models/note-reaction.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import $ from 'cafy'; +import $ from 'cafy'; import ID from '../../../../cafy-id'; import deepcopy = require('deepcopy'); import db from '../db/mongodb'; import Reaction from './note-reaction'; diff --git a/src/models/user-list.ts b/src/models/user-list.ts index 66e2afe213..7100fced7e 100644 --- a/src/models/user-list.ts +++ b/src/models/user-list.ts @@ -1,4 +1,5 @@ import * as mongo from 'mongodb'; +import deepcopy = require('deepcopy'); import db from '../db/mongodb'; const UserList = db.get('userList'); @@ -38,3 +39,29 @@ export async function deleteUserList(userList: string | mongo.ObjectID | IUserLi _id: u._id }); } + +export const pack = ( + userList: string | mongo.ObjectID | IUserList +) => new Promise(async (resolve, reject) => { + let _userList: any; + + if (mongo.ObjectID.prototype.isPrototypeOf(userList)) { + _userList = await UserList.findOne({ + _id: userList + }); + } else if (typeof userList === 'string') { + _userList = await UserList.findOne({ + _id: new mongo.ObjectID(userList) + }); + } else { + _userList = deepcopy(userList); + } + + if (!_userList) throw `invalid userList arg ${userList}`; + + // Rename _id to id + _userList.id = _userList._id; + delete _userList._id; + + resolve(_userList); +}); -- cgit v1.2.3-freya