diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f82fc39 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/routes/index.ts b/routes/index.ts index 5c34f35..531fec3 100644 --- a/routes/index.ts +++ b/routes/index.ts @@ -5,6 +5,8 @@ import { usersRouter } from './users/usersRoutes.js'; import { usersCVsRouter } from './users_cvs/usersCVsRoutes.js'; import { usersDealbreakersRouter } from './users_dealbreakers/userDealbreakersRoutes.js'; import { matchingRouter } from './matching/matchingRoutes.js'; +import multer from 'multer'; +import { extractCvText } from './users_cvs/users_CVsMiddleware.js'; const ROUTER = express.Router(); @@ -16,4 +18,49 @@ ROUTER.use('/users_cvs', usersCVsRouter); ROUTER.use('/users_dealbreakers', usersDealbreakersRouter); ROUTER.use('/matching', matchingRouter); +const upload = multer({ storage: multer.memoryStorage() }); // keep file in memory +// this endpoint is intentionally put here to avoid auth +// it will be moved to users_CVsRoutes after more integration testing +ROUTER.post('/upload-cv', upload.single('cv'), async (req, res) => { + // Validation: Check if file exists + if (!req.file) { + return res.status(400).json({ error: 'No file uploaded' }); + } + // Extract Dealbreakers + // Multer populates req.body with text fields. + // Since we JSON.stringify'd the array on frontend, we must JSON.parse it here. + let dealbreakers: string[] = []; + if (req.body.dealbreakers) { + try { + dealbreakers = JSON.parse(req.body.dealbreakers); + } catch (e) { + console.warn('Failed to parse dealbreakers JSON', e); + // Fallback: treat it as empty or single string if needed + } + } + + // Extract Text from CV (using middleware) + try { + const cvText = await extractCvText(req.file); + console.log('Extracted CV Length:', cvText.length); + console.log('Received Dealbreakers:', dealbreakers); + // // TO DO? Return combined data (or save to DB) + // res.json({ + // message: 'Bio received successfully', + // data: { + // cvText: cvText, + // dealbreakers: dealbreakers, + // }, + // }); + + res.json({ cvText }); + } catch (err) { + console.error(err); + // Better error handling for the client + const errorMessage = + err instanceof Error ? err.message : 'Failed to parse CV'; + res.status(500).json({ error: errorMessage }); + } +}); + export default ROUTER; diff --git a/server.ts b/server.ts index 7113b57..c2fcec2 100644 --- a/server.ts +++ b/server.ts @@ -6,6 +6,7 @@ import swaggerUi from 'swagger-ui-express'; const app = express(); +// CORS configuration - allow requests from frontend server app.use( cors({ origin: 'http://localhost:5173',