Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda