append messages from free users with "sent from shellphone"

This commit is contained in:
m5r
2021-10-03 21:31:26 +02:00
parent a28d89a8c2
commit 24f1e953f6
9 changed files with 31 additions and 47 deletions

View File

@ -1,28 +0,0 @@
import { NotFoundError, resolver } from "blitz";
import { z } from "zod";
import db, { Prisma } from "../../../db";
import { decrypt } from "../../../db/_encryption";
const GetConversations = z.object({
recipient: z.string(),
});
export default resolver.pipe(resolver.zod(GetConversations), resolver.authorize(), async ({ recipient }, context) => {
const organization = await db.organization.findFirst({ where: { id: context.session.orgId } });
if (!organization) {
throw new NotFoundError();
}
const conversation = await db.message.findMany({
where: { OR: [{ from: recipient }, { to: recipient }] },
orderBy: { sentAt: Prisma.SortOrder.desc },
});
return conversation.map((message) => {
return {
...message,
content: decrypt(message.content, organization.encryptionKey),
};
});
});