const team = await db.transaction(async (tx) => {
const [team] = await tx.insert(teams).values(teamObj).returning();
await tx.insert(team_stats).values({
team_id: team.id,
total_losses: 0,
total_wins: 0,
xp: 0,
total_money_earned: 0,
total_money_lost: 0
});
await tx.insert(user_teams).values({
team_id: team.id,
user_id: Number(locals.user.id)
});
return team;
});
//make sure team is in db
const [test] = await db.query.teams.findMany({
where: (teams, { eq }) => eq(teams.id, team.id)
});
const team = await db.transaction(async (tx) => {
const [team] = await tx.insert(teams).values(teamObj).returning();
await tx.insert(team_stats).values({
team_id: team.id,
total_losses: 0,
total_wins: 0,
xp: 0,
total_money_earned: 0,
total_money_lost: 0
});
await tx.insert(user_teams).values({
team_id: team.id,
user_id: Number(locals.user.id)
});
return team;
});
//make sure team is in db
const [test] = await db.query.teams.findMany({
where: (teams, { eq }) => eq(teams.id, team.id)
});