ドキュメントが見つからなくてもエラーにせずnullを返すように

This commit is contained in:
syuilo
2018-10-04 00:39:11 +09:00
parent 7e50646ede
commit baad11288a
15 changed files with 50 additions and 34 deletions

View File

@ -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;