Add basic transactions

This commit is contained in:
Owen Schwartz 2024-12-24 16:00:02 -05:00
parent 3b042cb246
commit 01c56463b6
22 changed files with 548 additions and 459 deletions

View file

@ -31,18 +31,18 @@ async function generateEmailVerificationCode(
userId: string,
email: string
): Promise<string> {
await db
.delete(emailVerificationCodes)
.where(eq(emailVerificationCodes.userId, userId));
const code = generateRandomString(8, alphabet("0-9"));
await db.transaction(async (trx) => {
await trx
.delete(emailVerificationCodes)
.where(eq(emailVerificationCodes.userId, userId));
await db.insert(emailVerificationCodes).values({
userId,
email,
code,
expiresAt: createDate(new TimeSpan(15, "m")).getTime()
await trx.insert(emailVerificationCodes).values({
userId,
email,
code,
expiresAt: createDate(new TimeSpan(15, "m")).getTime()
});
});
return code;
}