-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror-checking.js
66 lines (59 loc) · 2.17 KB
/
error-checking.js
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
59
60
61
62
63
64
65
66
/*globals COLUMN_WORKSHOP_NAME, COLUMN_WORKSHOP_CAPACITY, COLUMN_FIRST_NAME,
COLUMN_LAST_NAME, COLUMN_GRADE, PREFERENCE_COLUMNS, Logger */
// Functions that check the inputs for valid types. Can be extended to check
// for other params.
// Current version only checks if the correct type in the correct column.
// Really only makes sure that integers are where they should be and gives row
// and column of incorrect input.
function workshopInputChecker(name, capacity, location, row) {
// Increment the row number to make it match the sheet's row numbers
row++;
if (typeof name !== "string") {
throw new Error(
"Invalid workshop at row " +
row +
" column " +
COLUMN_WORKSHOP_NAME +
" in workshop sheet"
);
}
if (typeof capacity !== "number" || isNaN(capacity)) {
throw new Error(
"Invalid workshop capacity at row " +
row +
" column " +
COLUMN_WORKSHOP_CAPACITY +
" in workshop sheet"
);
}
}
function studentInputChecker(firstName, lastName, grade, row) {
// Increment the row number to make it match the sheet's row numbers
row++;
if (typeof firstName !== "string") {
throw new Error(
"Invalid first name at row " + row + " column " + COLUMN_FIRST_NAME
);
}
if (typeof lastName !== "string") {
throw new Error(
"Invalid last name at row " + row + " column " + COLUMN_LAST_NAME
);
}
if (typeof grade !== "string") {
throw new Error(
"Invalid grade at row " + row + " column " + COLUMN_GRADE
);
}
}
function preferenceInputChecker(workshopNum, row, preferenceNumber) {
// Increment the row number to make it match the sheet's row numbers
row++;
if (typeof workshopNum !== "number" || isNaN(workshopNum)) {
const columnLetterCodepoint = 65 + PREFERENCE_COLUMNS[preferenceNumber];
const columnLetter = String.fromCharCode(columnLetterCodepoint);
throw new Error(
"Invalid workshop number at row " + row + " column " + columnLetter
);
}
}