diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index c73aab8a..c4d38a73 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -154,7 +154,6 @@ model ResumesResume { id String @id @default(cuid()) userId String title String @db.Text - // TODO: Update role, experience, location to use Enums role String @db.Text experience String @db.Text locationId String diff --git a/apps/portal/src/components/resumes/badges/resumeBadgeConstants.ts b/apps/portal/src/components/resumes/badges/resumeBadgeConstants.ts index bb3f36ad..db198228 100644 --- a/apps/portal/src/components/resumes/badges/resumeBadgeConstants.ts +++ b/apps/portal/src/components/resumes/badges/resumeBadgeConstants.ts @@ -20,7 +20,6 @@ export type BadgeInfo = { title: string; }; -// TODO: Add other badges in export type BadgePayload = { maxResumeUpvoteCount: number; reviewedResumesCount: number; diff --git a/apps/portal/src/pages/api/file-storage.ts b/apps/portal/src/pages/api/file-storage.ts index cc48bab1..4295c043 100644 --- a/apps/portal/src/pages/api/file-storage.ts +++ b/apps/portal/src/pages/api/file-storage.ts @@ -17,8 +17,8 @@ export default async function handler( req: NextApiRequest, res: NextApiResponse, ) { - if (req.method === 'POST') { - try { + try { + if (req.method === 'POST') { const form = formidable({ keepExtensions: true }); form.parse(req, async (err, fields, files) => { if (err) { @@ -45,8 +45,26 @@ export default async function handler( url: `${BASE_FILE_URL}/${key}/${filePath}`, }); }); - } catch (error: unknown) { - return Promise.reject(error); + } else if (req.method === 'DELETE') { + const { key, fileUrl } = req.query; + const storageKey = key as string; + const url = fileUrl as string; + + const filePath = url.substring(url.lastIndexOf('/') + 1); + + const { error } = await supabase.storage + .from(storageKey) + .remove([filePath]); + + if (error) { + throw error; + } + + return res.status(200).json({ + message: `File ${filePath} has been deleted`, + }); } + } catch (error: unknown) { + return Promise.reject(error); } } diff --git a/apps/portal/src/pages/resumes/[resumeId].tsx b/apps/portal/src/pages/resumes/[resumeId].tsx index 97f78efe..1b36c53d 100644 --- a/apps/portal/src/pages/resumes/[resumeId].tsx +++ b/apps/portal/src/pages/resumes/[resumeId].tsx @@ -1,3 +1,4 @@ +import axios from 'axios'; import clsx from 'clsx'; import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import Error from 'next/error'; @@ -25,6 +26,7 @@ import ResumePdf from '~/components/resumes/ResumePdf'; import ResumeExpandableText from '~/components/resumes/shared/ResumeExpandableText'; import loginPageHref from '~/components/shared/loginPageHref'; +import { RESUME_STORAGE_KEY } from '~/constants/file-storage-keys'; import { BROWSE_TABS_VALUES, getFilterLabel, @@ -183,10 +185,15 @@ export default function ResumeReviewPage() { return deleteResumeMutation.mutate( { id: resumeId as string }, { - onSuccess() { - // TODO: Delete from file storage + async onSuccess() { + // Delete from file storage + if (detailsQuery.data != null) { + await axios.delete( + `/api/file-storage?key=${RESUME_STORAGE_KEY}&fileUrl=${detailsQuery.data.url}`, + ); + } - // redirect to browse with default settings + // Redirect to browse with default settings router.push({ pathname: '/resumes', query: {