-
Hello. I have a shared api folder, it containts all stuff related to backend api, I also have a dto schema, it's used for checking if is the data accurate from backend. export const BoardDtoSchema = v.object({
id: v.string(),
title: v.string(),
icon: v.picklist(ICONS),
background: v.object({
identifier: v.string(),
url: v.nullable(v.string())
}),
columns: v.array(ColumnDtoSchema)
}) But it's used in conjunction with api, so the infered type will be In all over codebase I want to use Board type, which is basically the same with The same comes with AddBoardDtoSchema - export const AddBoardDtoSchema = v.object({
title: v.pipe(v.string(), v.trim(), v.minLength(3)),
icon: v.picklist(ICONS),
background: v.string()
}) This is used to accept values from frontend and validate them before sending to backend. But for the form other schema is being used. export const AddBoardSchema = v.object({
title: v.pipe(
v.string(),
v.trim(),
v.minLength(3, 'Please enter at least 3 characters.')
),
icon: v.picklist(ICONS),
background: v.string()
}) But is basically the same, so I really don't know how to group all this stuff together, and do not to make overhead. In my opinion, if i define DtoSchema, i should use it only within service of api folder, but because it's the same as my "main" types in the codebase i should recreate the same types, just to avoid dto word. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I suggest that you create a mapper anyway, even if it's just a function that returns the argument. This function will convert This will give you flexibility in the future to not depend on the shape of the backend data and also resolve your request to not use the |
Beta Was this translation helpful? Give feedback.
I suggest that you create a mapper anyway, even if it's just a function that returns the argument. This function will convert
BoardDto
intoBoard
, even if these types are the same.This will give you flexibility in the future to not depend on the shape of the backend data and also resolve your request to not use the
Dto
type in the codebase