• 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

85.14
/src/controller/request/validators/general-validators.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 general-validators.
23
 *
24
 * @module internal/spec
25
 */
1✔
26

27
import { toFail, toPass, ValidationError } from '../../../helpers/specification-validation';
28
import User, { TermsOfServiceStatus, UserType } from '../../../entity/user/user';
29
import {
30
  EMPTY_ARRAY,
31
  INVALID_ACTIVE_USER_ID, INVALID_CUSTOM_ROLE_ID,
32
  INVALID_ORGAN_ID,
33
  INVALID_ROLE_ID,
34
  INVALID_USER_ID,
35
} from './validation-errors';
36
import { In } from 'typeorm';
37
import Role from '../../../entity/rbac/role';
38

39
export const positiveNumber = async (p: number) => {
1✔
40
  if (p <= 0) return toFail(new ValidationError('Number must be positive'));
×
41
  return toPass(p);
×
42
};
×
43

44
export const userMustExist = async (p: number) => {
1✔
45
  if (await User.findOne({ where: {
12✔
46
    id: p, acceptedToS: In([TermsOfServiceStatus.ACCEPTED, TermsOfServiceStatus.NOT_REQUIRED]),
12✔
47
  } }) == null) {
12✔
48
    return toFail(INVALID_USER_ID());
2✔
49
  }
2✔
50
  return toPass(p);
10✔
51
};
10✔
52

53
export const activeUserMustExist = async (p: number) => {
1✔
54
  if (await User.findOne({ where: { id: p, active: true } }) == null) {
×
55
    return toFail(INVALID_ACTIVE_USER_ID());
×
56
  }
×
57
  return toPass(p);
×
58
};
×
59

60
export const ownerIsOrgan = async (id: number) => {
1✔
61
  const owner = await User.findOne({ where: { id, deleted: false, type: UserType.ORGAN } });
6✔
62
  if (!owner) return toFail(INVALID_ORGAN_ID());
6✔
63
  return toPass(id);
3✔
64
};
3✔
65

66
export const nonEmptyArray = async <T>(list: T[]) => {
1✔
67
  if (list.length === 0) {
17!
68
    return toFail(EMPTY_ARRAY());
×
69
  }
×
70
  return toPass(list);
17✔
71
};
17✔
72

73
export const rolesMustExist = async (ids: number[] | undefined) => {
1✔
74
  if (ids == undefined) return toPass(ids);
12✔
75
  const roles = await Role.find({ where: { id: In(ids) } });
7✔
76
  const foundIds = roles.map((role) => role.id);
7✔
77
  for (let id of ids) {
7✔
78
    if (!foundIds.includes(id)) {
7✔
79
      return toFail(INVALID_ROLE_ID(id));
2✔
80
    }
2✔
81
  }
7✔
82
  return toPass(ids);
5✔
83
};
5✔
84

85
export const rolesCannotBeSystemDefault = async (ids: number[]) => {
1✔
86
  if (ids == undefined) return toPass(ids);
10✔
87
  const roles = await Role.find({ where: { id: In(ids) } });
5✔
88
  const systemDefaultRoles = roles.filter((r) => r.systemDefault);
5✔
89
  if (systemDefaultRoles.length > 0) {
9✔
90
    return toFail(INVALID_CUSTOM_ROLE_ID(systemDefaultRoles[0].id));
2✔
91
  }
2✔
92
  return toPass(ids);
3✔
93
};
3✔
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