-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMain.gs
82 lines (58 loc) · 1.8 KB
/
Main.gs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function doPost(request) {
var route = Config.route.post(request.parameter.route)
if(! route){
Response.message = ['Route parameter must be set on config'];
return Response.fail();
}
App.init(request);
Database.checkColumn();
var activeRow = Database.getRow();
var rule = Validation.run();
if(!rule){
return Response.fail();
}
App.config.allowMethod = Config.route.post(App.config.request.parameter.route)
if(App.config.action=="put")
{
if(activeRow==-1){
if(App.config.allowMethod.indexOf("insert") ==-1){
Response.message.push(App.config.key+" does not exists.");
return Response.fail();
}
var id= Database.insertData();
Response.message = ["Data has been added."];
return Response.success();
}
var id= Database.updateData(activeRow);
Response.message = ["Data has been updated."];
return Response.success();
}
if(activeRow==-1){
Response.message = [App.config.key+" does not exists."];
return Response.fail();
}
Database.deleteData(activeRow);
Response.message = ["Data has beeen deleted."];
return Response.success();
}
/*
filter request for post method
*/
function doGet(request){
var route = Config.route.get(request.parameter.route)
if(! route){
Response.message.push('Route paramerer must be set on config');
return Response.fail();
}
App.init(request);
Database.checkColumn();
if(App.config.request.parameter[App.config.key]){
var activeRow = Database.getRow();
if(activeRow==-1 || activeRow==false){
Response.message.push('Data with '+myInit.key+ ' not found.');
return Response.fail();
}
return Response.result(Database.getOne(activeRow));
}
return Response.result(Database.getMany());
}