Skip to content

Commit 4757430

Browse files
authored
Merge pull request #2365 from trycompai/main
[comp] Production Deploy
2 parents dfdf39d + 3cc3fb1 commit 4757430

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,12 @@ export class PoliciesService {
14351435
organizationId,
14361436
);
14371437

1438+
const fileName = `${organizationName} - All Policies.pdf`;
14381439
const downloadUrl =
1439-
await this.attachmentsService.getPresignedDownloadUrl(key);
1440+
await this.attachmentsService.getPresignedDownloadUrlWithFilename(
1441+
key,
1442+
fileName,
1443+
);
14401444

14411445
this.logger.log(
14421446
`Generated PDF bundle for organization ${organizationId} with ${policies.length} policies`,

apps/app/src/app/(app)/[orgId]/policies/all/components/PolicyPageActions.test.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ vi.mock('@/components/sheets/create-policy-sheet', () => ({
2020
CreatePolicySheet: () => <div data-testid="create-policy-sheet" />,
2121
}));
2222

23-
// Mock pdf-generator
24-
vi.mock('@/lib/pdf-generator', () => ({
25-
downloadAllPolicies: vi.fn(),
26-
}));
27-
2823
// Mock api client
2924
vi.mock('@/lib/api-client', () => ({
3025
api: { get: vi.fn() },

apps/app/src/app/(app)/[orgId]/policies/all/components/PolicyPageActions.tsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
import { CreatePolicySheet } from '@/components/sheets/create-policy-sheet';
44
import { api } from '@/lib/api-client';
55
import { Add, Download } from '@carbon/icons-react';
6-
import type { AuditLog, Member, Organization, Policy, User } from '@db';
6+
import type { Policy } from '@db';
77
import { Button, HStack } from '@trycompai/design-system';
88
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
99
import { useState } from 'react';
10+
import { toast } from 'sonner';
1011
import { usePermissions } from '@/hooks/use-permissions';
1112

12-
type AuditLogWithRelations = AuditLog & {
13-
user: User | null;
14-
member: Member | null;
15-
organization: Organization;
16-
};
17-
1813
interface PolicyPageActionsProps {
1914
policies: Policy[];
2015
}
@@ -29,21 +24,23 @@ export function PolicyPageActions({ policies }: PolicyPageActionsProps) {
2924
const handleDownloadAll = async () => {
3025
setIsDownloadingAll(true);
3126
try {
32-
const logsEntries = await Promise.all(
33-
policies.map(async (policy) => {
34-
const res = await api.get<{ data: AuditLogWithRelations[] }>(
35-
`/v1/audit-logs?entityType=policy&entityId=${policy.id}`,
36-
);
37-
const allLogs = Array.isArray(res.data?.data) ? res.data.data : [];
38-
const approvalLogs = allLogs.filter((log) =>
39-
log.description?.toLowerCase().includes('published'),
40-
);
41-
return [policy.id, approvalLogs] as const;
42-
}),
27+
const res = await api.get<{ downloadUrl: string; name: string; policyCount: number }>(
28+
'/v1/policies/download-all',
4329
);
44-
const policyLogs = Object.fromEntries(logsEntries);
45-
const { downloadAllPolicies } = await import('@/lib/pdf-generator');
46-
await downloadAllPolicies(policies, policyLogs);
30+
31+
if (res.error || !res.data?.downloadUrl) {
32+
toast.error('Failed to generate PDF. Please try again.');
33+
return;
34+
}
35+
36+
const link = document.createElement('a');
37+
link.href = res.data.downloadUrl;
38+
link.download = `${res.data.name ?? 'all-policies'}.pdf`;
39+
document.body.appendChild(link);
40+
link.click();
41+
document.body.removeChild(link);
42+
} catch {
43+
toast.error('Failed to download policies.');
4744
} finally {
4845
setIsDownloadingAll(false);
4946
}

0 commit comments

Comments
 (0)