forked from FoundKeyGang/FoundKey
refactor: add NoteReactions.packMany
This commit is contained in:
parent
6775028b1e
commit
b630cd7eac
3 changed files with 16 additions and 2 deletions
|
@ -25,8 +25,22 @@ export const NoteReactionRepository = db.getRepository(NoteReaction).extend({
|
|||
user: await Users.pack(reaction.user ?? reaction.userId, me),
|
||||
type: convertLegacyReaction(reaction.reaction),
|
||||
...(opts.withNote ? {
|
||||
// may throw error
|
||||
note: await Notes.pack(reaction.note ?? reaction.noteId, me),
|
||||
} : {}),
|
||||
};
|
||||
},
|
||||
|
||||
async packMany(
|
||||
src: NoteReaction[],
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
options?: {
|
||||
withNote: booleam;
|
||||
},
|
||||
): Promise<Packed<'NoteReaction'>[]> {
|
||||
const reactions = await Promise.allSettled(src.map(reaction => this.pack(reaction, me, options)));
|
||||
|
||||
// filter out rejected promises, only keep fulfilled values
|
||||
return reactions.flatMap(result => result.status === 'fulfilled' ? [result.value] : []);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -75,5 +75,5 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
relations: ['user', 'user.avatar', 'user.banner', 'note'],
|
||||
});
|
||||
|
||||
return await Promise.all(reactions.map(reaction => NoteReactions.pack(reaction, user)));
|
||||
return await NoteReactions.packMany(reactions, user);
|
||||
});
|
||||
|
|
|
@ -62,5 +62,5 @@ export default define(meta, paramDef, async (ps, me) => {
|
|||
.take(ps.limit)
|
||||
.getMany();
|
||||
|
||||
return await Promise.all(reactions.map(reaction => NoteReactions.pack(reaction, me, { withNote: true })));
|
||||
return await NoteReactions.packMany(reactions, me, { withNote: true });
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue