chore: format

This commit is contained in:
2025-10-10 16:43:21 +02:00
parent f0aabd63b6
commit 75c29e0ba4
551 changed files with 433948 additions and 94145 deletions

View File

@@ -1,98 +1,98 @@
import { z } from "zod"
import { authProcedure } from "../trpc"
import { prisma } from "../utils/prisma"
import fs from "fs/promises"
import { TRPCError } from "@trpc/server"
import { z } from "zod";
import { authProcedure } from "../trpc";
import { prisma } from "../utils/prisma";
import fs from "fs/promises";
import { TRPCError } from "@trpc/server";
const createOrganizationSchema = z.object({
name: z.string().min(1, "Organization name is required"),
description: z.string().optional(),
})
name: z.string().min(1, "Organization name is required"),
description: z.string().optional(),
});
export const createOrganization = authProcedure
.input(createOrganizationSchema)
.mutation(async ({ ctx, input }) => {
const organization = await prisma.organization.create({
data: {
name: input.name,
description: input.description,
UserOrganizations: {
create: {
userId: ctx.user.id,
},
},
Templates: {
createMany: {
data: [
{
name: "Newsletter",
content: await fs.readFile(
"templates/newsletter.html",
"utf-8"
),
},
],
},
},
EmailDeliverySettings: {
// Default settings
create: {},
},
GeneralSettings: {
// Default settings
create: {},
},
},
select: {
id: true,
name: true,
description: true,
createdAt: true,
},
})
.input(createOrganizationSchema)
.mutation(async ({ ctx, input }) => {
const organization = await prisma.organization.create({
data: {
name: input.name,
description: input.description,
UserOrganizations: {
create: {
userId: ctx.user.id,
},
},
Templates: {
createMany: {
data: [
{
name: "Newsletter",
content: await fs.readFile(
"templates/newsletter.html",
"utf-8",
),
},
],
},
},
EmailDeliverySettings: {
// Default settings
create: {},
},
GeneralSettings: {
// Default settings
create: {},
},
},
select: {
id: true,
name: true,
description: true,
createdAt: true,
},
});
return {
organization,
}
})
return {
organization,
};
});
const updateOrganizationSchema = z.object({
id: z.string(),
name: z.string().min(1, "Organization name is required"),
description: z.string().optional(),
})
id: z.string(),
name: z.string().min(1, "Organization name is required"),
description: z.string().optional(),
});
export const updateOrganization = authProcedure
.input(updateOrganizationSchema)
.mutation(async ({ ctx, input }) => {
const userOrg = await prisma.userOrganization.findFirst({
where: {
userId: ctx.user.id,
organizationId: input.id,
},
})
.input(updateOrganizationSchema)
.mutation(async ({ ctx, input }) => {
const userOrg = await prisma.userOrganization.findFirst({
where: {
userId: ctx.user.id,
organizationId: input.id,
},
});
if (!userOrg) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You do not have access to update this organization.",
})
}
if (!userOrg) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You do not have access to update this organization.",
});
}
const updatedOrganization = await prisma.organization.update({
where: { id: input.id },
data: {
name: input.name,
description: input.description,
},
select: {
id: true,
name: true,
description: true,
createdAt: true,
updatedAt: true,
},
})
const updatedOrganization = await prisma.organization.update({
where: { id: input.id },
data: {
name: input.name,
description: input.description,
},
select: {
id: true,
name: true,
description: true,
createdAt: true,
updatedAt: true,
},
});
return { organization: updatedOrganization }
})
return { organization: updatedOrganization };
});

View File

@@ -1,46 +1,46 @@
import { z } from "zod"
import { authProcedure } from "../trpc"
import { prisma } from "../utils/prisma"
import { TRPCError } from "@trpc/server"
import { z } from "zod";
import { authProcedure } from "../trpc";
import { prisma } from "../utils/prisma";
import { TRPCError } from "@trpc/server";
export const getOrganizationById = authProcedure
.input(
z.object({
id: z.string(),
})
)
.query(async ({ ctx, input }) => {
const userOrg = await prisma.userOrganization.findFirst({
where: {
userId: ctx.user.id,
organizationId: input.id,
},
})
.input(
z.object({
id: z.string(),
}),
)
.query(async ({ ctx, input }) => {
const userOrg = await prisma.userOrganization.findFirst({
where: {
userId: ctx.user.id,
organizationId: input.id,
},
});
if (!userOrg) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You do not have access to this organization.",
})
}
if (!userOrg) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You do not have access to this organization.",
});
}
const organization = await prisma.organization.findUnique({
where: { id: input.id },
select: {
id: true,
name: true,
description: true,
createdAt: true,
updatedAt: true,
},
})
const organization = await prisma.organization.findUnique({
where: { id: input.id },
select: {
id: true,
name: true,
description: true,
createdAt: true,
updatedAt: true,
},
});
if (!organization) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Organization not found.",
})
}
if (!organization) {
throw new TRPCError({
code: "NOT_FOUND",
message: "Organization not found.",
});
}
return organization
})
return organization;
});

View File

@@ -1,9 +1,9 @@
import { router } from "../trpc"
import { createOrganization, updateOrganization } from "./mutation"
import { getOrganizationById } from "./query"
import { router } from "../trpc";
import { createOrganization, updateOrganization } from "./mutation";
import { getOrganizationById } from "./query";
export const organizationRouter = router({
create: createOrganization,
update: updateOrganization,
getById: getOrganizationById,
})
create: createOrganization,
update: updateOrganization,
getById: getOrganizationById,
});