@formio/appserver 2.0.0-rc.8 → 2.0.0

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.
@@ -8,6 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
11
22
  Object.defineProperty(exports, "__esModule", { value: true });
12
23
  exports.Database = void 0;
13
24
  const mongodb_1 = require("mongodb");
@@ -19,6 +30,7 @@ class Database {
19
30
  constructor(config) {
20
31
  this.config = config;
21
32
  this.prefix = '';
33
+ this.authQuery = null;
22
34
  this.db = null;
23
35
  this.client = null; // Add this line
24
36
  this.currentCollectionName = 'submissions';
@@ -41,7 +53,6 @@ class Database {
41
53
  }
42
54
  /**
43
55
  * Connect to the database.
44
- * @param {*} scope
45
56
  * @returns
46
57
  */
47
58
  connect() {
@@ -135,7 +146,7 @@ class Database {
135
146
  }
136
147
  // Generic load record method.
137
148
  load(collectionName_1) {
138
- return __awaiter(this, arguments, void 0, function* (collectionName, query = {}) {
149
+ return __awaiter(this, arguments, void 0, function* (collectionName, dbQuery = {}) {
139
150
  if (!this.db) {
140
151
  return null;
141
152
  }
@@ -146,7 +157,7 @@ class Database {
146
157
  }
147
158
  let item;
148
159
  try {
149
- item = yield collection.findOne(query);
160
+ item = yield collection.findOne(dbQuery);
150
161
  }
151
162
  catch (err) {
152
163
  error(err.message);
@@ -154,9 +165,118 @@ class Database {
154
165
  return item;
155
166
  });
156
167
  }
168
+ // Provides a suplemental query for authentication purposes.
169
+ indexAuth(query) {
170
+ this.authQuery = query || null;
171
+ }
172
+ getQueryValue(name, value, selector) {
173
+ if (name === 'created' || name === 'modified') {
174
+ return new Date(value);
175
+ }
176
+ if ((typeof value === 'string') && (!selector || (selector === 'eq' || selector === 'ne'))) {
177
+ const lcValue = value.toLowerCase();
178
+ if (lcValue === 'null') {
179
+ return null;
180
+ }
181
+ if (lcValue === '"null"') {
182
+ return 'null';
183
+ }
184
+ if (lcValue === 'true') {
185
+ return true;
186
+ }
187
+ if (lcValue === '"true"') {
188
+ return 'true';
189
+ }
190
+ if (lcValue === 'false') {
191
+ return false;
192
+ }
193
+ if (lcValue === '"false"') {
194
+ return 'false';
195
+ }
196
+ }
197
+ return value;
198
+ }
199
+ /**
200
+ * Converts the url query to query parameters.
201
+ * @param query
202
+ * @returns
203
+ */
204
+ dbQuery(query = {}) {
205
+ const dbQuery = {};
206
+ const { limit, skip, sort } = query, filters = __rest(query, ["limit", "skip", "sort"]);
207
+ if (limit !== undefined) {
208
+ dbQuery.limit = limit ? Number(limit) : 10;
209
+ }
210
+ if (skip !== undefined) {
211
+ dbQuery.skip = skip ? Number(skip) : 0;
212
+ }
213
+ if (sort) {
214
+ dbQuery.sort = {};
215
+ const sortParts = sort.split(',');
216
+ sortParts.forEach((part) => {
217
+ const desc = part.charAt(0) === '-';
218
+ const field = desc ? part.substring(1) : part;
219
+ dbQuery.sort[field] = desc ? -1 : 1;
220
+ });
221
+ }
222
+ // Iterate through each filter.
223
+ Object.entries(filters).forEach(([name, value]) => {
224
+ // Get the filter object.
225
+ const filter = (0, lodash_1.zipObject)(['name', 'selector'], name.split('__'));
226
+ if (filter.selector) {
227
+ var filterQuery = dbQuery[filter.name];
228
+ // Init the filter.
229
+ if (!filterQuery) {
230
+ filterQuery = {};
231
+ }
232
+ if (filter.selector === 'exists') {
233
+ value = ((value === 'true') || (value === '1')) ? true : value;
234
+ value = ((value === 'false') || (value === '0')) ? false : value;
235
+ value = !!value;
236
+ }
237
+ else if (filter.selector === 'regex') {
238
+ const parts = value.match(/\/?([^/]+)\/?([^/]+)?/);
239
+ if (!parts) {
240
+ return;
241
+ }
242
+ try {
243
+ value = new RegExp((0, lodash_1.escapeRegExp)(parts[1]), (parts[2] || 'i'));
244
+ }
245
+ catch (err) {
246
+ error(err);
247
+ value = null;
248
+ }
249
+ }
250
+ // Special case for in filter with multiple values.
251
+ else if (['in', 'nin'].includes(filter.selector)) {
252
+ value = Array.isArray(value) ? value : value.split(',');
253
+ value = value.map((item) => this.getQueryValue(filter.name, item, filter.selector));
254
+ }
255
+ else {
256
+ // Set the selector for this filter name.
257
+ value = this.getQueryValue(filter.name, value, filter.selector);
258
+ }
259
+ filterQuery[`$${filter.selector}`] = value;
260
+ dbQuery[filter.name] = filterQuery;
261
+ return;
262
+ }
263
+ else {
264
+ // Set the find query to this value.
265
+ value = this.getQueryValue(filter.name, value, filter.selector);
266
+ dbQuery[filter.name] = value;
267
+ return;
268
+ }
269
+ });
270
+ // If an authQuery is provided, merge it in.
271
+ if (this.authQuery && (0, lodash_1.isPlainObject)(this.authQuery)) {
272
+ return (0, lodash_1.merge)(dbQuery, this.authQuery);
273
+ }
274
+ // Return the dbQuery.
275
+ return dbQuery;
276
+ }
157
277
  // Generic delete record method.
158
278
  remove(collectionName_1) {
159
- return __awaiter(this, arguments, void 0, function* (collectionName, query = {}) {
279
+ return __awaiter(this, arguments, void 0, function* (collectionName, dbQuery = {}) {
160
280
  if (!this.db) {
161
281
  return null;
162
282
  }
@@ -167,7 +287,7 @@ class Database {
167
287
  }
168
288
  let result;
169
289
  try {
170
- result = yield collection.deleteOne(query);
290
+ result = yield collection.deleteOne(dbQuery);
171
291
  }
172
292
  catch (err) {
173
293
  error(err.message);
@@ -177,27 +297,26 @@ class Database {
177
297
  }
178
298
  /**
179
299
  * Ensures the form collection is created an returns it.
180
- * @param scope
181
300
  * @returns
182
301
  */
183
- formCollection(scope) {
302
+ formCollection(form) {
184
303
  return __awaiter(this, void 0, void 0, function* () {
185
- if (this.db && scope && scope.form && scope.form.settings && scope.form.settings.collection) {
186
- if (this.currentCollection && this.currentCollectionName === scope.form.settings.collection) {
304
+ if (this.db && form && form.settings && form.settings.collection) {
305
+ if (this.currentCollection && this.currentCollectionName === form.settings.collection) {
187
306
  return this.currentCollection;
188
307
  }
189
308
  let collection = null;
190
309
  try {
191
- debug('db.createCollection()', scope.form.settings.collection);
192
- yield this.db.createCollection(this.collectionName(scope.form.settings.collection));
193
- collection = this.collection(scope.form.settings.collection);
194
- this.setupIndexes(collection, scope);
310
+ debug('db.createCollection()', form.settings.collection);
311
+ yield this.db.createCollection(this.collectionName(form.settings.collection));
312
+ collection = this.collection(form.settings.collection);
313
+ this.setupIndexes(collection, form);
195
314
  }
196
315
  catch (err) {
197
316
  error(err.message);
198
317
  }
199
- this.currentCollection = collection || this.collection(scope.form.settings.collection);
200
- this.currentCollectionName = scope.form.settings.collection;
318
+ this.currentCollection = collection || this.collection(form.settings.collection);
319
+ this.currentCollectionName = form.settings.collection;
201
320
  return this.currentCollection;
202
321
  }
203
322
  return this.defaultCollection;
@@ -206,7 +325,7 @@ class Database {
206
325
  /**
207
326
  * Setup indexes.
208
327
  */
209
- setupIndexes(collection, scope) {
328
+ setupIndexes(collection, form) {
210
329
  return __awaiter(this, void 0, void 0, function* () {
211
330
  if (!collection) {
212
331
  return;
@@ -232,8 +351,8 @@ class Database {
232
351
  else {
233
352
  this.addIndex(collection, 'created');
234
353
  }
235
- if (scope && scope.form && scope.form.components) {
236
- scope.utils.eachComponent(scope.form.components, (component, path) => {
354
+ if (form && form.components) {
355
+ core_1.Utils.eachComponent(form.components, (component, path) => {
237
356
  if (component.dbIndex) {
238
357
  this.addIndex(collection, `data.${path}`);
239
358
  }
@@ -262,13 +381,12 @@ class Database {
262
381
  }
263
382
  /**
264
383
  * Adds new indexes to the forms submission collection.
265
- * @param scope
266
384
  * @param indexes
267
385
  * @returns
268
386
  */
269
- addIndexes(scope, indexes) {
387
+ addIndexes(form, indexes) {
270
388
  return __awaiter(this, void 0, void 0, function* () {
271
- const collection = yield this.formCollection(scope);
389
+ const collection = yield this.formCollection(form);
272
390
  if (!collection) {
273
391
  return;
274
392
  }
@@ -295,13 +413,12 @@ class Database {
295
413
  }
296
414
  /**
297
415
  * Removes indexes to the forms submission collection.
298
- * @param scope
299
416
  * @param indexes
300
417
  * @returns
301
418
  */
302
- removeIndexes(scope, indexes) {
419
+ removeIndexes(form, indexes) {
303
420
  return __awaiter(this, void 0, void 0, function* () {
304
- const collection = yield this.formCollection(scope);
421
+ const collection = yield this.formCollection(form);
305
422
  if (!collection) {
306
423
  return;
307
424
  }
@@ -315,59 +432,60 @@ class Database {
315
432
  * @param {*} table
316
433
  * @param {*} query
317
434
  */
318
- index(scope_1) {
319
- return __awaiter(this, arguments, void 0, function* (scope, query = {}, collection = null) {
435
+ index(form_1) {
436
+ return __awaiter(this, arguments, void 0, function* (form, urlQuery = {}, collection = null) {
320
437
  let items = [], skip = 0, limit = 10, count = 0;
321
438
  try {
322
- limit = query.limit || 10;
323
- skip = query.skip || 0;
324
- const sort = query.sort || { created: -1 };
325
- const includeDeleted = query.includeDeleted || false;
439
+ limit = urlQuery.limit || 10;
440
+ skip = urlQuery.skip || 0;
441
+ const sort = urlQuery.sort || { created: -1 };
442
+ const includeDeleted = urlQuery.includeDeleted || false;
326
443
  let project = {};
327
- if (query.select) {
328
- if (typeof query.select === 'string') {
329
- const fields = query.select.split(',');
444
+ if (urlQuery.select) {
445
+ if (typeof urlQuery.select === 'string') {
446
+ const fields = urlQuery.select.split(',');
330
447
  fields.forEach((field) => {
331
448
  project[field] = true;
332
449
  });
333
450
  }
334
451
  else {
335
- Object.keys(query.select).forEach((field) => {
452
+ Object.keys(urlQuery.select).forEach((field) => {
336
453
  project[field] = true;
337
454
  });
338
455
  }
339
456
  }
340
- delete query.limit;
341
- delete query.skip;
342
- delete query.sort;
343
- delete query.select;
344
- delete query.includeDeleted;
345
- debug('db.index()', query);
346
- items = (yield this.find(scope, query, limit, skip, sort, project, collection, includeDeleted)) || [];
347
- count = yield this.count(scope, query, collection, includeDeleted);
457
+ delete urlQuery.limit;
458
+ delete urlQuery.skip;
459
+ delete urlQuery.sort;
460
+ delete urlQuery.select;
461
+ delete urlQuery.includeDeleted;
462
+ debug('db.index()', urlQuery);
463
+ const dbQuery = this.dbQuery(urlQuery);
464
+ items = (yield this.find(form, dbQuery, limit, skip, sort, project, collection, includeDeleted)) || [];
465
+ count = yield this.count(form, dbQuery, collection, includeDeleted);
348
466
  }
349
467
  catch (err) {
350
468
  error(err.message);
351
469
  }
352
- return { items, limit, skip, count };
470
+ return { items: items, limit, skip, count };
353
471
  });
354
472
  }
355
473
  /**
356
474
  * Perform a count of the amount of documents within a collection.
357
- * @param scope
475
+ * @param form
358
476
  * @param query
359
477
  * @returns
360
478
  */
361
- count(scope_1) {
362
- return __awaiter(this, arguments, void 0, function* (scope, query = {}, inCollection = null, includeDeleted = false) {
479
+ count(form_1) {
480
+ return __awaiter(this, arguments, void 0, function* (form, dbQuery = {}, inCollection = null, includeDeleted = false) {
363
481
  let count = 0;
364
482
  try {
365
- debug('db.count()', query);
366
- const collection = inCollection || (yield this.formCollection(scope));
483
+ debug('db.count()', dbQuery);
484
+ const collection = inCollection || (yield this.formCollection(form));
367
485
  if (!collection) {
368
486
  return 0;
369
487
  }
370
- count = yield collection.countDocuments(this.query(scope, query, includeDeleted));
488
+ count = yield collection.countDocuments(this.query(form, dbQuery, includeDeleted));
371
489
  }
372
490
  catch (err) {
373
491
  error(err.message);
@@ -378,21 +496,21 @@ class Database {
378
496
  /**
379
497
  * Create a new record.
380
498
  */
381
- create(scope_1, record_1) {
382
- return __awaiter(this, arguments, void 0, function* (scope, record, allowFields = []) {
499
+ create(form_1, record_1) {
500
+ return __awaiter(this, arguments, void 0, function* (form, record, allowFields = []) {
383
501
  record.deleted = null;
384
502
  record.created = new Date();
385
503
  record.modified = new Date();
386
- if (scope.form && scope.form._id) {
387
- record.form = this.ObjectId(scope.form._id);
504
+ if (form && form._id) {
505
+ record.form = this.ObjectId(form._id);
388
506
  }
389
- if (scope.project && scope.project._id) {
390
- record.project = this.ObjectId(scope.project._id);
507
+ if (form.project && form.project) {
508
+ record.project = this.ObjectId(form.project);
391
509
  }
392
510
  if (record.owner) {
393
511
  record.owner = this.ObjectId(record.owner);
394
512
  }
395
- const collection = yield this.formCollection(scope);
513
+ const collection = yield this.formCollection(form);
396
514
  try {
397
515
  debug('db.create()', record);
398
516
  const result = yield collection.insertOne((0, lodash_1.pick)(record, [
@@ -410,10 +528,11 @@ class Database {
410
528
  if (!result.insertedId) {
411
529
  return null;
412
530
  }
413
- return yield this.read(scope, result.insertedId);
531
+ return yield this.read(form, result.insertedId);
414
532
  }
415
533
  catch (err) {
416
534
  error(err.message);
535
+ return null;
417
536
  }
418
537
  });
419
538
  }
@@ -423,7 +542,7 @@ class Database {
423
542
  * @param {*} id
424
543
  * @returns
425
544
  */
426
- query(scope, query = {}, includeAll = false) {
545
+ query(form, query = {}, includeAll = false) {
427
546
  if (query._id) {
428
547
  query._id = this.ObjectId(query._id);
429
548
  }
@@ -433,11 +552,11 @@ class Database {
433
552
  if (query.form) {
434
553
  query.form = this.ObjectId(query.form);
435
554
  }
436
- else if (!includeAll && scope.form && scope.form._id) {
437
- query.form = this.ObjectId(scope.form._id);
555
+ else if (!includeAll && form && form._id) {
556
+ query.form = this.ObjectId(form._id);
438
557
  }
439
- if (!includeAll && scope.project && scope.project._id) {
440
- query.project = this.ObjectId(scope.project._id);
558
+ if (!includeAll && form.project) {
559
+ query.project = this.ObjectId(form.project);
441
560
  }
442
561
  if (!includeAll) {
443
562
  query.deleted = { $eq: null };
@@ -445,7 +564,7 @@ class Database {
445
564
  // Handle nested queries.
446
565
  ['$or', '$and'].forEach((key) => {
447
566
  if (query[key]) {
448
- query[key].forEach((subQuery) => this.query(scope, subQuery, true));
567
+ query[key].forEach((subQuery) => this.query(form, subQuery, true));
449
568
  }
450
569
  });
451
570
  return query;
@@ -453,15 +572,15 @@ class Database {
453
572
  /**
454
573
  * Find many records that match a query.
455
574
  */
456
- find(scope_1) {
457
- return __awaiter(this, arguments, void 0, function* (scope, query = {}, limit = 10, skip = 0, sort = { created: -1 }, select = {}, inCollection = null, includeDeleted = false) {
575
+ find(form_1) {
576
+ return __awaiter(this, arguments, void 0, function* (form, dbQuery = {}, limit = 10, skip = 0, sort = { created: -1 }, select = {}, inCollection = null, includeDeleted = false) {
458
577
  try {
459
- debug('db.find()', query);
460
- const collection = inCollection || (yield this.formCollection(scope));
578
+ debug('db.find()', dbQuery);
579
+ const collection = inCollection || (yield this.formCollection(form));
461
580
  if (!collection) {
462
581
  return [];
463
582
  }
464
- return yield collection.find(this.query(scope, query, includeDeleted)).limit(limit).skip(skip).sort(sort).project(select).toArray();
583
+ return yield collection.find(this.query(form, dbQuery, includeDeleted)).limit(limit).skip(skip).sort(sort).project(select).toArray();
465
584
  }
466
585
  catch (err) {
467
586
  error(err.message);
@@ -472,15 +591,19 @@ class Database {
472
591
  /**
473
592
  * Find a record for a provided query.
474
593
  */
475
- findOne(scope_1) {
476
- return __awaiter(this, arguments, void 0, function* (scope, query = {}, options = {}) {
594
+ findOne(form_1) {
595
+ return __awaiter(this, arguments, void 0, function* (form, dbQuery = {}, options = {}) {
477
596
  try {
478
- debug('db.findOne()', query);
479
- const collection = yield this.formCollection(scope);
597
+ debug('db.findOne()', dbQuery);
598
+ const collection = yield this.formCollection(form);
480
599
  if (!collection) {
481
600
  return null;
482
601
  }
483
- return yield collection.findOne(this.query(scope, query));
602
+ const doc = yield collection.findOne(this.query(form, dbQuery));
603
+ if (!doc) {
604
+ return null;
605
+ }
606
+ return doc;
484
607
  }
485
608
  catch (err) {
486
609
  error(err.message);
@@ -494,18 +617,22 @@ class Database {
494
617
  * @param {*} table
495
618
  * @param {*} query
496
619
  */
497
- read(scope, id) {
620
+ read(form, id) {
498
621
  return __awaiter(this, void 0, void 0, function* () {
499
622
  try {
500
623
  debug('db.read()', id);
501
624
  if (!id) {
502
625
  return null;
503
626
  }
504
- const collection = yield this.formCollection(scope);
627
+ const collection = yield this.formCollection(form);
505
628
  if (!collection) {
506
629
  return null;
507
630
  }
508
- return yield collection.findOne(this.query(scope, { _id: this.ObjectId(id) }));
631
+ const doc = yield collection.findOne(this.query(form, { _id: this.ObjectId(id) }));
632
+ if (!doc) {
633
+ return null;
634
+ }
635
+ return doc;
509
636
  }
510
637
  catch (err) {
511
638
  error(err.message);
@@ -519,25 +646,25 @@ class Database {
519
646
  * @param {*} table
520
647
  * @param {*} query
521
648
  */
522
- update(scope_1, id_1, update_1) {
523
- return __awaiter(this, arguments, void 0, function* (scope, id, update, allowFields = []) {
649
+ update(form_1, id_1, update_1) {
650
+ return __awaiter(this, arguments, void 0, function* (form, id, update, allowFields = []) {
524
651
  if (!id || !update) {
525
652
  return null;
526
653
  }
527
654
  update.modified = new Date();
528
655
  try {
529
656
  debug('db.update()', id, update);
530
- const collection = yield this.formCollection(scope);
657
+ const collection = yield this.formCollection(form);
531
658
  if (!collection) {
532
659
  return null;
533
660
  }
534
- const result = yield collection.updateOne(this.query(scope, { _id: this.ObjectId(id) }), {
661
+ const result = yield collection.updateOne(this.query(form, { _id: this.ObjectId(id) }), {
535
662
  $set: (0, lodash_1.pick)(update, ['data', 'metadata', 'modified', 'state'].concat(allowFields))
536
663
  });
537
664
  if (result.modifiedCount === 0) {
538
665
  return null;
539
666
  }
540
- return yield this.read(scope, id);
667
+ return yield this.read(form, id);
541
668
  }
542
669
  catch (err) {
543
670
  error(err.message);
@@ -548,25 +675,25 @@ class Database {
548
675
  /**
549
676
  * Delete a record from the database.
550
677
  */
551
- delete(scope_1, id_1) {
552
- return __awaiter(this, arguments, void 0, function* (scope, id, hard = false) {
678
+ delete(form_1, id_1) {
679
+ return __awaiter(this, arguments, void 0, function* (form, id, hard = false) {
553
680
  if (!id) {
554
681
  return false;
555
682
  }
556
683
  try {
557
684
  debug('db.delete()', id, hard ? '(hard)' : '(soft)');
558
- const collection = yield this.formCollection(scope);
685
+ const collection = yield this.formCollection(form);
559
686
  if (!collection) {
560
687
  return false;
561
688
  }
562
689
  if (hard) {
563
690
  // Hard delete - completely remove the record from the database
564
- const result = yield collection.deleteOne(this.query(scope, { _id: this.ObjectId(id) }, true));
691
+ const result = yield collection.deleteOne(this.query(form, { _id: this.ObjectId(id) }, true));
565
692
  return result.deletedCount > 0;
566
693
  }
567
694
  else {
568
695
  // Soft delete - set deleted timestamp
569
- const result = yield collection.updateOne(this.query(scope, { _id: this.ObjectId(id) }), {
696
+ const result = yield collection.updateOne(this.query(form, { _id: this.ObjectId(id) }), {
570
697
  $set: {
571
698
  deleted: new Date(),
572
699
  modified: new Date()
@@ -610,15 +737,14 @@ class Database {
610
737
  * - If the value is not unique, it returns the id of the non-unique submission.
611
738
  * - If an error occurs, or uniqueness cannot be determined, it will throw an error.
612
739
  *
613
- * @param scope
740
+ * @param form
614
741
  * @param context
615
742
  * @param value
616
743
  * @returns
617
744
  */
618
- isUnique(scope, context, value) {
745
+ isUnique(form, component, submission, componentPath, value) {
619
746
  return __awaiter(this, void 0, void 0, function* () {
620
- const { component, submission, form } = context;
621
- const path = `data.${context.path}`;
747
+ const path = `data.${componentPath}`;
622
748
  if (!form) {
623
749
  return false;
624
750
  }
@@ -666,8 +792,8 @@ class Database {
666
792
  // Perform the query.
667
793
  let result = null;
668
794
  try {
669
- result = yield this.findOne(scope, query, options);
670
- if (!result || ((result === null || result === void 0 ? void 0 : result._id.toString()) === (submission === null || submission === void 0 ? void 0 : submission._id))) {
795
+ result = yield this.findOne(form, query, options);
796
+ if (!(result === null || result === void 0 ? void 0 : result._id) || ((result === null || result === void 0 ? void 0 : result._id.toString()) === (submission === null || submission === void 0 ? void 0 : submission._id))) {
671
797
  return true;
672
798
  }
673
799
  else {
@@ -683,8 +809,8 @@ class Database {
683
809
  $options: 'i'
684
810
  }, query, path);
685
811
  try {
686
- result = yield this.findOne(scope, query);
687
- if (!result || ((result === null || result === void 0 ? void 0 : result._id.toString()) === (submission === null || submission === void 0 ? void 0 : submission._id))) {
812
+ result = yield this.findOne(form, query);
813
+ if (!(result === null || result === void 0 ? void 0 : result._id) || ((result === null || result === void 0 ? void 0 : result._id.toString()) === (submission === null || submission === void 0 ? void 0 : submission._id))) {
688
814
  return true;
689
815
  }
690
816
  else {