noob help : transaction not acid
sending two req at the same time, one with +10 the other with +100, the expected behavior for the trasnaction to wait for previous req to complete so its consistent
return await this.drizzle.db.transaction(async (trx) => {
const u = await trx
.select({
usd: users.usd,
})
.from(users)
.where(eq(users.id, 1));
if (!u || u.length == 0) {
throw new HttpException(
{
message: 'User not found',
success: false,
},
404,
);
}
const user = u[0];
await this.timeout(5000);
return (
await trx
.update(users)
.set({
usd: user.usd + val,
})
.where(eq(users.id, 1))
.returning()
)[0].usd;