-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcheckin.validator.js
More file actions
58 lines (55 loc) · 2.11 KB
/
checkin.validator.js
File metadata and controls
58 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"use strict";
const { body } = require('express-validator');
const {
PRIZE_CATEGORIES,
SPONSOR_CHALLENGES,
MLH_CHALLENGES
} = require('../../constants/checkin-options');
/**
* Validator for check-in form submission
*/
const checkinValidator = [
body('formData.prizeCategories')
.isArray()
.withMessage('Prize categories must be an array')
.custom((values) =>
Array.isArray(values) &&
values.every((value) => typeof value === 'string' && PRIZE_CATEGORIES.includes(value))
)
.withMessage('Prize categories contain invalid selections'),
body('formData.sponsorChallenges')
.isArray()
.withMessage('Sponsor challenges must be an array')
.custom((values) =>
Array.isArray(values) &&
values.every((value) => typeof value === 'string' && SPONSOR_CHALLENGES.includes(value))
)
.withMessage('Sponsor challenges contain invalid selections'),
body('formData.mlhChallenges')
.isArray()
.withMessage('MLH challenges must be an array')
.custom((values) =>
Array.isArray(values) &&
values.every((value) => typeof value === 'string' && MLH_CHALLENGES.includes(value))
)
.withMessage('MLH challenges contain invalid selections'),
// body('formData.workshopsAttended').isArray().withMessage('Workshops attended must be an array'),
body('formData.discordTag').notEmpty().withMessage('Discord tag is required'),
body('formData.devpostLink')
.notEmpty()
.withMessage('Devpost link is required')
.bail()
.isURL({ require_protocol: true, protocols: ['http', 'https'] })
.withMessage('Devpost link must be a valid URL')
.bail()
.custom((value) => {
try {
const url = new URL(value);
return url.hostname === 'devpost.com' || url.hostname.endsWith('.devpost.com');
} catch (error) {
return false;
}
})
.withMessage('Devpost link must be a devpost.com URL')
];
module.exports = checkinValidator;