• 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

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

27
import {
28
  Specification, toFail, toPass, ValidationError,
29
} from '../../../helpers/specification-validation';
30
import Duration from '../duration';
31
import { INVALID_DATE, INVALID_DATE_DURATION } from './validation-errors';
32

33
/**
1✔
34
 * Tests if the string is a valid date.
35
 * @param d
36
 */
1✔
37
export function validDate(d: string) {
1✔
38
  if (Number.isNaN(Date.parse(d))) {
6!
39
    return toFail(INVALID_DATE());
×
40
  }
×
41
  return toPass(d);
6✔
42
}
6✔
43

44
/**
1✔
45
 * Tests if the string is valid date or undefined
46
 * @param d
47
 */
1✔
48
export function validOrUndefinedDate(d: string) {
1✔
49
  if (!d) return toPass(d);
×
50
  return validDate(d);
×
51
}
×
52

53
/**
1✔
54
 * Tests if the endDate is after startDate
55
 * @param d - Request to check
56
 */
1✔
57
function endAfterStart<T extends Duration>(d: T) {
3✔
58
  if (Date.parse(d.endDate) <= Date.parse(d.startDate)) {
3!
59
    return toFail(INVALID_DATE_DURATION());
×
60
  }
×
61
  return toPass(d);
3✔
62
}
3✔
63

64
function durationSpec<T extends Duration>(): Specification<T, ValidationError> {
5✔
65
  return [
5✔
66
    [[validDate], 'startDate', new ValidationError('startDate:')],
5✔
67
    [[validDate], 'endDate', new ValidationError('endDate:')],
5✔
68
    endAfterStart,
5✔
69
  ];
5✔
70
}
5✔
71

72
export default durationSpec;
1✔
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