-
Notifications
You must be signed in to change notification settings - Fork 0
/
3.sync_function_run.js
42 lines (31 loc) · 1.05 KB
/
3.sync_function_run.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
function(doc, oldDoc) {
let a;
try {
a = doc._id.split("-");
} catch (error) {
throw({ forbidden: "error: invalid document ID format" });
}
if (doc.deleted && doc.deleted == true) {
requireRole(["editor", "admin"]);
} else {
if (a[0] === "order") {
requireRole(["editor", "admin", "user"]);
fieldCheck(doc.channels);
channel(doc.channels);
} else if (a[0] === "job") {
requireRole(["manager","editor", "admin"]);
fieldCheck(doc.channels);
channel(doc.channels);
} else {
throw({forbidden: "error: invalid docType"});
}
}
}
function fieldCheck(elementName) {
// Check if elementName exists in the data object, is not null, not empty, and not an integer
if (typeof elementName !== 'undefined' && elementName !== null && elementName !== '' && typeof elementName !== 'number') {
return true;
} else {
throw({forbidden: "error: field '" + elementName + "' has errors"});
}
}