Vithrax
Vithrax
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Vithrax on 9/5/2023 in #questions
tailwind error?
Hey I have a weird... Bug? i think. It looks like hidden class has presedence over the md:flex? https://gyazo.com/715ab2f6df0172b4c3bbf730e83e8aa6 When i manually turn off hidden then it looks ok Any suggestion guys?
3 replies
TTCTheo's Typesafe Cult
Created by Vithrax on 8/25/2023 in #questions
Zod object validator using Prisma (MySQL) enum
Hey, could anyone hint how to create a zod validator object, which one of the keys should be an enum from prisma (mysql)
model ProposalOption {
id Int @id @default(autoincrement())
description String @db.TinyText
category OptionCategory
active Boolean
}

enum OptionCategory {
reason
size
feature
additional
}
model ProposalOption {
id Int @id @default(autoincrement())
description String @db.TinyText
category OptionCategory
active Boolean
}

enum OptionCategory {
reason
size
feature
additional
}
zod validator (here is the issue, please help)
import z from "zod";
import type { OptionCategory } from "@prisma/client";

const options: OptionCategory[] = ["additional", "feature", "reason", "size"];

export const CreateProposalOptionValidator = z.object({
description: z
.string()
.min(5, { message: "Description must have at least 5 characters" })
.max(100, { message: "Description must have less than 100 characters" }),
// @ts-expect-error TODO: fix this, just a string atm
category: z.enum(options),
});

export type ProposalOptionCreateRequest = z.infer<
typeof CreateProposalOptionValidator
>;
import z from "zod";
import type { OptionCategory } from "@prisma/client";

const options: OptionCategory[] = ["additional", "feature", "reason", "size"];

export const CreateProposalOptionValidator = z.object({
description: z
.string()
.min(5, { message: "Description must have at least 5 characters" })
.max(100, { message: "Description must have less than 100 characters" }),
// @ts-expect-error TODO: fix this, just a string atm
category: z.enum(options),
});

export type ProposalOptionCreateRequest = z.infer<
typeof CreateProposalOptionValidator
>;
when parsing body on backend using this validator, category is just a string, which causes another type error on the backend when creating a new record pls help!
2 replies