Added memorial settings
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user