Skip to content

Commit d5f9398

Browse files
authored
Merge pull request #2403 from trycompai/main
[comp] Production Deploy
2 parents 2193303 + 85b5087 commit d5f9398

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

apps/api/src/policies/policies.service.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,16 +1187,16 @@ export class PoliciesService {
11871187
throw new NotFoundException('Organization not found');
11881188
}
11891189

1190-
// Get all published policies with currentVersion
1190+
// Get all non-archived policies, prioritizing published > needs_review > draft
11911191
const policies = await db.policy.findMany({
11921192
where: {
11931193
organizationId,
1194-
status: 'published',
11951194
isArchived: false,
11961195
},
11971196
select: {
11981197
id: true,
11991198
name: true,
1199+
status: true,
12001200
content: true,
12011201
pdfUrl: true,
12021202
currentVersion: {
@@ -1210,9 +1210,19 @@ export class PoliciesService {
12101210
});
12111211

12121212
if (policies.length === 0) {
1213-
throw new NotFoundException('No published policies available');
1213+
throw new NotFoundException('No policies available');
12141214
}
12151215

1216+
// Sort by status priority: published first, then needs_review, then draft
1217+
const statusPriority: Record<string, number> = {
1218+
published: 0,
1219+
needs_review: 1,
1220+
draft: 2,
1221+
};
1222+
policies.sort(
1223+
(a, b) => (statusPriority[a.status] ?? 3) - (statusPriority[b.status] ?? 3),
1224+
);
1225+
12161226
const mergedPdf = await PDFDocument.create();
12171227
const organizationName = organization.name || 'Organization';
12181228
const accentColor = this.getAccentColor(organization.primaryColor);
@@ -1231,6 +1241,7 @@ export class PoliciesService {
12311241
};
12321242

12331243
// Helper to get effective content and pdfUrl (version first, fallback to policy)
1244+
// Matches single policy download logic
12341245
const getEffectiveData = (policy: (typeof policies)[0]) => {
12351246
const content = policy.currentVersion?.content ?? policy.content;
12361247
const pdfUrl = policy.currentVersion?.pdfUrl ?? policy.pdfUrl;

0 commit comments

Comments
 (0)