Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

105
Vistas
Firestore Schema Validator - Set default value for the nested optional fields

I am using the firestore schema validator to validate the Input to REST API system. I have a input validation schema defined as below:

const userDataSchema = schema({
   field1 : field("field1").integer().default(1000).optional(),
   field2 : field("field2").integer().default(10).optional(),
});

module.exports = {
   testInput : ({
      userName : field("userName").string().trim(),
      userData : field("userData").objectOf(userDataSchema).optional(),
   })
}

userData is an optional field, and if we do not provide the userData field the default values are not getting assigned to field1 and field2. However if I provide userData without any fields the field1 and field2 are assigned with the default values.

Is there a way I can assign the default values to field1 and field2 if we do not pass userData?

Thank you,
KK

Is there a workaround to

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos