diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-04 00:39:11 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-04 00:39:11 +0900 |
| commit | baad11288af8ae1b950ecb5a62e23a70bee7d51d (patch) | |
| tree | 98a8dd3829753c4f78fd344e8c52b528edbb933e /src/models/note.ts | |
| parent | 9.3.1 (diff) | |
| download | sharkey-baad11288af8ae1b950ecb5a62e23a70bee7d51d.tar.gz sharkey-baad11288af8ae1b950ecb5a62e23a70bee7d51d.tar.bz2 sharkey-baad11288af8ae1b950ecb5a62e23a70bee7d51d.zip | |
ドキュメントが見つからなくてもエラーにせずnullを返すように
Diffstat (limited to 'src/models/note.ts')
| -rw-r--r-- | src/models/note.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/models/note.ts b/src/models/note.ts index 67ee525c31..75518d709f 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -226,6 +226,17 @@ export const hideNote = async (packedNote: any, meId: mongo.ObjectID) => { } }; +export const packMany = async ( + notes: (string | mongo.ObjectID | INote)[], + me?: string | mongo.ObjectID | IUser, + options?: { + detail?: boolean; + skipHide?: boolean; + } +) => { + return (await Promise.all(notes.map(n => pack(n, me, options)))).filter(x => x != null); +}; + /** * Pack a note for API response * @@ -271,7 +282,11 @@ export const pack = async ( _note = deepcopy(note); } - if (!_note) throw `invalid note arg ${note}`; + // 投稿がデータベース上に見つからなかったとき + if (_note == null) { + console.warn(`note not found on database: ${note}`); + return null; + } const id = _note._id; |