Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!