-
Notifications
You must be signed in to change notification settings - Fork 0
/
ven.txt
91 lines (72 loc) · 2.3 KB
/
ven.txt
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
activity.findOne({ partyId: "1" }, function (err, res) {
if (res) {
var array = res.activities;
console.log(JSON.stringify(res))
for (let indexJ = 0; indexJ < objectData.cases.length; indexJ++) {
var requestObject = objectData.cases[indexJ].serviceRequests;
for (let indexK = 0; indexK < requestObject.length; indexK++) {
var activityArray = requestObject[indexK].activities;
for(let indexL=0;indexL<activityArray.length ; indexL++){
var element = activityArray[indexL];
var newActivityObject = {
id : element.id,
traceId : '1',
clientId : '1'
}
array.push(newActivityObject);
}
}
}
activity.findOneAndUpdate({ partyId: "1" }, res, { new: true }, function (err, result) {
console.log("Updated Final");
});
} else {
var newObject = {};
newObject.partyId = "1";
newObject.activities = [];
for (let indexJ = 0; indexJ < objectData.cases.length; indexJ++) {
var requestObject = objectData.cases[indexJ].serviceRequests;
for (let indexK = 0; indexK < requestObject.length; indexK++) {
var activityArray = requestObject[indexK].activities;
for(let indexL=0;indexL<activityArray.length ; indexL++){
var element = activityArray[indexL];
var newActivityObject = {
id : element.id,
traceId : '1',
clientId : '1'
}
newObject.activities.push(newActivityObject);
}
}
}
activity.findOneAndUpdate({ partyId: "1" }, newObject, { new: true, upsert: true }, function (err, doc, res) {
if (doc) {
console.log("inserted into DB")
}
});
}
});
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const ActivitySchema = new Schema({
partyId: {
type: String,
},
id: {
type: String
},
activities: [
{
id: {
type: String
},
traceId: {
type: String,
},
clientId: {
type: String,
}
}
]
})
const Activity = mongoose.model('Activity', ActivitySchema);