feat: implement hard delete, email notifications, watermark, and fix bulk download
This commit is contained in:
1 parent
8dd1e10fea
commit
4667615ed0
15 files changed
+369
-65
No files matched your search
@@ -9,6 +9,11 @@ import {
|
||||
auditEvents,
|
||||
billingAddressVersions,
|
||||
editorialAccounts,
|
||||
downloadEvents,
|
||||
usages,
|
||||
lightboxItems,
|
||||
billingReports,
|
||||
albumAutoRules,
|
||||
} from "@/db/schema";
|
||||
import type * as schema from "@/db/schema";
|
||||
import type { AccountStatus } from "@/modules/auth/principal";
|
||||
@@ -51,6 +56,7 @@ export type EditorialServiceRepository = {
|
||||
adminUserId: string;
|
||||
}): Promise<void>;
|
||||
archiveEditorial(input: { editorialId: string; adminUserId: string }): Promise<void>;
|
||||
hardDeleteEditorial(editorialId: string): Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -156,6 +162,10 @@ export function createEditorialService({
|
||||
async archiveEditorial(input: { editorialId: string; adminUserId: string }): Promise<void> {
|
||||
await repository.archiveEditorial(input);
|
||||
},
|
||||
|
||||
async hardDeleteEditorial(editorialId: string): Promise<void> {
|
||||
await repository.hardDeleteEditorial(editorialId);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -510,6 +520,38 @@ export function createEditorialServiceRepository(
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async hardDeleteEditorial(editorialId: string) {
|
||||
await db.transaction(async (transaction) => {
|
||||
await lockEditorialForMutation(transaction, editorialId);
|
||||
|
||||
const [editorial] = await transaction
|
||||
.select({ userId: editorialAccounts.userId })
|
||||
.from(editorialAccounts)
|
||||
.where(eq(editorialAccounts.id, editorialId));
|
||||
|
||||
if (!editorial) return;
|
||||
|
||||
// Cascade deletions manually due to restrict constraints
|
||||
await transaction.delete(downloadEvents).where(eq(downloadEvents.editorialAccountId, editorialId));
|
||||
await transaction.delete(usages).where(eq(usages.editorialAccountId, editorialId));
|
||||
await transaction.delete(lightboxItems).where(eq(lightboxItems.editorialAccountId, editorialId));
|
||||
await transaction.delete(billingReports).where(eq(billingReports.editorialAccountId, editorialId));
|
||||
await transaction.delete(albumAutoRules).where(eq(albumAutoRules.editorialAccountId, editorialId));
|
||||
await transaction.delete(albumGrants).where(eq(albumGrants.editorialAccountId, editorialId));
|
||||
await transaction.delete(billingAddressVersions).where(eq(billingAddressVersions.editorialAccountId, editorialId));
|
||||
await transaction.delete(auditEvents).where(and(eq(auditEvents.entityId, editorialId), eq(auditEvents.entityType, "editorial_account")));
|
||||
|
||||
await transaction.delete(editorialAccounts).where(eq(editorialAccounts.id, editorialId));
|
||||
|
||||
if (editorial.userId) {
|
||||
const { accounts, sessions, users } = await import("@/db/schema/auth");
|
||||
await transaction.delete(accounts).where(eq(accounts.userId, editorial.userId));
|
||||
await transaction.delete(sessions).where(eq(sessions.userId, editorial.userId));
|
||||
await transaction.delete(users).where(eq(users.id, editorial.userId));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user