-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhelpers.js
53 lines (48 loc) · 1.16 KB
/
helpers.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
exports.siteName = "This is a tile";
exports.parseResultSet = data => JSON.parse(JSON.stringify(data));
exports.echo = function(obj) {
// eslint-disable-next-line no-console
console.log(obj);
};
exports.readBody = function(req) {
let opt = {};
let {
offset,
limit,
fields,
soft_delete,
verbose,
sort_by,
group_by,
total_rows
} = req.query;
opt.method = req.method;
if (opt.method === "PUT" || opt.method === "POST") {
opt.fields = req.body;
} else {
fields = fields ? fields.split(",") : undefined;
if (fields) {
opt.columns = fields;
}
}
//Please remove this
if (req.user) {
opt.user_id = req.user.user_id;
} else {
opt.user_id = 1;
}
offset = parseInt(offset);
limit = parseInt(limit);
if (soft_delete) opt.soft_delete = soft_delete == "true";
if (verbose) opt.verbose = verbose == "true";
if (limit > 0) opt.limit = limit;
if (offset > 0) opt.offset = offset;
if (sort_by) opt.order_by = sort_by;
if (group_by) opt.group_by = group_by;
if (total_rows) {
opt.total_rows = total_rows == "true" ? true : false;
} else {
opt.total_rows = false;
}
return opt;
};