• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GEWIS / sudosos-backend / 25753937432

12 May 2026 09:17AM UTC coverage: 88.117% (-1.0%) from 89.089%
25753937432

push

github

web-flow
chore(deps): fix missing dependencies for running docs:dev (#911)

3925 of 4574 branches covered (85.81%)

Branch coverage included in aggregate %.

20093 of 22683 relevant lines covered (88.58%)

1125.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/controller/request/validators/user-request-spec.ts
1
/**
1✔
2
 *  SudoSOS back-end API service.
3
 *  Copyright (C) 2026 Study association GEWIS
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as published
7
 *  by the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 *
18
 *  @license
19
 */
1✔
20

21
/**
1✔
22
 * This is the module page of the user-request-spec.
23
 *
24
 * @module internal/spec/user-request-spec
25
 */
1✔
26

27
import {
28
  Specification, toFail, toPass, ValidationError,
29
} from '../../../helpers/specification-validation';
30
import { maxLength, nonZeroString } from './string-spec';
31
import { UserType } from '../../../entity/user/user';
32
import { INVALID_USER_TYPE } from './validation-errors';
33
import validator from 'validator';
34
import BaseUserRequest, { CreateUserRequest } from '../user-request';
35

36
/**
1✔
37
 * Most names cannot be '' or longer than 64.
38
 */
1✔
39
const nameSpec: () => Specification<string, ValidationError> = () => [
1✔
40
  nonZeroString,
7✔
41
  maxLength(64),
7✔
42
];
7✔
43

44
function validEmail(mail: string) {
5✔
45
  if (mail === undefined) return toFail(new ValidationError('invalid e-mail'));
5!
46
  if (validator.isEmail(mail)) return toPass(mail);
5!
47
  else return toFail(new ValidationError('invalid e-mail'));
×
48
}
5✔
49

50
/**
1✔
51
 * Checks if provided type is valid
52
 */
1✔
53
function validUserType(u: CreateUserRequest) {
4✔
54
  if (!Object.values(UserType).includes(u.type)) {
4!
55
    return toFail(INVALID_USER_TYPE());
×
56
  }
×
57
  return toPass(u);
4✔
58
}
4✔
59

60
/**
1✔
61
 * When updating we check firstName and lastName.
62
 */
1✔
63
const updateUserSpec: <T extends BaseUserRequest>() => Specification<T, ValidationError> = () => [
1✔
64
  [nameSpec(), 'firstName', new ValidationError('Firstname: ')],
7✔
65
  [[validEmail], 'email', new ValidationError('E-mail: ')],
7✔
66
  [[maxLength(64)], 'lastName', new ValidationError('Lastname: ')],
7✔
67
];
7✔
68

69
/**
1✔
70
 * When creating a user we also check the userType
71
 */
1✔
72
const createUserSpec: () => Specification<CreateUserRequest, ValidationError> = () => [
1✔
73
  ...updateUserSpec<CreateUserRequest>(),
7✔
74
  validUserType,
7✔
75
];
7✔
76

77
export function createUserRequestSpecFactory(): Specification<CreateUserRequest, ValidationError> {
1✔
78
  return createUserSpec();
7✔
79
}
7✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc