-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
106 lines (82 loc) · 2.34 KB
/
Copy pathindex.js
File metadata and controls
106 lines (82 loc) · 2.34 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var ApiBuilder = require('claudia-api-builder'),
Promise = require('bluebird'),
AWS = require('aws-sdk'),
shortid = require('shortid');
api = new ApiBuilder(),
docClient = Promise.promisifyAll(new AWS.DynamoDB.DocumentClient());
module.exports = api;
require('./professional-service.js')
require('./agenda.js')
// Create new user
api.post('/user', function (request) {
'use strict';
var params = {
TableName: "usuario",
Item: {
Id: request.body.id > 0 ? request.body.id : shortid.generate(),
name: request.body.name,
password: request.body.password,
email: request.body.email,
celular: request.body.celular
}
};
// Store it and return the promise,
// that will evaluate before reponding back to the client
return docClient.putAsync(params);
}, { success: 201 }); // Return HTTP status 201 - Created when successful
// Create new user
api.post('/user/login', function (request) {
'use strict';
var email, senha, params;
// Get the id from the pathParams
email = request.body.email;
senha = request.body.senha;
// Set up parameters for dynamo
params = {
TableName: 'usuario',
FilterExpression: 'email = :email and password = :senha',
ExpressionAttributeValues: {
':email': email,
':senha': senha
}
};
// Store it and return the promise,
// that will evaluate before reponding back to the client
return docClient.scanAsync(params);
}, { success: 201 }); // Return HTTP status 201 - Created when successful
// get user for {id}
api.get('/user/{id}', function (request) {
'use strict';
var id, params;
// // Get the id from the pathParams
id = request.pathParams.id;
// Set up parameters for dynamo
params = {
TableName: 'usuario',
Key: {
Id: id
}
};
// Get the item using our promisified function
return docClient.getAsync(params);
}); //200 ok is standard for non-errors
// delete user with {id}
api.delete('/user/{id}', function (request) {
'use strict';
var id, params;
// Get the id from the pathParams
id = request.pathParams.id;
// Set up parameters for dynamo
params = {
TableName: 'usuario',
Key: {
Id: id
}
};
// Get the item using our promisified function
// return a nice little message in the .then-clause
return docClient.deleteAsync(params)
.then(function () {
return 'Deleted user with id "' + id + '"';
});
}); //200 ok is standard for non-errors