fix: deletion corner cases

This commit is contained in:
Daniel Hougaard
2025-04-26 05:55:25 +04:00
parent e7783fe6cc
commit 11ee13676d
8 changed files with 91 additions and 63 deletions
@@ -1,3 +1,5 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
import { ormify, selectAllTableCols } from "@app/lib/knex";
@@ -7,9 +9,8 @@ export type TSecretReminderRecipientsDALFactory = ReturnType<typeof secretRemind
export const secretReminderRecipientsDALFactory = (db: TDbClient) => {
const secretReminderRecipientsOrm = ormify(db, TableName.SecretReminderRecipients);
const findUsersBySecretId = async (secretId: string) => {
const res = await db
.replicaNode()(TableName.SecretReminderRecipients)
const findUsersBySecretId = async (secretId: string, tx?: Knex) => {
const res = await (tx || db.replicaNode())(TableName.SecretReminderRecipients)
.where({ secretId })
.leftJoin(TableName.Users, `${TableName.SecretReminderRecipients}.userId`, `${TableName.Users}.id`)
.leftJoin(TableName.Project, `${TableName.SecretReminderRecipients}.projectId`, `${TableName.Project}.id`)