-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy path20191217154900-projectPhase2018Update.js
110 lines (95 loc) · 2.71 KB
/
20191217154900-projectPhase2018Update.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
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
'use strict';
var dbm;
var type;
var seed;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
};
let newItem = {
"type" : "projectPhase",
"_schemaName" : "List",
"name" : "Project Designation",
"legislation" : 2018,
"read" : [
"public",
"staff",
"sysadmin"
],
"write" : [
"staff",
"sysadmin"
],
"listOrder" : 0
};
let docList_order_2018 = [1,2,3,4,5,6,14,7,8,9,10,11,16,12,13,15,17,0];
let docList_order_2002 = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
exports.up = function(db) {
let mClient;
return db.connection.connect(db.connectionString, { native_parser: true })
.then((mClientInst) => {
// mClientInst is an instance of MongoClient
mClient = mClientInst;
var p = mClient.collection('epic');
p.updateOne({"_schemaName":"List", "legislation": 2018, "name": "EA Readiness Decision"}, {$set: {"name": "Readiness Decision"}});
p.updateOne({"_schemaName":"List", "legislation": 2018, "name": "Application Development & Review"}, {$set: {"name": "Application Development and Review"}});
p.updateOne({"_schemaName":"List", "legislation": 2018, "name": "Post Decision"}, {$set: {"name": "Post Decision - Extension"}});
p.insertOne(newItem);
p.aggregate([
{ $match: {_schemaName:"List", type: "projectPhase", legislation: 2018} }
])
.toArray()
.then((arr) => {
let i = 0;
for (let item of arr) {
p.update(
{ _id: item._id },
{
$set: { listOrder: docList_order_2018[i] }
}
)
i++;
}
}
).catch((e) => {
console.log("error: ", e);
mClient.close()
});
p.aggregate([
{ $match: {_schemaName:"List", type: "projectPhase", legislation: 2002} }
])
.toArray()
.then((arr) => {
let i = 0;
for (let item of arr) {
p.update(
{ _id: item._id },
{
$set: { listOrder: docList_order_2002[i] }
}
)
i++;
}
mClient.close();
}
).catch((e) => {
console.log("error: ", e);
mClient.close()
});
})
.catch((e) => {
console.log("e:", e);
mClient.close()
});
};
exports.down = function(db) {
return null;
};
exports._meta = {
"version": 1
};