-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsample-menus-data.js
More file actions
126 lines (80 loc) · 1.92 KB
/
sample-menus-data.js
File metadata and controls
126 lines (80 loc) · 1.92 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
function getMenus(){
var x = new Date();
x.setDate(1);
// x.setMonth(x.getMonth()-1);
var prev_month = x.getMonth()-1;
var prev_month2 = x.getMonth()-2;
var prev_month3 = x.getMonth()-3;
var menus = [
{
title: "string",
date: prev_month,
description: "string",
// recipes: [],
notes: "This is notes6",
// groceryId: ""
},
{
title: "string1",
date: prev_month2,
description: "string1",
// recipes: [],
notes: "This is notes5",
// groceryId: ""
},
{
title:"string2",
date: prev_month2,
description:"string2",
// recipes: [],
notes: "This is notes4",
// groceryId: ""
},
{
title:"string3",
date: new Date(),
description:"string3",
notes: "This is notes3",
// groceryId: ""
},
{
title:"string4",
date: prev_month3,
description:"string4",
// recipes: [],
notes: "This is notes2",
// groceryId: ""
}
];
return menus;
};
function createMenus(cb){
database.autoupdate('MenuModel', function(err){
if (err) return cb(err);
Menu.create(getMenus(), cb);
});
};
function attachMenusToUsers(users, menus){
// menus.forEach(function(menu){
// menu.updateAttribute('userId', users[2].id);
// });
users.forEach(function(user){
user.updateAttribute('userId', menus);
});
};
function attachRecipesToMenu(recipes, menus){
var arrayWithIds = idsOnly(recipes);
menus.forEach(function(menu){
menu.updateAttribute('recipes', arrayWithIds);
});
};
function idsOnly(array){
var result = Object.keys(array).map(function(e) {
return array[e].id;
});
return result;
};
module.exports.createMenus = createMenus;
module.exports.attachMenusToUsers = attachMenusToUsers;
module.exports.attachRecipesToMenu = attachRecipesToMenu;