Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

78
Vistas
Using different DTO representations for get/create/update of an object?

Let say that i have object A that has a reference to object B (in db).

interface A {
   id: string;
   bId: string;
}

interfaceB {
   id: string;
   name: string;
   // other properties
}

When creating object A, i have an autocomplete component (with API lookup). In this situation i just need bId property of an object B in order to store it in a db).

When i want to edit object A, or to show it (as a single entity or in a table) i need an object B (or a partial object) in order to preselect autocomplete component (for autocomplete component i need id and name property). Also if i want to display object A in a table, i just need a name property from B.

1 - Have one DTO for everything (get/post/put), in that case :

interface A {
  id: string,
  bId: Partial<B> // in partial object i will have just {name and id}
 }

For post/put calls, a payload would be for example {id: 3, {id: 129}} and for get requests data would be {id: 3, {id: 129, name: 'Something'}}

2 - Have different DTOs (that are basically the same in all but in one property)

3 - Something else?

What would be a good practise for this?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda