return early when data is not available as expected

This commit is contained in:
m5r
2021-08-02 18:02:49 +08:00
parent 09568ef684
commit 827ed9f1c0
11 changed files with 88 additions and 43 deletions

View File

@ -11,17 +11,19 @@ const GetConversations = z.object({
export default resolver.pipe(resolver.zod(GetConversations), resolver.authorize(), async ({ recipient }, context) => {
const customer = await getCurrentCustomer(null, context);
if (!customer) {
return;
}
const conversation = await db.message.findMany({
where: {
OR: [{ from: recipient }, { to: recipient }],
},
where: { OR: [{ from: recipient }, { to: recipient }] },
orderBy: { sentAt: Prisma.SortOrder.asc },
});
return conversation.map((message) => {
return {
...message,
content: decrypt(message.content, customer!.encryptionKey),
content: decrypt(message.content, customer.encryptionKey),
};
});
});