-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathri_api.js
More file actions
38 lines (35 loc) · 1.19 KB
/
ri_api.js
File metadata and controls
38 lines (35 loc) · 1.19 KB
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
(function() {
"use strict";
var Controller = require("org/arangodb/foxx").Controller,
Repository = require("org/arangodb/foxx").Repository,
console = require("console"),
arangodb = require("org/arangodb"),
actions = require("org/arangodb/actions"),
controller = new Controller(applicationContext),
words = new Repository(controller.collection("words"));
/** returns random Word
*
* returns random word form the database
*/
controller.get("/random", function (req, res) {
var result = words.collection.any();
var c = result.anzahl;
if(true == isNaN(c))
c = 0;
c++;
words.collection.update(result._id,{"anzahl": c});
res.responseCode = actions.HTTP_OK;
res.contentType = "application/json; charset=utf-8";
res.body = JSON.stringify(result);
});
/** add new Word
*
* adds new word into the database
*/
controller.post("/new", function (req, res) {
words.collection.save(JSON.parse(req.requestBody));
res.responseCode = actions.HTTP_OK;
res.contentType = "application/json; charset=utf-8";
res.body = JSON.stringify({ "msg": "stored" });
});
}());