Fix adoption report photos and section order
Deploy / deploy-dev (push) Successful in 1m41s
Deploy / deploy-prod (push) Has been skipped

This commit is contained in:
Corey Blais
2026-06-02 18:26:51 -04:00
parent cadbdc2a7f
commit 979a17132d
2 changed files with 57 additions and 21 deletions
+34 -2
View File
@@ -1387,6 +1387,37 @@ const deleteBirdPhotoObjectIfNeeded = async (objectKey: string | null) => {
}
};
const loadBirdReportPhotoBuffer = async (bird: BirdRow) => {
if (!bird.photo_object_key) {
return null;
}
const s3Config = getS3ImageStorageConfig();
if (!s3Config) {
return null;
}
const signedUrl = getSignedS3ObjectUrl({
config: s3Config,
objectKey: bird.photo_object_key,
expiresInSeconds: 5 * 60,
});
const imageResponse = await fetch(signedUrl);
if (!imageResponse.ok) {
return null;
}
const contentType = imageResponse.headers.get('content-type') || bird.photo_content_type || '';
if (!/^image\/(?:png|jpe?g)$/i.test(contentType)) {
return null;
}
return Buffer.from(await imageResponse.arrayBuffer());
};
const getDefaultBirdPhotoAttachment = () => {
const defaultPhotoPath = path.join(process.cwd(), 'assets', 'yoda-default.png');
@@ -3568,10 +3599,11 @@ app.post(
throw new Error('Unable to create bird transfer code.');
}
const [weights, vetVisits, notes] = await Promise.all([
const [weights, vetVisits, notes, birdPhotoBuffer] = await Promise.all([
listWeightsForBird(sourceBird.id, req.auth!.workspace.id, adoptionReportWeightHistoryDays),
listVetVisitsForBird(sourceBird.id, req.auth!.workspace.id),
listFlockNotes(req.auth!.workspace.id),
loadBirdReportPhotoBuffer(sourceBird),
]);
const birdNotes = notes.filter((note) => note.bird_id === sourceBird.id);
const pdf = await renderAdoptionReportPdf({
@@ -3579,8 +3611,8 @@ app.post(
weights,
vetVisits,
notes: birdNotes,
workspace: req.auth!.workspace,
transferCode: transferCode.code,
birdPhotoBuffer,
printFriendly: req.query.printFriendly === 'true',
assets: {
logoPath: path.join(process.cwd(), 'assets', 'flockpal-logo.png'),