-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontroller.js
90 lines (59 loc) · 1.4 KB
/
controller.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
var Model = require('./models')
var methods = require(__dirname + '/convenience')
var Sequelize = require('sequelize-values')();
var _ = require('lodash');
exports.getDynamic = function(req, res) {
var baselineTable = req.body.base
var joinTable = req.body.join
// console.log(req.body)
if (!joinTable) {
Model[baselineTable].findAll()
.then(function (data) {
res.json(data)
})
} else {
Model[baselineTable].findAll({
include: [{
model: Model[joinTable],
required: true
}]
}).then(function (data) {
res.json(data)
})
}
}
// var postAssociations = [
// {
// model: products
// },
// {
// model: orders,
// include: [{
// model: order_details
// }]
// }
// ]
exports.extSales = function (req, res) {
// var postAssociations = [{
// model: Model.orders,
// include: [{
// model: Model.order_details
// }]
// }]
var attributes = ['ProductName']
var subattributes = ['OrderDate', 'CustomerID', 'EmployeeID', 'ShipCountry', 'ShipName']
Model.products.findAll({
attributes: attributes,
include: [{
model: Model.orders,
required: true,
attributes: subattributes,
where: { OrderDate: {$between: [new Date('1996-01-01'), new Date('1996-12-31')]}}
}]
}).then(function(product) {
var data = Sequelize.getValuesDedup(product)
return methods.mergeObjects(data)
}).then(function(result) {
res.send(result)
})
}