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?