multi tenancy stuff

This commit is contained in:
m5r
2021-08-06 01:07:15 +08:00
parent b54f9ef43c
commit d20eeb0617
51 changed files with 907 additions and 2542 deletions

View File

@ -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),
};
});
});