Musa
Musa
Explore posts from servers
DTDrizzle Team
Created by Musa on 10/31/2024 in #help
Using Zod objects generated from drizzle zod with ts-rest . Parameters interpreted as optional
Hey I am trying to use drizzle zod to generate zod objects to be used in my ts rest contract. however when I try to use this contract in my handlers the fields in the body being passed are interpreted as being optional and not mandatory contract
import { Tenant } from "@repo/drizzle/src/schema/tenant";
import { selectUserSchema, insertUserSchema } from "./users";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { initContract } from "@ts-rest/core";
import { z } from "zod";

export const insertTenantSchema = createInsertSchema(Tenant).required({ name: true ,subdomain: true}).omit({ id: true, createdAt: true, updatedAt: true })
export const selectTenantSchema = createSelectSchema(Tenant)


const c = initContract();

export const tenantsContract = c.router({
create: {
method: 'POST',
path: '/tenants',
responses: {
201: z.object({
tenant: selectTenantSchema,
adminUser: selectUserSchema.omit({ password: true })
})
},
body: z.object({
tenant: insertTenantSchema,
adminUser: insertUserSchema
}),
summary: 'Create a new tenant with an admin user'
}
});
import { Tenant } from "@repo/drizzle/src/schema/tenant";
import { selectUserSchema, insertUserSchema } from "./users";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { initContract } from "@ts-rest/core";
import { z } from "zod";

export const insertTenantSchema = createInsertSchema(Tenant).required({ name: true ,subdomain: true}).omit({ id: true, createdAt: true, updatedAt: true })
export const selectTenantSchema = createSelectSchema(Tenant)


const c = initContract();

export const tenantsContract = c.router({
create: {
method: 'POST',
path: '/tenants',
responses: {
201: z.object({
tenant: selectTenantSchema,
adminUser: selectUserSchema.omit({ password: true })
})
},
body: z.object({
tenant: insertTenantSchema,
adminUser: insertUserSchema
}),
summary: 'Create a new tenant with an admin user'
}
});
body object
parameter) body: {
tenant?: {
name?: string;
subdomain?: string;
};
adminUser?: {
id?: string;
name?: string;
createdAt?: unknown;
updatedAt?: unknown;
email?: string;
password?: string;
tenantId?: string;
role?: string;
};
}
parameter) body: {
tenant?: {
name?: string;
subdomain?: string;
};
adminUser?: {
id?: string;
name?: string;
createdAt?: unknown;
updatedAt?: unknown;
email?: string;
password?: string;
tenantId?: string;
role?: string;
};
}
3 replies
RRailway
Created by Musa on 2/16/2024 in #✋|help
Project deploys successfully then crashes after a minute or 2
Project-id:a152df40-b98b-4053-afe7-e4c47c064cca My Golang application builds and deploys successfully but then suddenly crashes. I don't see any log messages
37 replies