Skip to content

Commit f6f21d7

Browse files
committed
improce updatedocument, fix a few issues
1 parent 4bae79e commit f6f21d7

9 files changed

Lines changed: 37 additions & 19 deletions

File tree

OpenFlow/src/DatabaseConnection.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ export class DatabaseConnection {
237237
await this.connect();
238238
var user: TokenUser = Crypt.verityToken(jwt);
239239
if (!this.hasAuthorization(user, item, "update")) { throw new Error("Access denied"); }
240-
var original: T = await this.getbyid<T>(item._id, collectionname, jwt);
241-
if (!original) { throw Error("item not found!"); }
242240

243241
// assume empty query, means full document, else update document
244242
if (query === null || query === undefined) {
245243
// this will add an _acl so needs to be after we checked old item
246244
if (!item.hasOwnProperty("_id")) {
247245
throw Error("Cannot update item without _id");
248246
}
247+
var original: T = await this.getbyid<T>(item._id, collectionname, jwt);
248+
if (!original) { throw Error("item not found!"); }
249249
item._modifiedby = user.name;
250250
item._modifiedbyid = user._id;
251251
item._modified = new Date(new Date().toISOString());
@@ -400,14 +400,10 @@ export class DatabaseConnection {
400400
throw Error("item not found!");
401401
}
402402
if (res.result.ok == 1) {
403-
if (w > 0) {
404-
if (res.modifiedCount == 0) {
405-
throw Error("item not found!");
406-
} else if (res.modifiedCount == 1 || res.modifiedCount == undefined) {
407-
item = item;
408-
} else {
409-
throw Error("More than one item was updated !!!");
410-
}
403+
if (res.modifiedCount == 0) {
404+
throw Error("item not found!");
405+
} else if (res.modifiedCount == 1 || res.modifiedCount == undefined) {
406+
item = item;
411407
}
412408
} else {
413409
throw Error("UpdateOne failed!!!");

OpenFlowNodeRED/src/Message.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class UpdateOneMessage {
147147
public j: boolean;
148148
public item: object;
149149
public collectionname: string;
150+
public query: object;
150151
public result: any;
151152
static assign(o: any): UpdateOneMessage {
152153
if (typeof o === "string" || o instanceof String) {

OpenFlowNodeRED/src/nodered/nodes/NoderedUtil.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ export class NoderedUtil {
7777
var result: QueryMessage = await WebSocketClient.instance.Send<QueryMessage>(_msg);
7878
return result.result;
7979
}
80-
public static async UpdateOne(collection: string, item: any, w: number, j: boolean, jwt: string): Promise<any> {
80+
public static async UpdateOne(collection: string, query: any, item: any, w: number, j: boolean, jwt: string): Promise<any> {
8181
var q: UpdateOneMessage = new UpdateOneMessage(); q.collectionname = collection;
8282
q.item = item; q.jwt = jwt;
83-
q.w = w; q.j = j;
83+
q.w = w; q.j = j; q.query = query;
8484
var _msg: Message = new Message();
8585
_msg.command = "updateone"; _msg.data = JSON.stringify(q);
8686
var result: QueryMessage = await WebSocketClient.instance.Send<QueryMessage>(_msg);

OpenFlowNodeRED/src/nodered/nodes/amqp_nodes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class amqp_connection {
1717
constructor(public config: Iamqp_connection) {
1818
RED.nodes.createNode(this, config);
1919
this.node = this;
20+
this.node.status({});
2021
if (this.node.credentials && this.node.credentials.hasOwnProperty("username")) {
2122
this.username = this.node.credentials.username;
2223
}
@@ -41,6 +42,7 @@ export class amqp_consumer_node {
4142
RED.nodes.createNode(this, config);
4243
try {
4344
this.node = this;
45+
this.node.status({});
4446
this.node.on("close", this.onclose);
4547
var _config: amqp_connection = RED.nodes.getNode(this.config.config);
4648
let username: string = null;
@@ -117,6 +119,7 @@ export class amqp_publisher_node {
117119
RED.nodes.createNode(this, config);
118120
try {
119121
this.node = this;
122+
this.node.status({});
120123
this.node.on("input", this.oninput);
121124
this.node.on("close", this.onclose);
122125

@@ -198,6 +201,7 @@ export class amqp_acknowledgment_node {
198201
constructor(public config: Iamqp_acknowledgment_node) {
199202
RED.nodes.createNode(this, config);
200203
this.node = this;
204+
this.node.status({});
201205
this.node.on("input", this.oninput);
202206
this.node.on("close", this.onclose);
203207
}

OpenFlowNodeRED/src/nodered/nodes/api.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@
10111011
journal: { value: "false", required: true },
10121012
action: { value: "updateOne", required: true },
10131013
query: { value: "", required: true },
1014-
updatedocument: { value: "", required: true },
1014+
updatedocument: { value: "{ \"$inc\": { \"count\": 1}}", required: true },
10151015
collection: { value: "entities", required: true }
10161016
},
10171017
inputs: 1,

OpenFlowNodeRED/src/nodered/nodes/api_nodes.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class api_credentials {
1818
constructor(public config: Iapi_get_jwt) {
1919
RED.nodes.createNode(this, config);
2020
this.node = this;
21+
this.node.status({});
2122
if (this.node.credentials && this.node.credentials.hasOwnProperty("username")) {
2223
this.username = this.node.credentials.username;
2324
}
@@ -35,6 +36,7 @@ export class api_get_jwt {
3536
constructor(public config: Iapi_get_jwt) {
3637
RED.nodes.createNode(this, config);
3738
this.node = this;
39+
this.node.status({});
3840
this.node.on("input", this.oninput);
3941
this.node.on("close", this.onclose);
4042
}
@@ -92,6 +94,7 @@ export class api_get {
9294
constructor(public config: Iapi_get) {
9395
RED.nodes.createNode(this, config);
9496
this.node = this;
97+
this.node.status({});
9598
this.node.on("input", this.oninput);
9699
this.node.on("close", this.onclose);
97100
}
@@ -152,6 +155,7 @@ export class api_add {
152155
constructor(public config: Iapi_add) {
153156
RED.nodes.createNode(this, config);
154157
this.node = this;
158+
this.node.status({});
155159
this.node.on("input", this.oninput);
156160
this.node.on("close", this.onclose);
157161
}
@@ -223,6 +227,7 @@ export class api_update {
223227
constructor(public config: Iapi_update) {
224228
RED.nodes.createNode(this, config);
225229
this.node = this;
230+
this.node.status({});
226231
this.node.on("input", this.oninput);
227232
this.node.on("close", this.onclose);
228233
}
@@ -255,7 +260,7 @@ export class api_update {
255260
if (!NoderedUtil.IsNullEmpty(this.config.entitytype)) {
256261
element._type = this.config.entitytype;
257262
}
258-
Promises.push(NoderedUtil.UpdateOne(this.config.collection, element, this.config.writeconcern, this.config.journal, msg.jwt));
263+
Promises.push(NoderedUtil.UpdateOne(this.config.collection, null, element, this.config.writeconcern, this.config.journal, msg.jwt));
259264
}
260265
data = await Promise.all(Promises.map(p => p.catch(e => e)));
261266

@@ -294,6 +299,7 @@ export class api_addorupdate {
294299
constructor(public config: Iapi_addorupdate) {
295300
RED.nodes.createNode(this, config);
296301
this.node = this;
302+
this.node.status({});
297303
this.node.on("input", this.oninput);
298304
this.node.on("close", this.onclose);
299305
}
@@ -364,6 +370,7 @@ export class api_delete {
364370
constructor(public config: Iapi_delete) {
365371
RED.nodes.createNode(this, config);
366372
this.node = this;
373+
this.node.status({});
367374
this.node.on("input", this.oninput);
368375
this.node.on("close", this.onclose);
369376
}
@@ -428,6 +435,7 @@ export class api_map_reduce {
428435
constructor(public config: Iapi_map_reduce) {
429436
RED.nodes.createNode(this, config);
430437
this.node = this;
438+
this.node.status({});
431439
this.node.on("input", this.oninput);
432440
this.node.on("close", this.onclose);
433441
}
@@ -491,6 +499,7 @@ export class api_updatedocument {
491499
constructor(public config: Iapi_updatedocument) {
492500
RED.nodes.createNode(this, config);
493501
this.node = this;
502+
this.node.status({});
494503
this.node.on("input", this.oninput);
495504
this.node.on("close", this.onclose);
496505
}
@@ -518,8 +527,13 @@ export class api_updatedocument {
518527
}
519528

520529
this.node.status({ fill: "blue", shape: "dot", text: "Running Update Document" });
521-
var result = await NoderedUtil.UpdateMany(this.config.collection, this.config.query, this.config.updatedocument, this.config.writeconcern, this.config.journal, msg.jwt);
522-
msg.payload = result;
530+
if (this.config.action === "updateOne") {
531+
var result = await NoderedUtil.UpdateOne(this.config.collection, this.config.query, this.config.updatedocument, this.config.writeconcern, this.config.journal, msg.jwt);
532+
msg.payload = result;
533+
} else {
534+
var result = await NoderedUtil.UpdateMany(this.config.collection, this.config.query, this.config.updatedocument, this.config.writeconcern, this.config.journal, msg.jwt);
535+
msg.payload = result;
536+
}
523537
this.node.send(msg);
524538
this.node.status({});
525539
} catch (error) {

OpenFlowNodeRED/src/nodered/nodes/rpa_nodes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class rpa_detector_node {
1919
RED.nodes.createNode(this, config);
2020
try {
2121
this.node = this;
22+
this.node.status({});
2223
this.node.on("close", this.onclose);
2324
this.host = Config.amqp_url;
2425
this.connect();
@@ -77,6 +78,7 @@ export class rpa_workflow_node {
7778
RED.nodes.createNode(this, config);
7879
try {
7980
this.node = this;
81+
this.node.status({});
8082
this.node.on("input", this.oninput);
8183
this.node.on("close", this.onclose);
8284
this.host = Config.amqp_url;

OpenFlowNodeRED/src/nodered/nodes/workflow_nodes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class workflow_in_node {
7777
result = this.nestedassign(res[0], result);
7878
// result.payload = Object.assign(res[0].payload, result.payload);
7979
// result = Object.assign(res[0], result);
80-
await NoderedUtil.UpdateOne("workflow_instances", result, 0, false, data.jwt);
80+
await NoderedUtil.UpdateOne("workflow_instances", null, result, 0, false, data.jwt);
8181
} else {
8282
var res2 = this.workflow = await NoderedUtil.InsertOne("workflow_instances",
8383
{ _type: "instance", "queue": this.config.queue, "name": this.config.name, payload: data.payload }, 0, false, data.jwt);
@@ -111,6 +111,7 @@ export class workflow_out_node {
111111
constructor(public config: Iworkflow_out_node) {
112112
RED.nodes.createNode(this, config);
113113
this.node = this;
114+
this.node.status({});
114115
this.node.on("input", this.oninput);
115116
this.node.on("close", this.onclose);
116117

@@ -121,7 +122,7 @@ export class workflow_out_node {
121122
if (msg.amqpacknowledgment) {
122123
msg.state = this.config.state;
123124
if (msg._id !== null && msg._id !== undefined && msg._id !== "") {
124-
var res = await NoderedUtil.UpdateOne("workflow_instances", msg, 0, false, msg.jwt);
125+
var res = await NoderedUtil.UpdateOne("workflow_instances", null, msg, 0, false, msg.jwt);
125126
}
126127
var data: any = {};
127128
data.payload = msg.payload;

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.114
1+
0.0.115

0 commit comments

Comments
 (0)