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

108
Vistas
Multi data store function

Hel loo all! This is my function

public async create({ request, response }: HttpContextContract) {
    // find or create team
    let team: typeof Team
    let r = request.body
    if (r.existingTeamId) {
      team = await Team.findOrFail(r.existingTeamId)
    } else {
      team = await Team.create({
        title: r.title,
        size: r.size,
      })
    }
    // create teammembers
    r.teamMembers.forEach(
      async (member) =>
        await TeamMember.create({
          ...member,
          name,
          position,
          email,
          teamId: team.id,
        })
    )
    // create training
    const training = await Training.create({ title: r.title, body: r.training.body })

    // create teamLead
    const teamLead = Team.create({ teamlead_first_name: r.firstName, teamlead_last_name: r.lastName, teamlead_email: r.email, teamlead_id: r.teamLeadId })


    return response.json(training)
  }

So if there will be team id i will find that team if there will not be team id then user must create new team then in create team members user must add multi members and there i will get team.id so then user must create training and then team lead thats in teams table so whats i'm doing wrong here? i'm new in this so this is very hard for me so can someone please help me?

about 4 years ago · Santiago Trujillo
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