Advertisement
KoctrX

Untitled

Jul 10th, 2024
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function removeFiles() {
  2.         return multerHelper.unlinkFiles([
  3.             ...(req?.files?.introVideo || []),
  4.             ...(req?.files?.outroVideo || []),
  5.             ...(req?.files?.questionVideos || []),
  6.         ]);
  7.     }
  8.  
  9.     try {
  10.         console.log('DATA: ', req.body);
  11.         console.log('FILES: ', req.files);
  12.  
  13.         const introFile = req?.files?.introVideo[0] || false;
  14.         const outroFile = req?.files?.outroVideo[0] || false;
  15.         const questionFiles = req?.files?.questionVideos || [];
  16.  
  17.         const result = await api.job.createJob({
  18.             name: req?.body?.name || 'Unnamed',
  19.             interview: {
  20.                 intro: introFile ? { fileUpload: null } : null,
  21.  
  22.                 outro: {
  23.                     title: req?.body?.outro?.title || undefined,
  24.                     description: req?.body?.outro?.description || undefined,
  25.                     media: outroFile ? { fileUpload: null } : undefined
  26.                 },
  27.  
  28.                 questions: (req?.body?.questions || []).map(question => ({
  29.                     ...question//, media: { fileUpload: null }
  30.                 })),
  31.  
  32.                 introFile, outroFile, questionFiles
  33.             }
  34.         });
  35.  
  36.         await removeFiles();
  37.         res.send({ data: result, success: true });
  38.     } catch (err) {
  39.         await removeFiles();
  40.         next(err);
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement