mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-30 17:03:09 +02:00
108dcb3e61
これらの処理はパフォーマンス的に現実的でないし、すべてのモデルの関係を把握している必要があり保守が困難 論理削除でなんとかする
41 lines
934 B
TypeScript
41 lines
934 B
TypeScript
import * as mongo from 'mongodb';
|
|
const deepcopy = require('deepcopy');
|
|
import db from '../db/mongodb';
|
|
import isObjectId from '../misc/is-objectid';
|
|
|
|
const UserList = db.get<IUserList>('userList');
|
|
export default UserList;
|
|
|
|
export interface IUserList {
|
|
_id: mongo.ObjectID;
|
|
createdAt: Date;
|
|
title: string;
|
|
userId: mongo.ObjectID;
|
|
userIds: mongo.ObjectID[];
|
|
}
|
|
|
|
export const pack = (
|
|
userList: string | mongo.ObjectID | IUserList
|
|
) => new Promise<any>(async (resolve, reject) => {
|
|
let _userList: any;
|
|
|
|
if (isObjectId(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);
|
|
});
|