Added memorial settings

This commit is contained in:
Corey Blais
2026-04-22 10:42:43 -04:00
parent 36e074c1fd
commit 646f895ed6
8 changed files with 466 additions and 32 deletions
@@ -302,6 +302,18 @@ export const listOwnedWorkspacesByOwnerEmail = async (ownerEmail: string, exclud
};
export const getWorkspaceBirdCount = async (workspaceId: number) => {
const birdCount = await db.query<{ count: string }>(
`SELECT COUNT(*)::text AS count
FROM birds
WHERE workspace_id = $1
AND memorialized_at IS NULL`,
[workspaceId],
);
return Number(birdCount.rows[0]?.count ?? 0);
};
export const getWorkspaceTotalBirdCount = async (workspaceId: number) => {
const birdCount = await db.query<{ count: string }>(
`SELECT COUNT(*)::text AS count
FROM birds
@@ -313,7 +325,7 @@ export const getWorkspaceBirdCount = async (workspaceId: number) => {
};
export const deleteWorkspaceIfEmpty = async (workspaceId: number) => {
if ((await getWorkspaceBirdCount(workspaceId)) > 0) {
if ((await getWorkspaceTotalBirdCount(workspaceId)) > 0) {
return { deleted: false as const, reason: 'birds_present' as const };
}