@researchdatabox/sails-hook-redbox-storage-mongo 1.4.8 → 1.4.10

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.
@@ -146,6 +146,7 @@ var Services;
146
146
  _.unset(record, 'dateCreated');
147
147
  _.unset(record, 'lastSaveDate');
148
148
  _.unset(record, '_id');
149
+ _.unset(record, 'id');
149
150
  yield Record.updateOne({ redboxOid: oid }).set(record);
150
151
  response.success = true;
151
152
  }
@@ -663,9 +664,11 @@ var Services;
663
664
  updateDatastream(oid, record, newMetadata, fileRoot, fileIdsAdded) {
664
665
  return FormsService.getFormByName(record.metaMetadata.form, true)
665
666
  .flatMap(form => {
667
+ form = form !== null && form !== void 0 ? form : { attachmentFields: [] };
668
+ const typedForm = form;
666
669
  const reqs = [];
667
670
  record.metaMetadata.attachmentFields = form.attachmentFields;
668
- _.each(form.attachmentFields, (attField) => __awaiter(this, void 0, void 0, function* () {
671
+ _.each(typedForm.attachmentFields, (attField) => __awaiter(this, void 0, void 0, function* () {
669
672
  const oldAttachments = record.metadata[attField];
670
673
  const newAttachments = newMetadata[attField];
671
674
  const removeIds = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@researchdatabox/sails-hook-redbox-storage-mongo",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "A MongoDB storage plugin for ReDBox.",
5
5
  "main": "index.js",
6
6
  "sails": {
@@ -153,6 +153,12 @@ export module Services {
153
153
  _.unset(record, 'dateCreated');
154
154
  _.unset(record, 'lastSaveDate');
155
155
  _.unset(record, '_id');
156
+
157
+ // Records with an 'id' property fail to save with error:
158
+ // {"cause":{"name":"AdapterError","adapterMethodName":"update","modelIdentity":"record","raw":{"code":"E_CANNOT_INTERPRET_AS_OBJECTID"}},"isOperational":true}
159
+ // Fix by ensuring the 'id' property is removed.
160
+ _.unset(record, 'id');
161
+
156
162
  await Record.updateOne({ redboxOid: oid }).set(record);
157
163
  response.success = true;
158
164
  } catch (err) {
@@ -700,9 +706,13 @@ export module Services {
700
706
  // loop thru the attachment fields and determine if we need to add or remove
701
707
  return FormsService.getFormByName(record.metaMetadata.form, true)
702
708
  .flatMap(form => {
709
+ // For any generated, view-only forms, the form may be null, add a coalescence to avoid breaking
710
+ // the attachment update process.
711
+ form = form ?? { attachmentFields: [] };
712
+ const typedForm = form as { attachmentFields: string[] };
703
713
  const reqs = [];
704
714
  record.metaMetadata.attachmentFields = form.attachmentFields;
705
- _.each(form.attachmentFields, async (attField) => {
715
+ _.each(typedForm.attachmentFields, async (attField) => {
706
716
  const oldAttachments = record.metadata[attField];
707
717
  const newAttachments = newMetadata[attField];
708
718
  const removeIds = [];