[resumes][feat] delete resume file on deletion (#555)

pull/556/head
Keane Chan 2 years ago committed by GitHub
parent 0e02e23015
commit 3e91ff2d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -20,7 +20,6 @@ export type BadgeInfo = {
title: string;
};
// TODO: Add other badges in
export type BadgePayload = {
maxResumeUpvoteCount: number;
reviewedResumesCount: number;

@ -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);
}
}

@ -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: {

Loading…
Cancel
Save