-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (60 loc) · 2.14 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function() {
"use strict";
var Foxx = require("org/arangodb/foxx"),
ArangoError = require("org/arangodb").ArangoError,
Users = require("./repositories/users").Repository,
Friendships = require("./repositories/friendships").Repository,
User = require("./models/user").Model,
Friendship = require("./models/friendship").Model,
users,
friendships,
controller;
controller = new Foxx.Controller(applicationContext);
users = new Users(controller.collection("users"), {
model: User
});
friendships = new Friendships(controller.collection("friendships"), {
model: Friendship
});
friendships.usersCollection = controller.collection("users").name();
controller.post("/user", function(req, res) {
var toAdd = req.params("user");
users.save(toAdd);
}).bodyParam("user", "The user information to add", User);
controller.get("/user/:key", function(req, res) {
var key = req.params("key");
res.json(users.byId(key));
}).pathParam("key", {
description: "The key of the user",
type: "string"
});
controller.get("/user-by-name/:name", function(req, res) {
var name = req.params("name");
res.json(users.byName(name));
}).pathParam("name", {
description: "The name of the user you want to find",
type: "string"
}).errorResponse(ArangoError, 404, "User not found");
controller.get("/user", function(req, res) {
res.json(users.summaries());
});
controller.put("/user/:key", function(req, res) {
var key = req.params("key"),
newInformation = req.params("user");
users.replaceById(key, newInformation);
}).pathParam("key", {
description: "The key of the user",
type: "string"
}).bodyParam("user", "The user information to add", User);
controller.del("/user/:key", function(req, res) {
var key = req.params("key");
users.removeById(key);
}).pathParam("key", {
description: "The key of the user",
type: "string"
});
controller.post("/friendship", function(req, res) {
var friendship = req.params("friendship");
friendships.save(friendship);
}).bodyParam("friendship", "The friendship you want to create", Friendship);
}());