Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Off topic) how hard is to use nestia capabilities outside nestjs controller? #944

Closed
hikinine opened this issue Jul 5, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@hikinine
Copy link

hikinine commented Jul 5, 2024

On my domain layer I usually adapt controller inputs into aggregate/entities/value object/etc

I do have a schema that ensure every entity props to match the desired type. Lets say

const schema = {
  isActive: z.boolean(),
  auth: z.instanceOf(Authentication),
  profile: instanceOf(Profile),
  email: z.string()
}

export interface UserProps {
  isActive: boolean
  auth: Authentication
  profile: Profile
  email: string
  //...
}
export class User extends Entity<User> {
  static schema = schema
}


const user = new User({
  isActive: true,
  profile: new Profile({...}),
  email: 'whatever@gmail.com',
  ...
})

When I do construct an entity object, it auto runs an type validation based on schema checking if props match schema.

Question

How hard is to just pass an interface and validation be done? Without an schema, pure interface.

If an primitive was provided, check if matchs
If an class was provided, check by instanceof

Thanks in advance

@samchon
Copy link
Owner

samchon commented Aug 14, 2024

You can use below typia functions:

typia.is<T>() function auto-casts to the T type when valid.
typia.assertGuard<T>() function auto-casts when no type error.

Related documents:

@samchon samchon self-assigned this Aug 14, 2024
@samchon samchon added the question Further information is requested label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants