Added missing bird
This commit is contained in:
1 parent
328a9a704d
commit
e06dae91a3
6 files changed
+366
-4
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { db } from '../db/client.js';
|
||||
import type { BirdGender, BirdRow, PendingBirdTransferRow, VetVisitRow, WeightRow } from '../types.js';
|
||||
import type { BirdGender, BirdRow, LostBirdMatchRow, PendingBirdTransferRow, VetVisitRow, WeightRow } from '../types.js';
|
||||
|
||||
const birdSelectFields = `
|
||||
birds.id,
|
||||
@@ -59,6 +59,30 @@ export const listBirds = async (workspaceId: number) => {
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
export const findBirdsByBandId = async (tagId: string) => {
|
||||
const result = await db.query<LostBirdMatchRow>(
|
||||
`SELECT
|
||||
${birdSelectFields},
|
||||
workspaces.name AS workspace_name,
|
||||
workspaces.billing_email AS workspace_billing_email
|
||||
FROM birds
|
||||
INNER JOIN workspaces ON workspaces.id = birds.workspace_id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT weight_grams, recorded_on
|
||||
FROM weight_records
|
||||
WHERE weight_records.bird_id = birds.id
|
||||
ORDER BY recorded_on DESC
|
||||
LIMIT 1
|
||||
) latest ON TRUE
|
||||
WHERE LOWER(birds.tag_id) = LOWER($1)
|
||||
ORDER BY birds.created_at ASC
|
||||
LIMIT 10`,
|
||||
[tagId],
|
||||
);
|
||||
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
export const createBird = async ({
|
||||
workspaceId,
|
||||
name,
|
||||
|
||||
@@ -250,6 +250,27 @@ export const listWorkspaceMembers = async (workspaceId: number) => {
|
||||
return result.rows;
|
||||
};
|
||||
|
||||
export const listWorkspaceNotificationEmails = async (workspaceId: number) => {
|
||||
const result = await db.query<{ email: string }>(
|
||||
`SELECT DISTINCT LOWER(TRIM(email)) AS email
|
||||
FROM (
|
||||
SELECT COALESCE(invite_email, email) AS email
|
||||
FROM workspace_members
|
||||
WHERE workspace_id = $1
|
||||
UNION
|
||||
SELECT billing_email AS email
|
||||
FROM workspaces
|
||||
WHERE id = $1
|
||||
) contact_emails
|
||||
WHERE email IS NOT NULL
|
||||
AND TRIM(email) <> ''
|
||||
ORDER BY email ASC`,
|
||||
[workspaceId],
|
||||
);
|
||||
|
||||
return result.rows.map((row) => row.email);
|
||||
};
|
||||
|
||||
export const findAlternateWorkspaceForUser = async (userId: string, excludeWorkspaceId: number) => {
|
||||
const result = await db.query<{ workspace_id: number }>(
|
||||
`SELECT workspace_id
|
||||
|
||||
Reference in new issue
Block a user