Skip to content

Commit 2aae684

Browse files
committed
Support Uploading Resume As .txt/.text
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
1 parent fffa215 commit 2aae684

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

nextstep-backend/src/openapi/swagger.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ paths:
800800
file:
801801
type: string
802802
format: binary
803-
description: The resume file to upload (PDF, DOC, DOCX)
803+
description: The resume file to upload (PDF, DOC, DOCX, TXT)
804804
jobDescription:
805805
type: string
806806
description: Optional job description for scoring
@@ -820,7 +820,7 @@ paths:
820820
fileTooLarge:
821821
value: "File too large"
822822
invalidFileType:
823-
value: "Invalid file type. Only PDF, DOC, and DOCX files are allowed"
823+
value: "Invalid file type. Only PDF, DOC, DOCX and TXT/TEXT files are allowed"
824824
noFileUploaded:
825825
value: "No file uploaded"
826826
'401':

nextstep-backend/src/services/resources_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ const createResumesStorage = () => {
7070
fileSize: config.resources.resumeMaxSize()
7171
},
7272
fileFilter: (req, file, cb) => {
73-
const allowedTypes = /pdf|doc|docx/;
73+
const allowedTypes = /pdf|doc|docx|txt|text/;
7474
const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase());
7575
const mimetype = allowedTypes.test(file.mimetype);
7676

7777
if (extname && mimetype) {
7878
return cb(null, true);
7979
} else {
80-
return cb(new TypeError(`Invalid file type. Only PDF, DOC, and DOCX files are allowed.`));
80+
return cb(new TypeError(`Invalid file type. Only PDF, DOC, DOCX and TXT/TEXT files are allowed.`));
8181
}
8282
}
8383
});

nextstep-backend/src/services/resume_service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const parseDocument = async (filePath: string): Promise<string> => {
5959
case '.doc':
6060
return await parseWord(filePath);
6161
case '.txt':
62+
case '.text':
6263
return fs.readFileSync(filePath, 'utf-8');
6364
default:
6465
throw new Error(`Unsupported file format: ${ext}`);

nextstep-backend/src/tests/resources_resumes.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ describe('Resume API Tests', () => {
126126
it('should validate file type', async () => {
127127
const response = await request(app)
128128
.post('/resource/resume')
129-
.attach('file', Buffer.from('invalid content'), { filename: 'test.txt' })
129+
.attach('file', Buffer.from('invalid content'), { filename: 'test.png' })
130130
.expect(400);
131131

132-
expect(response.text).toBe('Invalid file type. Only PDF, DOC, and DOCX files are allowed.');
132+
expect(response.text).toBe('Invalid file type. Only PDF, DOC, DOCX and TXT/TEXT files are allowed.');
133133
});
134134

135135
it('should handle missing file', async () => {

0 commit comments

Comments
 (0)