improve resource schema to reflect new icon structure

This commit is contained in:
Brandon Egger 2023-09-04 00:33:54 -05:00
parent f7144e7cf4
commit 2edc5d57b6
4 changed files with 15 additions and 21 deletions

View File

@ -70,7 +70,7 @@ type Photo {
model AuditoryResource { model AuditoryResource {
id String @id @default(auto()) @map("_id") @db.ObjectId id String @id @default(auto()) @map("_id") @db.ObjectId
icon String icon String?
name String name String
description String description String
photo Photo? photo Photo?

View File

@ -8,7 +8,7 @@ type ResourcePhotoProps = (
src: string | undefined; src: string | undefined;
} }
| { | {
src: string; src: string | undefined;
photo: null; photo: null;
} }
) & { name: string }; ) & { name: string };

View File

@ -346,10 +346,7 @@ function ResourceSummarySubForm({
}: { }: {
resource?: ResourceUpdateInput; resource?: ResourceUpdateInput;
}) { }) {
const { const { register } = useFormContext<ResourceUpdateInput>();
register,
formState: { errors },
} = useFormContext<ResourceUpdateInput>();
return ( return (
<div className="space-y-4 px-4"> <div className="space-y-4 px-4">

View File

@ -17,18 +17,13 @@ const emptyStringToUndefined = (val: string | undefined | null) => {
}; };
const AuditoryResourceSchema = z.object({ const AuditoryResourceSchema = z.object({
id: z.string(), icon: z.string().min(1).optional(),
icon: z.string().min(1),
name: z.string().min(1), name: z.string().min(1),
description: z.string().min(1), description: z.string().min(1),
manufacturer: z.object({ manufacturer: z.object({
name: z.string().min(1), name: z.string().min(1),
required: z.boolean(), required: z.boolean().default(false),
notice: z notice: z.string().nullable().transform(emptyStringToUndefined),
.string()
.nullable()
.transform(emptyStringToUndefined),
}), }),
ages: z.object({ min: z.number().int(), max: z.number().int() }), ages: z.object({ min: z.number().int(), max: z.number().int() }),
skills: z.array(z.nativeEnum(Skill)), skills: z.array(z.nativeEnum(Skill)),
@ -40,12 +35,14 @@ const AuditoryResourceSchema = z.object({
data: z.instanceof(Buffer), data: z.instanceof(Buffer),
}) })
.nullable(), .nullable(),
platform_links: z.array( platform_links: z
z.object({ .array(
platform: z.nativeEnum(Platform), z.object({
link: z.string().min(1), platform: z.nativeEnum(Platform),
}) link: z.string().min(1),
), })
)
.default([]),
}); });
export const auditoryResourceRouter = createTRPCRouter({ export const auditoryResourceRouter = createTRPCRouter({
@ -86,7 +83,7 @@ export const auditoryResourceRouter = createTRPCRouter({
}), }),
update: protectedProcedure update: protectedProcedure
.input(AuditoryResourceSchema.partial()) .input(AuditoryResourceSchema.partial().extend({ id: z.string() }))
.mutation(async ({ input, ctx }) => { .mutation(async ({ input, ctx }) => {
return await ctx.prisma.auditoryResource.update({ return await ctx.prisma.auditoryResource.update({
where: { where: {