diff options
Diffstat (limited to 'src/models')
| -rw-r--r-- | src/models/favorite.ts | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/models/favorite.ts b/src/models/favorite.ts index b2d2fc93e8..2c07959be7 100644 --- a/src/models/favorite.ts +++ b/src/models/favorite.ts @@ -41,6 +41,13 @@ export async function deleteFavorite(favorite: string | mongo.ObjectID | IFavori }); } +export const packMany = async ( + favorites: any[], + me: any +) => { + return (await Promise.all(favorites.map(f => pack(f, me)))).filter(x => x != null); +}; + /** * Pack a favorite for API response */ @@ -70,5 +77,11 @@ export const pack = ( // Populate note _favorite.note = await packNote(_favorite.noteId, me); + // (データベースの不具合などで)投稿が見つからなかったら + if (_favorite.note == null) { + console.warn(`favorite: note not found on database: ${_favorite.noteId}`); + return resolve(null); + } + resolve(_favorite); }); |