Commit 774e1bf20c952aa0b77d790e53ad1230d447d53b
1 parent
96e4677f6e
Exists in
master
push supplier name to mongodb
Showing 1 changed file with 13 additions and 12 deletions Side-by-side Diff
partner-cjk.js
... | ... | @@ -97,7 +97,15 @@ function insertTaskToMongoDb(task) { |
97 | 97 | if (!isMongoReady()) { return; } |
98 | 98 | |
99 | 99 | try { |
100 | - mongodb.collection(config.mongodb.collection).insertOne(task); | |
100 | + mongodb.collection(config.mongodb.collection).insertOne(task, function(err, result) { | |
101 | + mongodb.collection(config.mongodb.collection).updateOne( | |
102 | + {requestId: task.requestId}, | |
103 | + { | |
104 | + $push: {suppliers: config.globals.gateway_name} | |
105 | + } | |
106 | + | |
107 | + ) | |
108 | + }); | |
101 | 109 | } |
102 | 110 | catch(err) { |
103 | 111 | //logger.warn('Exception when inserting document to mongodb', {err: err, task: task}); |
... | ... | @@ -108,23 +116,16 @@ function pushResponseToMongoDb(task, response) { |
108 | 116 | if (!isMongoReady()) { return; } |
109 | 117 | |
110 | 118 | try { |
111 | - var rc = null; | |
112 | - var message = null; | |
113 | - var refnum = null; | |
119 | + var lastResponse = {}; | |
114 | 120 | |
115 | - if (response.parsed) { | |
116 | - if (response.parsed.rc) { rc = response.parsed.rc; }; | |
117 | - if (response.parsed.message) { message = response.parsed.message; }; | |
118 | - if (response.parsed.refnum) { refnum = response.parsed.refnum; }; | |
121 | + if (response.parsed && response.parsed.ciwaru) { | |
122 | + lastResponse = response.parsed.ciwaru; | |
119 | 123 | } |
120 | 124 | |
121 | 125 | mongodb.collection(config.mongodb.collection).updateOne( |
122 | 126 | {requestId: task.requestId}, |
123 | 127 | { |
124 | - rc: rc, | |
125 | - message: message, | |
126 | - refnum: refnum, | |
127 | - | |
128 | + lastResponse: lastResponse, | |
128 | 129 | $push: {responses: response} |
129 | 130 | }, |
130 | 131 | function(err, result) { |