Skip to content

Commit 3e91ff2

Browse files
authored
[resumes][feat] delete resume file on deletion (#555)
1 parent 0e02e23 commit 3e91ff2

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

apps/portal/prisma/schema.prisma

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ model ResumesResume {
154154
id String @id @default(cuid())
155155
userId String
156156
title String @db.Text
157-
// TODO: Update role, experience, location to use Enums
158157
role String @db.Text
159158
experience String @db.Text
160159
locationId String

apps/portal/src/components/resumes/badges/resumeBadgeConstants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export type BadgeInfo = {
2020
title: string;
2121
};
2222

23-
// TODO: Add other badges in
2423
export type BadgePayload = {
2524
maxResumeUpvoteCount: number;
2625
reviewedResumesCount: number;

apps/portal/src/pages/api/file-storage.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export default async function handler(
1717
req: NextApiRequest,
1818
res: NextApiResponse,
1919
) {
20-
if (req.method === 'POST') {
21-
try {
20+
try {
21+
if (req.method === 'POST') {
2222
const form = formidable({ keepExtensions: true });
2323
form.parse(req, async (err, fields, files) => {
2424
if (err) {
@@ -45,8 +45,26 @@ export default async function handler(
4545
url: `${BASE_FILE_URL}/${key}/${filePath}`,
4646
});
4747
});
48-
} catch (error: unknown) {
49-
return Promise.reject(error);
48+
} else if (req.method === 'DELETE') {
49+
const { key, fileUrl } = req.query;
50+
const storageKey = key as string;
51+
const url = fileUrl as string;
52+
53+
const filePath = url.substring(url.lastIndexOf('/') + 1);
54+
55+
const { error } = await supabase.storage
56+
.from(storageKey)
57+
.remove([filePath]);
58+
59+
if (error) {
60+
throw error;
61+
}
62+
63+
return res.status(200).json({
64+
message: `File ${filePath} has been deleted`,
65+
});
5066
}
67+
} catch (error: unknown) {
68+
return Promise.reject(error);
5169
}
5270
}

apps/portal/src/pages/resumes/[resumeId].tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import axios from 'axios';
12
import clsx from 'clsx';
23
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
34
import Error from 'next/error';
@@ -25,6 +26,7 @@ import ResumePdf from '~/components/resumes/ResumePdf';
2526
import ResumeExpandableText from '~/components/resumes/shared/ResumeExpandableText';
2627
import loginPageHref from '~/components/shared/loginPageHref';
2728

29+
import { RESUME_STORAGE_KEY } from '~/constants/file-storage-keys';
2830
import {
2931
BROWSE_TABS_VALUES,
3032
getFilterLabel,
@@ -183,10 +185,15 @@ export default function ResumeReviewPage() {
183185
return deleteResumeMutation.mutate(
184186
{ id: resumeId as string },
185187
{
186-
onSuccess() {
187-
// TODO: Delete from file storage
188+
async onSuccess() {
189+
// Delete from file storage
190+
if (detailsQuery.data != null) {
191+
await axios.delete(
192+
`/api/file-storage?key=${RESUME_STORAGE_KEY}&fileUrl=${detailsQuery.data.url}`,
193+
);
194+
}
188195

189-
// redirect to browse with default settings
196+
// Redirect to browse with default settings
190197
router.push({
191198
pathname: '/resumes',
192199
query: {

0 commit comments

Comments
 (0)