multi tenancy stuff
This commit is contained in:
@ -3,15 +3,14 @@ import { z } from "zod";
|
||||
|
||||
import db, { Prisma } from "../../../db";
|
||||
import { decrypt } from "../../../db/_encryption";
|
||||
import getCurrentCustomer from "../../customers/queries/get-current-customer";
|
||||
|
||||
const GetConversations = z.object({
|
||||
recipient: z.string(),
|
||||
});
|
||||
|
||||
export default resolver.pipe(resolver.zod(GetConversations), resolver.authorize(), async ({ recipient }, context) => {
|
||||
const customer = await getCurrentCustomer(null, context);
|
||||
if (!customer) {
|
||||
const organization = await db.organization.findFirst({ where: { id: context.session.orgId } });
|
||||
if (!organization) {
|
||||
throw new NotFoundError();
|
||||
}
|
||||
|
||||
@ -23,7 +22,7 @@ export default resolver.pipe(resolver.zod(GetConversations), resolver.authorize(
|
||||
return conversation.map((message) => {
|
||||
return {
|
||||
...message,
|
||||
content: decrypt(message.content, customer.encryptionKey),
|
||||
content: decrypt(message.content, organization.encryptionKey),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user