-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmgwebExamples.ro
45 lines (45 loc) · 1.25 KB
/
zmgwebExamples.ro
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
IRIS for Windows^MAC^mg-web M back-end Example APIs^~Format=IRIS.S~^RAW
%RO on 24 Apr 2024 4:44 PM
%zmgwebExamples^MAC^^65716,60263.112524^0
%zmgwebExamples ; mg-web M back-end Example APIs
buildRoutes ;
i $$buildAPIs^%zmgwebUtils("/home/irisowner/mgweb-routes.json")
QUIT
;
helloworld(req) ;
n res
s res("hello")="world"
QUIT $$response^%zmgweb(.res)
;
save(req) ;
n errors,id,res
;
i '$d(req("body")) d QUIT $$errorResponse^%zmgweb(.errors)
. s errors("error")="Missing or empty body"
;
i '$d(req("body","firstName")) d QUIT $$errorResponse^%zmgweb(.errors)
. s errors("error")="Missing or empty firstName"
;
i '$d(req("body","lastName")) d QUIT $$errorResponse^%zmgweb(.errors)
. s errors("error")="Missing or empty lastName"
;
s id=$increment(^Person("nextId"))
m ^Person("data",id)=req("body")
s res("id")=id
s res("ok")="true"
QUIT $$response^%zmgweb(.res)
;
getUser(req) ;
n errors,id,res
;
s userId=$g(req("params","userId"))
i userId="" d QUIT $$errorResponse^%zmgweb(.errors)
. s errors("error")="User Id not defined"
;
i '$D(^Person("data",userId)) d QUIT $$errorResponse^%zmgweb(.errors)
. s errors("error")="No such user in the database"
;
m res("data")=^Person("data",userId)
s res("key")=userId
QUIT $$response^%zmgweb(.res)
;