mwanago / express-typescript

875 stars 204 forks source link

[question] class transformer for dtos #2

Open orenmizr opened 5 years ago

orenmizr commented 5 years ago

hi, isn't making classes via the validation middleware costly - reallocating memory to the req.body object into a class and than again creating a model class for insertion...

isn't there a way to work with the req.body object directly - what is the advantage here ? thanks.

babacarcissedia commented 5 years ago

@orenmizr yeah maybe, I personaly use the following approach:

const v = Validator.make(request.body, {
  email: 'required|email',
  password: 'required'
})

If you are familiar with Laravel you'll recognize this