.ketchikan
.ketchikan
TTCTheo's Typesafe Cult
Created by .ketchikan on 5/3/2023 in #questions
Prisma Create with Connect Issue
Here is what my create procedure looks like right now:
create: privateProcedure
.input(
orgSchema
)
.mutation(async ({ ctx, input }) => {
const currentUser = ctx.userId

// Must pass the ratelimit
const { success } = await ratelimit.limit(currentUser)

if (!success) throw new TRPCError({ code: "TOO_MANY_REQUESTS" });

const org = await ctx.prisma.org.create({
data: {
createdBy: currentUser,
modifiedBy: currentUser,
name: input.name,
nickname: input.nickname,
albatrossOrgId: input.albatrossOrgId,
parentOrgId: input.parentOrgId,
// orgType: {
// connect: {id: input.orgTypeId}
// }

},
});

return org;
}),
create: privateProcedure
.input(
orgSchema
)
.mutation(async ({ ctx, input }) => {
const currentUser = ctx.userId

// Must pass the ratelimit
const { success } = await ratelimit.limit(currentUser)

if (!success) throw new TRPCError({ code: "TOO_MANY_REQUESTS" });

const org = await ctx.prisma.org.create({
data: {
createdBy: currentUser,
modifiedBy: currentUser,
name: input.name,
nickname: input.nickname,
albatrossOrgId: input.albatrossOrgId,
parentOrgId: input.parentOrgId,
// orgType: {
// connect: {id: input.orgTypeId}
// }

},
});

return org;
}),
2 replies
TTCTheo's Typesafe Cult
Created by .ketchikan on 4/12/2023 in #questions
Zod optional fields and numbers
Thank you for your help!
8 replies
TTCTheo's Typesafe Cult
Created by .ketchikan on 4/12/2023 in #questions
Zod optional fields and numbers
Oh I may have just figured it out! Let me know if this is a bad solution:
<button
onClick={() =>
mutate({
albatrossOrgId: parseInt(albatrossID),
name: orgName,
nickname: nickname || undefined,
parentOrgId: parseInt(parentOrg) || undefined,
})
}
type="submit"
className="border border-black bg-blue-400 "
>
<button
onClick={() =>
mutate({
albatrossOrgId: parseInt(albatrossID),
name: orgName,
nickname: nickname || undefined,
parentOrgId: parseInt(parentOrg) || undefined,
})
}
type="submit"
className="border border-black bg-blue-400 "
>
8 replies
TTCTheo's Typesafe Cult
Created by .ketchikan on 4/12/2023 in #questions
Zod optional fields and numbers
I reset ts just in case, but it looks like it's persisting
8 replies
TTCTheo's Typesafe Cult
Created by .ketchikan on 4/12/2023 in #questions
Zod optional fields and numbers
The error is on albatrossOrgId and parentOrgId (both of which I added that coerce), it's a typing error, it's expecting numbers but getting a string still
8 replies
TTCTheo's Typesafe Cult
Created by .ketchikan on 4/12/2023 in #questions
Zod optional fields and numbers
Oh good thinking! I tried that out, but I'm getting an error on the button:
<button
onClick={() =>
mutate({
albatrossOrgId: albatrossID,
name: orgName,
nickname: nickname,
parentOrgId: parentOrg,
})
}
type="submit"
className="border border-black bg-blue-400 "
>
<button
onClick={() =>
mutate({
albatrossOrgId: albatrossID,
name: orgName,
nickname: nickname,
parentOrgId: parentOrg,
})
}
type="submit"
className="border border-black bg-blue-400 "
>
8 replies