import { z } from 'zod' import { TableEntity } from './db.model' import { createQueryParamFilter } from './api.model' /** * Dtos validate and type cast data send from client to server * Model is a subset of Entity and typecasts data on both client and server side * Entity is a typesafe representation of the database table columns */ export const {{ModelNoun}}Entity = TableEntity.extend({ xid: z.string(), // this is an external user friendly application wide unique id name: z.string(), }) // will be used on client side, remove all sensitive fields export const {{ModelNoun}} = {{ModelNoun}}Entity.omit({}) // will be used on server side, and might be used inplace of entity if equal export const {{ModelNoun}}Model = {{ModelNoun}}Entity.omit({}) // used to pass data from service to repositroy where the Dto lacks the computed fileds such as xid etc. export const New{{ModelNoun}}Model = {{ModelNoun}}Entity.omit({ id: true, deleted_at: true, created_at: true, updated_at: true, }) export const New{{ModelNoun}}Dto = New{{ModelNoun}}Model.omit({ xid: true, }) export const Edit{{ModelNoun}}Model = {{ModelNoun}}Entity.omit({ id: true, deleted_at: true, created_at: true, updated_at: true, }).partial() export const Edit{{ModelNoun}}Dto = Edit{{ModelNoun}}Model.omit({}) export const {{ModelNoun}}FilterFields = {{ModelNoun}}Entity.pick({ xid: true, }) export const {{ModelNoun}}QueryParams = createQueryParamFilter({{ModelNoun}}FilterFields) export type I{{ModelNoun}}Entity = z.infer export type I{{ModelNoun}}Model = z.infer export type INew{{ModelNoun}}Dto = z.infer export type INew{{ModelNoun}}Model = z.infer export type IEdit{{ModelNoun}}Dto = z.infer export type IEdit{{ModelNoun}}Model = z.infer export type I{{ModelNoun}}QueryParams = z.infer export type I{{ModelNoun}} = z.infer