From 2edc5d57b6abf56e7d99ac546fdb2c65955a5350 Mon Sep 17 00:00:00 2001 From: Brandon Egger Date: Mon, 4 Sep 2023 00:33:54 -0500 Subject: [PATCH] improve resource schema to reflect new icon structure --- prisma/schema.prisma | 2 +- src/components/ResourcePhoto.tsx | 2 +- src/components/admin/resources/form.tsx | 5 +--- src/server/api/routers/auditoryResources.ts | 27 +++++++++------------ 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 2ca430b..0a9465a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -70,7 +70,7 @@ type Photo { model AuditoryResource { id String @id @default(auto()) @map("_id") @db.ObjectId - icon String + icon String? name String description String photo Photo? diff --git a/src/components/ResourcePhoto.tsx b/src/components/ResourcePhoto.tsx index df56ba2..443b26d 100644 --- a/src/components/ResourcePhoto.tsx +++ b/src/components/ResourcePhoto.tsx @@ -8,7 +8,7 @@ type ResourcePhotoProps = ( src: string | undefined; } | { - src: string; + src: string | undefined; photo: null; } ) & { name: string }; diff --git a/src/components/admin/resources/form.tsx b/src/components/admin/resources/form.tsx index fa689f8..cc24ff9 100644 --- a/src/components/admin/resources/form.tsx +++ b/src/components/admin/resources/form.tsx @@ -346,10 +346,7 @@ function ResourceSummarySubForm({ }: { resource?: ResourceUpdateInput; }) { - const { - register, - formState: { errors }, - } = useFormContext(); + const { register } = useFormContext(); return (
diff --git a/src/server/api/routers/auditoryResources.ts b/src/server/api/routers/auditoryResources.ts index 4f6a705..e631fa6 100644 --- a/src/server/api/routers/auditoryResources.ts +++ b/src/server/api/routers/auditoryResources.ts @@ -17,18 +17,13 @@ const emptyStringToUndefined = (val: string | undefined | null) => { }; const AuditoryResourceSchema = z.object({ - id: z.string(), - icon: z.string().min(1), + icon: z.string().min(1).optional(), name: z.string().min(1), description: z.string().min(1), manufacturer: z.object({ name: z.string().min(1), - required: z.boolean(), - notice: z - .string() - - .nullable() - .transform(emptyStringToUndefined), + required: z.boolean().default(false), + notice: z.string().nullable().transform(emptyStringToUndefined), }), ages: z.object({ min: z.number().int(), max: z.number().int() }), skills: z.array(z.nativeEnum(Skill)), @@ -40,12 +35,14 @@ const AuditoryResourceSchema = z.object({ data: z.instanceof(Buffer), }) .nullable(), - platform_links: z.array( - z.object({ - platform: z.nativeEnum(Platform), - link: z.string().min(1), - }) - ), + platform_links: z + .array( + z.object({ + platform: z.nativeEnum(Platform), + link: z.string().min(1), + }) + ) + .default([]), }); export const auditoryResourceRouter = createTRPCRouter({ @@ -86,7 +83,7 @@ export const auditoryResourceRouter = createTRPCRouter({ }), update: protectedProcedure - .input(AuditoryResourceSchema.partial()) + .input(AuditoryResourceSchema.partial().extend({ id: z.string() })) .mutation(async ({ input, ctx }) => { return await ctx.prisma.auditoryResource.update({ where: {