-
Notifications
You must be signed in to change notification settings - Fork 22
Closed
Labels
🐛 bugSomething isn't workingSomething isn't working
Description
user.schema.ts
export const userSchema = z.object({
id: z.string(),
name: z.string(),
createdAt: z.date(),
})
export const createUserSchema = userSchema.pick({ name: true })
user.router.ts
@Router({ alias: 'user' })
export class UsersRouter {
constructor(private readonly prisma: PrismaService) {}
@Query({ input: createUserSchema, output: userSchema })
async login(@Input('name') name: string) {
const foundUser = await this.prisma.user.findUnique({
where: {
name,
},
})
if (foundUser) return foundUser
return this.prisma.user.create({
data: {
name,
},
})
}
@Query({ input: z.string(), output: userSchema })
async byName(@Input() name: string) {
const foundUser = await this.prisma.user.findUnique({
where: {
name,
},
})
if (!foundUser) throw new TRPCError({ code: 'NOT_FOUND' })
return foundUser
}
}

Metadata
Metadata
Assignees
Labels
🐛 bugSomething isn't workingSomething isn't working