added qr, cleaned up profile views, and added the critical alerts

This commit is contained in:
blaisadmin
2026-05-20 21:54:17 -04:00
parent f2c506ec16
commit 1c0d57299d
9 changed files with 949 additions and 60 deletions
+43 -6
View File
@@ -33,6 +33,8 @@ const birdSelectFields = `
birds.photo_updated_at,
birds.notify_on_dob,
birds.notify_on_gotcha_day,
birds.public_profile_code,
birds.public_profile_enabled,
birds.memorialized_at,
birds.memorialized_on::text,
birds.memorial_note,
@@ -62,6 +64,27 @@ export const getBirdById = async (birdId: string, workspaceId: number) => {
return result.rows[0] ?? null;
};
export const getBirdByPublicProfileCode = async (publicProfileCode: string) => {
const result = await db.query<BirdRow>(
`SELECT
${birdSelectFields}
FROM birds
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 birds.public_profile_code = $1
AND birds.public_profile_enabled = TRUE
AND birds.memorialized_at IS NULL`,
[publicProfileCode],
);
return result.rows[0] ?? null;
};
export const listBirds = async (workspaceId: number) => {
const result = await db.query<BirdRow>(
`SELECT
@@ -274,6 +297,8 @@ export const createBird = async ({
photoUpdatedAt = null,
notifyOnDob,
notifyOnGotchaDay,
publicProfileCode = null,
publicProfileEnabled = false,
}: {
birdId?: string;
workspaceId: number;
@@ -293,11 +318,13 @@ export const createBird = async ({
photoUpdatedAt?: string | null;
notifyOnDob: boolean;
notifyOnGotchaDay: boolean;
publicProfileCode?: string | null;
publicProfileEnabled?: boolean;
}) => {
const result = await db.query<BirdRow>(
`INSERT INTO birds (id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth, gotcha_day, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day)
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18)
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
`INSERT INTO birds (id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth, gotcha_day, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled)
VALUES (COALESCE($1::uuid, gen_random_uuid()), $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at, NULL::text AS latest_weight_grams, NULL::text AS latest_recorded_on`,
[
birdId ?? null,
workspaceId,
@@ -317,6 +344,8 @@ export const createBird = async ({
photoUpdatedAt,
notifyOnDob,
notifyOnGotchaDay,
publicProfileCode,
publicProfileEnabled,
],
);
@@ -342,6 +371,8 @@ export const updateBird = async ({
photoUpdatedAt = null,
notifyOnDob,
notifyOnGotchaDay,
publicProfileCode,
publicProfileEnabled,
}: {
birdId: string;
workspaceId: number;
@@ -361,6 +392,8 @@ export const updateBird = async ({
photoUpdatedAt?: string | null;
notifyOnDob: boolean;
notifyOnGotchaDay: boolean;
publicProfileCode: string | null;
publicProfileEnabled: boolean;
}) => {
const result = await db.query<BirdRow>(
`UPDATE birds
@@ -379,11 +412,13 @@ export const updateBird = async ({
photo_content_type = $14,
photo_updated_at = $15,
notify_on_dob = $16,
notify_on_gotcha_day = $17
notify_on_gotcha_day = $17,
public_profile_code = $18,
public_profile_enabled = $19
WHERE id = $1
AND workspace_id = $18
AND workspace_id = $20
AND memorialized_at IS NULL
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
RETURNING id, workspace_id, name, tag_id, species, motivators, demotivators, favorite_snack, gender, date_of_birth::text, gotcha_day::text, chart_color, photo_data_url, photo_object_key, photo_content_type, photo_updated_at, notify_on_dob, notify_on_gotcha_day, public_profile_code, public_profile_enabled, memorialized_at, memorialized_on::text, memorial_note, notify_on_memorial_day, created_at,
(
SELECT weight_grams::text
FROM weight_records
@@ -416,6 +451,8 @@ export const updateBird = async ({
photoUpdatedAt,
notifyOnDob,
notifyOnGotchaDay,
publicProfileCode,
publicProfileEnabled,
workspaceId,
],
);