Skip to content

Commit 736fd2c

Browse files
Merge pull request #23 from GabrielDeveloper/master
Release
2 parents c435623 + 25a7090 commit 736fd2c

11 files changed

Lines changed: 229 additions & 30 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*/logs/*
44
npm-debug.log
55
*.swp
6+
*.env

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IClient
22

3-
[![Build Status](https://travis-ci.org/GabrielDeveloper/iclient.svg?branch=master)](https://travis-ci.org/GabrielDeveloper/iclient)
3+
[![Build Status](https://travis-ci.org/highideas/iClient-server.svg?branch=master)](https://travis-ci.org/highideas/iClient-server)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/93364e7bc8054a9ba67f74b86c8e248e)](https://www.codacy.com/app/GabrielDeveloper/iclient?utm_source=github.com&utm_medium=referral&utm_content=GabrielDeveloper/iclient&utm_campaign=Badge_Grade)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/93364e7bc8054a9ba67f74b86c8e248e)](https://www.codacy.com/app/GabrielDeveloper/iclient?utm_source=github.com&utm_medium=referral&utm_content=GabrielDeveloper/iclient&utm_campaign=Badge_Coverage)
6-
[![codecov](https://codecov.io/gh/GabrielDeveloper/iclient/branch/master/graph/badge.svg)](https://codecov.io/gh/GabrielDeveloper/iclient)
6+
[![codecov](https://codecov.io/gh/highideas/iClient-server/branch/master/graph/badge.svg)](https://codecov.io/gh/highideas/iClient-server)
77

88

99
Simple application to mark visit to clients.
@@ -12,7 +12,6 @@
1212

1313
Client uses a number of open source projects to work properly:
1414

15-
* [AngularJS] - HTML enhanced for web apps!
1615
* [Node.js] - evented I/O for the backend
1716
* [Express] - fast node.js network app framework
1817
* [Gulp] - the streaming build system

docker-compose.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
version: '2'
22
services:
3+
iClientMongoServer:
4+
image: mongo:3.2
5+
container_name: iClientMongoServer
6+
restart: always
7+
volumes:
8+
- iClientMongoData:/data/db
9+
ports:
10+
- "27017:27017"
11+
312
iClientNodeServer:
413
image: node:4.6.0
514
container_name: iClientNodeServer
615
restart: always
16+
environment:
17+
- DATABASE_ICLIENT=${DATABASE_ICLIENT}
18+
- SECRET_ICLIENT=${SECRET_ICLIENT}
19+
command: bash -c 'cd /server/ && npm install && node /server/index.js'
720
ports:
821
- "3000:3000"
922
volumes:
1023
- ./server:/server
24+
links:
25+
- iClientMongoServer
1126
tty: true
1227

13-
iClientMongoServer:
14-
image: mongo:3.0
15-
container_name: iClientMongoServer
16-
restart: always
17-
volumes:
18-
- iClientMongoData:/data/db
19-
ports:
20-
- "27017:27017"
21-
2228
volumes:
2329
iClientMongoData: {}

server/api/v1/visit.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ module.exports = function (api) {
4646
};
4747
}));
4848

49+
api.get("/visit/:id", verifyJWT, wagner.invoke(function (Visit) {
50+
return function (req, res) {
51+
var query = {"_id" : req.params.id};
52+
Visit.find(query, function (error, visit) {
53+
if (error) {
54+
return res.
55+
status(status.INTERNAL_SERVER_ERROR).
56+
json({ error : error.toString() });
57+
}
58+
if (visit.length <= 0) {
59+
return res.
60+
status(status.NOT_FOUND).
61+
json({ error: "Not Found"});
62+
}
63+
64+
res.json({ visit : visit});
65+
});
66+
};
67+
}));
68+
4969
api.post("/visit", verifyJWT, wagner.invoke(function (Visit) {
5070
return function (req, res) {
5171
Visit.create(req.body, function (error, visit) {
@@ -120,5 +140,36 @@ module.exports = function (api) {
120140
};
121141
}));
122142

143+
api.get("/visit/group/area", verifyJWT, wagner.invoke(function (Visit) {
144+
return function (req, res) {
145+
var query = {'client.area._id' : req.params.id};
146+
Visit.aggregate([
147+
{ $sort: {visit_date: -1}},
148+
{ $group: {
149+
_id: "$client.name",
150+
visit: {$first: "$$ROOT"}
151+
}},
152+
{ $group : {
153+
_id: "$visit.client.area._id",
154+
visits: {$push: "$$ROOT"}
155+
}}
156+
],
157+
function (error, visits) {
158+
if (error) {
159+
return res.
160+
status(status.INTERNAL_SERVER_ERROR).
161+
json({ error : error.toString() });
162+
}
163+
if (visits.length <= 0) {
164+
return res.
165+
status(status.NOT_FOUND).
166+
json({ error: "Not Found"});
167+
}
168+
169+
return res.json({ visits : visits});
170+
});
171+
};
172+
}));
173+
123174
return api;
124175
};

server/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
"host": "mongodb://iClientMongoServer",
3+
"port": "27017",
4+
"database": process.env.DATABASE_ICLIENT,
5+
"secret": process.env.SECRET_ICLIENT
6+
}

server/config_test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
"host": "mongodb://localhost",
3+
"port": "27017",
4+
"database": "iclient_test",
5+
"secret": "KeySecretTest"
6+
}

server/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
global.rootPath = require("path").dirname(require.main.filename) + "/";
12
global.rootRequire = function(name) {
2-
return require(require("path").dirname(require.main.filename) + "/" + name);
3+
return require(global.rootPath + name);
34
};
45

6+
require('dotenv').config({path: global.rootPath + '.env', silent: true});
57
var express = require("express");
68
var wagner = require("wagner-core");
79
var bodyParser = require("body-parser");
@@ -32,4 +34,3 @@ app.use("/api/v1", rootRequire("api/v1/api")());
3234

3335
app.listen(3000);
3436
console.log("Listening on port 3000!");
35-

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"body-parser": "1.12.4",
1212
"codacy-coverage": "^2.0.0",
13+
"dotenv": "^2.0.0",
1314
"express": "4.12.3",
1415
"express-session": "1.11.2",
1516
"http-status": "0.1.8",

server/test/api.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@ var express = require("express");
66
var wagner = require("wagner-core");
77
var superagent = require("superagent");
88
var bodyparser = require("body-parser");
9+
var Config = rootRequire('config_test');
910

1011
var URL_ROOT = "http://localhost:3001";
1112

1213
describe("Tests API", function() {
1314
var server;
1415
var Client;
15-
var config = {
16-
"host" : "mongodb://localhost",
17-
"port" : "27017",
18-
"database" : "iclient_test",
19-
"secret" : "Keysecret-Teste"
20-
};
21-
22-
var models = rootRequire("models/models")(config);
16+
var models = rootRequire("models/models")(Config);
2317

2418
before(function () {
2519
var app = express();

server/test/client_api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function () {
5454
"name" : "Gabriel",
5555
"address" : "Street 23",
5656
"city" : "London",
57-
"area" : "Center",
57+
"area" : { "_id": "Center", 'parents' : "Center"},
5858
"frequency" : 15,
5959
"ability" : 200
6060
},
@@ -63,7 +63,7 @@ module.exports = function () {
6363
"name" : "Gonçalves",
6464
"address" : "Street 32",
6565
"city" : "London",
66-
"area" : "Center",
66+
"area" : { "_id": "South", 'parents': "Center"},
6767
"frequency" : 20,
6868
"ability" : 200
6969
},

0 commit comments

Comments
 (0)