-
Notifications
You must be signed in to change notification settings - Fork 0
/
requestLineAPI.js
65 lines (55 loc) · 1.56 KB
/
requestLineAPI.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
var thinky = require('./utils');
var employee = require('./employeeAPI').Employee;
var RequestLine = thinky.createModel('RequestLine',{
requestID: String,
feeding: Boolean,
transportation: Boolean,
approved: Boolean,
transportationConfirmation: Boolean,
feedingId: String,
employeeID: String
});
RequestLine.ensureIndex('requestID');
RequestLine.belongsTo(employee,'employee','employeeID','id');
// RequestLine.hasOne(feeding,'feed','id','reqLineId');
exports.list = function(req, res){
RequestLine.orderBy({index: 'requestID'}).getJoin({request: true, employee: true}).run().then(function(requestLines){
res.json({
data: requestLines,
profile: res.decoded[0],
success: true
});
}).error(function(err){
res.json({message:err});
});
};
exports.add = function(req, res){
RequestLine.save(req.body).then(function(result){
res.json(result);
}).error(function(err){
res.json({message: err});
});
};
exports.get = function(req, res){
RequestLine.get(req.params.id).getJoin({employee: true}).run().then(function(requestLine){
console.log(requestLine);
res.json(requestLine);
}).error(function(err){
res.json({message: err});
});
};
exports.update = function(req, res){
RequestLine.get(req.params.id).update(req.body).run().then(function(result){
res.json(result);
}).error(function(err){
res.json({message: err});
});
};
exports.delete = function(req, res){
RequestLine.get(req.params.id).delete().execute().then(function(result){
res.json(result);
}).error(function(err){
res.json({message: err});
});
};
exports.RequestLine =RequestLine;