add validation for update organization
This commit is contained in:
@@ -3,6 +3,7 @@ import { z } from "zod";
|
||||
import { createTRPCRouter, protectedProcedure } from "@/server/api/trpc";
|
||||
import { db } from "@/server/db";
|
||||
import { getOrganizationBySlug } from "@/server/services/organization.service";
|
||||
import { slug } from "@/utils/slug";
|
||||
|
||||
export const organizationRouter = createTRPCRouter({
|
||||
first: protectedProcedure.query(({ ctx }) => {
|
||||
@@ -28,17 +29,18 @@ export const organizationRouter = createTRPCRouter({
|
||||
update: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
slug: z.string(),
|
||||
}),
|
||||
)
|
||||
.mutation(({ input }) => {
|
||||
return db.organization.update({
|
||||
where: {
|
||||
slug: input.slug,
|
||||
id: input.id,
|
||||
},
|
||||
data: {
|
||||
name: input.name,
|
||||
slug: slug(input.name)
|
||||
},
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
type GetServerSidePropsResult,
|
||||
} from "next";
|
||||
import { getServerAuthSession } from "./auth";
|
||||
import { db } from "./db";
|
||||
|
||||
export function createServerSideProps(
|
||||
cb?: (context: GetServerSidePropsContext) => Promise<any>,
|
||||
@@ -10,7 +11,7 @@ export function createServerSideProps(
|
||||
return async function getServerSideProps(
|
||||
context: GetServerSidePropsContext,
|
||||
): Promise<GetServerSidePropsResult<any>> {
|
||||
const session = await getServerAuthSession(context);
|
||||
const session = await getServerAuthSession(context);
|
||||
|
||||
if(!session) {
|
||||
return {
|
||||
@@ -21,6 +22,23 @@ export function createServerSideProps(
|
||||
}
|
||||
}
|
||||
|
||||
if(context.params?.organization) {
|
||||
const organization = await db.user.findFirst({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
organization: {
|
||||
slug: context.params.organization as string
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if(!organization) {
|
||||
return {
|
||||
notFound: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const res = await (typeof cb === "function"
|
||||
? cb(context)
|
||||
: Promise.resolve({}));
|
||||
|
||||
Reference in New Issue
Block a user