-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprofessional-service.js
More file actions
100 lines (79 loc) · 2.47 KB
/
Copy pathprofessional-service.js
File metadata and controls
100 lines (79 loc) · 2.47 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
var AWS = require('aws-sdk'),
Promise = require('bluebird'),
shortid = require('shortid'),
docClient = Promise.promisifyAll(new AWS.DynamoDB.DocumentClient());
// Create new profissional
api.post('/profissional', function (request) {
'use strict';
// Map to the item to store from the posted data
// (psst should an application/x-form-www-urlencoded be used
// we could have read it below with request.post.userId etc.)
var params = {
TableName: "profissional",
Item: {
Id: shortid.generate(),
NomeProfissional: request.body.nomeProfissional,
Cidade: request.body.cidade,
Estado: request.body.estado,
Endereco: request.body.endereco,
Bairro: request.body.bairro,
Telefone: request.body.telefone,
Celular: request.body.celular,
CelularSecundario: request.body.celularSecundario,
IdUsuario: request.body.idUsuario
}
};
// 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
// scan profis
api.get('/profissional', function (request) {
'use strict';
var params;
// Set up parameters for dynamo
params = {
TableName: 'profissional',
FilterExpression: 'Ativo = :ativo',
ExpressionAttributeValues: {
':ativo': true
}
};
// Get the item using our promisified function
return docClient.scanAsync(params);
}); //200 ok is standard for non-errors
// get profi for {id}
api.get('/profissional/{id}', function (request) {
'use strict';
var idUsuario, params;
// Get the id from the pathParams
idUsuario = request.pathParams.id;
// Set up parameters for dynamo
params = {
TableName: 'profissional',
FilterExpression: 'IdUsuario = :id',
ExpressionAttributeValues: {
':id': idUsuario
}
//Key: { IdProfissional : id, DataAgendamento : data }
};
// Get the item using our promisified function
return docClient.scanAsync(params);
}); //200 ok is standard for non-errors
// get user for {id}
api.get('/profissional/{id}/services', function (request) {
'use strict';
var id, params;
// Get the id from the pathParams
id = request.pathParams.id;
// Set up parameters for dynamo
params = {
TableName: 'profissional_servico',
FilterExpression: 'IdUsuario = :id',
ExpressionAttributeValues: {
':id': id
}
};
// Get the item using our promisified function
return docClient.scanAsync(params);
}); //200 ok is standard for non-errors