@overmap-ai/core 1.0.38-component-fields.16 → 1.0.38-component-fields.17

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.
@@ -3013,7 +3013,7 @@ var __publicField = (obj, key, value) => {
3013
3013
  delete LATEST_REVISION_CACHE[userFormRevision.offline_id];
3014
3014
  }
3015
3015
  },
3016
- addUserFormSubmission: (state, action) => {
3016
+ updateOrCreateUserFormSubmission: (state, action) => {
3017
3017
  state.submissions[action.payload.offline_id] = action.payload;
3018
3018
  },
3019
3019
  addUserFormSubmissionAttachment: (state, action) => {
@@ -3102,7 +3102,7 @@ var __publicField = (obj, key, value) => {
3102
3102
  addUserForm,
3103
3103
  addUserForms,
3104
3104
  addUserFormRevisions,
3105
- addUserFormSubmission,
3105
+ updateOrCreateUserFormSubmission,
3106
3106
  addUserFormSubmissions,
3107
3107
  deleteUserFormSubmission,
3108
3108
  deleteUserFormSubmissions,
@@ -5705,6 +5705,43 @@ var __publicField = (obj, key, value) => {
5705
5705
  return { payloadWithoutFiles, files };
5706
5706
  };
5707
5707
  class UserFormSubmissionService extends BaseApiService {
5708
+ constructor() {
5709
+ super(...arguments);
5710
+ // Attach files to submission, after uploading them to S3
5711
+ __publicField(this, "getAttachFilesPromises", (files, payload) => {
5712
+ const { store } = this.client;
5713
+ return Object.entries(files).map(async ([key, fileArray]) => {
5714
+ const attachResults = [];
5715
+ for (const file of fileArray) {
5716
+ const sha1 = await hashFile(file);
5717
+ await this.client.files.addCache(file, sha1);
5718
+ const [fileProps] = await this.client.files.uploadFileToS3(sha1);
5719
+ const submissionAttachmentPayload = offline({
5720
+ ...fileProps,
5721
+ submission: payload.offline_id,
5722
+ field_identifier: key
5723
+ });
5724
+ const attach = await this.enqueueRequest({
5725
+ description: "Attach file to form submission",
5726
+ method: HttpMethod.POST,
5727
+ url: `/forms/submission/${payload.offline_id}/attachments/`,
5728
+ payload: submissionAttachmentPayload,
5729
+ blockers: [payload.component, payload.issue, payload.form_revision].filter(
5730
+ (x) => x !== void 0
5731
+ ),
5732
+ blocks: [submissionAttachmentPayload.offline_id]
5733
+ });
5734
+ const offlinePayload = {
5735
+ ...submissionAttachmentPayload,
5736
+ file: URL.createObjectURL(file)
5737
+ };
5738
+ store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
5739
+ attachResults.push(attach);
5740
+ }
5741
+ return attachResults;
5742
+ });
5743
+ });
5744
+ }
5708
5745
  add(payload) {
5709
5746
  const { store } = this.client;
5710
5747
  const state = store.getState();
@@ -5721,36 +5758,7 @@ var __publicField = (obj, key, value) => {
5721
5758
  blockers: [payload.issue, payload.component].filter((x) => x !== void 0),
5722
5759
  blocks: [payload.offline_id]
5723
5760
  });
5724
- const attachFilesPromises = Object.entries(files).map(async ([key, fileArray]) => {
5725
- const attachResults = [];
5726
- for (const file of fileArray) {
5727
- const sha1 = await hashFile(file);
5728
- await this.client.files.addCache(file, sha1);
5729
- const [fileProps] = await this.client.files.uploadFileToS3(sha1);
5730
- const submissionAttachmentPayload = offline({
5731
- ...fileProps,
5732
- submission: payload.offline_id,
5733
- field_identifier: key
5734
- });
5735
- const attach = await this.enqueueRequest({
5736
- description: "Attach file to form submission",
5737
- method: HttpMethod.POST,
5738
- url: `/forms/submission/${payload.offline_id}/attachments/`,
5739
- payload: submissionAttachmentPayload,
5740
- blockers: [payload.component, payload.issue, payload.form_revision].filter(
5741
- (x) => x !== void 0
5742
- ),
5743
- blocks: [submissionAttachmentPayload.offline_id]
5744
- });
5745
- const offlinePayload = {
5746
- ...submissionAttachmentPayload,
5747
- file: URL.createObjectURL(file)
5748
- };
5749
- store.dispatch(addUserFormSubmissionAttachment(offlinePayload));
5750
- attachResults.push(attach);
5751
- }
5752
- return attachResults;
5753
- });
5761
+ const attachFilesPromises = this.getAttachFilesPromises(files, payload);
5754
5762
  const fullOfflineResult = {
5755
5763
  ...payload,
5756
5764
  created_by: state.userReducer.currentUser.id,
@@ -5760,9 +5768,9 @@ var __publicField = (obj, key, value) => {
5760
5768
  ...fullOfflineResult,
5761
5769
  ...payloadWithoutFiles
5762
5770
  };
5763
- store.dispatch(addUserFormSubmission(offlineResultWithoutFiles));
5771
+ store.dispatch(updateOrCreateUserFormSubmission(offlineResultWithoutFiles));
5764
5772
  void promise.then((result) => {
5765
- store.dispatch(addUserFormSubmission(result));
5773
+ store.dispatch(updateOrCreateUserFormSubmission(result));
5766
5774
  return result;
5767
5775
  }).catch(() => {
5768
5776
  store.dispatch(deleteUserFormSubmission(payload.offline_id));
@@ -5770,6 +5778,26 @@ var __publicField = (obj, key, value) => {
5770
5778
  const settledPromise = Promise.all([promise, ...attachFilesPromises]).then(() => promise);
5771
5779
  return [fullOfflineResult, settledPromise];
5772
5780
  }
5781
+ update(submission) {
5782
+ const { store } = this.client;
5783
+ const { payloadWithoutFiles, files } = separateFilesFromValues(submission);
5784
+ if (!("created_by" in payloadWithoutFiles) || !("created_at" in payloadWithoutFiles)) {
5785
+ throw new Error("Expected payloadWithoutFiles to have created_by and created_at fields.");
5786
+ }
5787
+ const attachFilesPromises = this.getAttachFilesPromises(files, submission);
5788
+ store.dispatch(updateOrCreateUserFormSubmission(payloadWithoutFiles));
5789
+ const promise = this.enqueueRequest({
5790
+ description: "Patch form submission",
5791
+ method: HttpMethod.PATCH,
5792
+ url: `/submissions/${submission.offline_id}/`,
5793
+ payload: payloadWithoutFiles,
5794
+ blockers: [payloadWithoutFiles.issue, payloadWithoutFiles.component].filter(
5795
+ (x) => x !== void 0
5796
+ ),
5797
+ blocks: [payloadWithoutFiles.offline_id]
5798
+ });
5799
+ return Promise.all([promise, ...attachFilesPromises]).then(() => promise);
5800
+ }
5773
5801
  async delete(submissionId) {
5774
5802
  const { store } = this.client;
5775
5803
  const state = store.getState();
@@ -5785,7 +5813,7 @@ var __publicField = (obj, key, value) => {
5785
5813
  });
5786
5814
  } catch (e) {
5787
5815
  if (submission) {
5788
- store.dispatch(addUserFormSubmission(submission));
5816
+ store.dispatch(updateOrCreateUserFormSubmission(submission));
5789
5817
  }
5790
5818
  throw e;
5791
5819
  }
@@ -11910,7 +11938,6 @@ var __publicField = (obj, key, value) => {
11910
11938
  exports2.addUserFormRevision = addUserFormRevision;
11911
11939
  exports2.addUserFormRevisionAttachment = addUserFormRevisionAttachment;
11912
11940
  exports2.addUserFormRevisions = addUserFormRevisions;
11913
- exports2.addUserFormSubmission = addUserFormSubmission;
11914
11941
  exports2.addUserFormSubmissionAttachment = addUserFormSubmissionAttachment;
11915
11942
  exports2.addUserFormSubmissions = addUserFormSubmissions;
11916
11943
  exports2.addUserForms = addUserForms;
@@ -12244,6 +12271,7 @@ var __publicField = (obj, key, value) => {
12244
12271
  exports2.updateComponent = updateComponent;
12245
12272
  exports2.updateIssue = updateIssue;
12246
12273
  exports2.updateOrCreateProject = updateOrCreateProject;
12274
+ exports2.updateOrCreateUserFormSubmission = updateOrCreateUserFormSubmission;
12247
12275
  exports2.updateOrganizationAccess = updateOrganizationAccess;
12248
12276
  exports2.updateProjectAccess = updateProjectAccess;
12249
12277
  exports2.updateStages = updateStages;