@openinc/parse-server-opendash 2.4.73 → 2.4.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -88,7 +88,7 @@ async function init() {
88
88
  }
89
89
  object.set("tag", source.tag);
90
90
  }
91
- if (!object.articlenr) {
91
+ if (!object.get("articlenr")) {
92
92
  const article = await object
93
93
  .get("article")
94
94
  ?.fetch({ useMasterKey: true });
@@ -100,31 +100,31 @@ async function init() {
100
100
  : article?.get("targettime") || 0);
101
101
  }
102
102
  }
103
- if (object.status === "canceled") {
103
+ if (object.get("status") === "canceled") {
104
104
  }
105
105
  // If the order is started and has a source, it is running
106
- if (object.start &&
107
- object.start.getTime() < nowThresholded &&
108
- object.source &&
109
- !object.status) {
106
+ if (object.get("start") &&
107
+ object.get("start").getTime() < nowThresholded &&
108
+ object.get("source") &&
109
+ !object.get("status")) {
110
110
  object.set("status", "running");
111
111
  }
112
- if (object.start &&
113
- object.start.getTime() > Date.now() &&
114
- object.source &&
115
- !object.status) {
112
+ if (object.get("start") &&
113
+ object.get("start").getTime() > Date.now() &&
114
+ object.get("source") &&
115
+ !object.get("status")) {
116
116
  object.set("status", "planned");
117
117
  }
118
118
  // If the order is started and has no source, it is unknown
119
- if (object.start &&
120
- object.start.getTime() < nowThresholded &&
121
- !object.source) {
119
+ if (object.get("start") &&
120
+ object.get("start").getTime() < nowThresholded &&
121
+ !object.get("source")) {
122
122
  object.set("status", "unknown");
123
123
  }
124
124
  // If the order has been started and ended, it is done
125
- if (object.start &&
126
- object.duration &&
127
- (object.status === "running" || object.status === "planned")) {
125
+ if (object.get("start") &&
126
+ object.get("duration") &&
127
+ (object.get("status") === "running" || object.get("status") === "planned")) {
128
128
  object.set("status", "done");
129
129
  }
130
130
  });
@@ -133,13 +133,14 @@ async function init() {
133
133
  try {
134
134
  if (original) {
135
135
  // If the order is canceled, publish it as canceled
136
- if (object.status === "canceled" && original.status !== "canceled") {
136
+ if (object.get("status") === "canceled" &&
137
+ original.get("status") !== "canceled") {
137
138
  const data = await object2OWItem(object);
138
139
  await (0, ow_1.publishDataItem)(data, user?.getEmail(), true);
139
140
  return;
140
141
  }
141
142
  // If the order is rescheduled, publish it as rescheduled
142
- if ((original?.start?.getTime() || 0) !==
143
+ if ((original?.get("start")?.getTime() || 0) !==
143
144
  (object.get("start")?.getTime() || 0)) {
144
145
  console.log("-".repeat(20));
145
146
  console.log("Publishing rescheduled order");
@@ -150,14 +151,14 @@ async function init() {
150
151
  return;
151
152
  }
152
153
  }
153
- if (object.status === "canceled") {
154
+ if (object.get("status") === "canceled") {
154
155
  // If order was canceled before, do not publish it
155
156
  return;
156
157
  }
157
158
  const data = await object2OWItem(object);
158
159
  await (0, ow_1.publishDataItem)(data, user?.getEmail(), true);
159
160
  // Publish all running orders separately to make use of these as reference values
160
- if (object.status === "running") {
161
+ if (object.get("status") === "running") {
161
162
  const runningData = { ...data };
162
163
  runningData.id = "ow_mes_order_running";
163
164
  runningData.name = "Order_Running";
@@ -289,11 +290,13 @@ async function createValueArrayForObject(object, extraValues, fields) {
289
290
  function scheduleOrderStartedStatusCheck(cronInterval) {
290
291
  const job = new cron_1.CronJob(cronInterval, // cronTime
291
292
  () => {
292
- console.log("Checking Order Status");
293
+ const date = new Date(Date.now() - 24 * 60 * 60 * 1000);
294
+ console.log(`Checking Order Status for Orders started in the last 24 hours (Since ${date.toISOString()})`);
293
295
  //Orders of last 24 hours
294
- const query = new Parse.Query("MES_Order");
295
- query.greaterThanOrEqualTo("start", new Date(Date.now() - 24 * 60 * 60 * 1000));
296
+ const query = new Parse.Query(types_1.MES_Order);
297
+ query.greaterThanOrEqualTo("start", date);
296
298
  query.find({ useMasterKey: true }).then((orders) => {
299
+ console.log(`Checking ${orders.length} Orders`);
297
300
  orders.forEach((order) => {
298
301
  const status = order.get("status");
299
302
  if (!status) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "2.4.73",
3
+ "version": "2.4.75",
4
4
  "description": "Parse Server Cloud Code for open.DASH",
5
5
  "keywords": [
6
6
  "parse",