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 {
id String @id @default(auto()) @map("_id") @db.ObjectId
icon String
icon String?
name String
description String
photo Photo?

View File

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

View File

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

View File

@ -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: {