Improve pack function of favorite
This commit is contained in:
parent
c1ef1bf605
commit
e8afa2c940
2 changed files with 15 additions and 2 deletions
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue