Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/api/src/offboarding-checklist/access-revocation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ export class AccessRevocationService {
where: { id: revocation.id },
});

await this.syncAccessRevocationCompletion(organizationId, memberId);
try {
await this.syncAccessRevocationCompletion(organizationId, memberId);
} catch (err) {
this.logger.warn(`Failed to sync access revocation completion for member ${memberId}`, err);
}

return { success: true };
}
Expand Down Expand Up @@ -221,7 +225,11 @@ export class AccessRevocationService {
});
}

await this.syncAccessRevocationCompletion(organizationId, memberId, revokedById);
try {
await this.syncAccessRevocationCompletion(organizationId, memberId, revokedById);
} catch (err) {
this.logger.warn(`Failed to sync access revocation completion for member ${memberId}`, err);
}

return { confirmed: toCreate.length };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,44 @@ export class OffboardingChecklistService {
completions.map((c) => [c.templateItemId, c]),
);

const completionIds = completions.map((c) => c.id);

const allAttachments =
completionIds.length > 0
? await db.attachment.findMany({
where: {
organizationId,
entityId: { in: completionIds },
entityType: AttachmentEntityType.offboarding_checklist,
},
orderBy: { createdAt: 'asc' },
})
: [];

const attachmentsByCompletion = new Map<string, typeof allAttachments>();
for (const attachment of allAttachments) {
const existing = attachmentsByCompletion.get(attachment.entityId) ?? [];
existing.push(attachment);
attachmentsByCompletion.set(attachment.entityId, existing);
}

const items = await Promise.all(
templateItems.map(async (template) => {
const completion = completionMap.get(template.id);
const evidence = completion
? await this.attachmentsService.getAttachments(
organizationId,
completion.id,
AttachmentEntityType.offboarding_checklist,
)
const rawAttachments = completion
? (attachmentsByCompletion.get(completion.id) ?? [])
: [];

const evidence = await Promise.all(
rawAttachments.map(async (attachment) => ({
id: attachment.id,
name: attachment.name,
type: attachment.type,
downloadUrl: await this.attachmentsService.getPresignedDownloadUrl(attachment.url),
createdAt: attachment.createdAt,
})),
);

return {
...template,
templateItemId: template.id,
Expand Down

This file was deleted.

13 changes: 1 addition & 12 deletions apps/app/src/hooks/use-access-revocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useApi } from '@/hooks/use-api';
import { useApiSWR } from '@/hooks/use-api-swr';
import { fileToBase64 } from '@/lib/file-utils';
import { useCallback } from 'react';

interface RevokedBy {
Expand Down Expand Up @@ -84,15 +85,3 @@ export function useAccessRevocations(memberId: string) {
revokeAll,
};
}

function fileToBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const result = reader.result as string;
resolve(result.split(',')[1]);
};
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});
}
13 changes: 1 addition & 12 deletions apps/app/src/hooks/use-offboarding-checklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { useApi } from '@/hooks/use-api';
import { useApiSWR } from '@/hooks/use-api-swr';
import { fileToBase64 } from '@/lib/file-utils';
import { useCallback } from 'react';

interface CompletedBy {
Expand Down Expand Up @@ -129,15 +130,3 @@ export function useOffboardingChecklist(memberId: string) {
refreshChecklist: mutate,
};
}

function fileToBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const result = reader.result as string;
resolve(result.split(',')[1]);
};
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});
}
11 changes: 11 additions & 0 deletions apps/app/src/lib/file-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function fileToBase64(file: File): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const result = reader.result as string;
resolve(result.split(',')[1]);
};
reader.onerror = () => reject(new Error('Failed to read file'));
reader.readAsDataURL(file);
});
}
Loading