@overmap-ai/core 1.0.51-fix-document-urls.0 → 1.0.51-fix-document-urls.2

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.
@@ -4059,9 +4059,18 @@ var __publicField = (obj, key, value) => {
4059
4059
  }
4060
4060
  }
4061
4061
  for (const document2 of action.payload) {
4062
+ const existingDocument = state.documents[document2.offline_id];
4063
+ if (document2.organization !== void 0 && document2.organization !== existingDocument.organization) {
4064
+ throw new Error("organization cannot be updated");
4065
+ }
4066
+ if (document2.project !== void 0 && document2.project !== existingDocument.project) {
4067
+ throw new Error("project cannot be updated");
4068
+ }
4062
4069
  state.documents[document2.offline_id] = {
4063
- ...state.documents[document2.offline_id],
4070
+ ...existingDocument,
4064
4071
  ...document2
4072
+ // Without the cast, TypeScript doesn't realize that we have guaranteed that the document doesn't
4073
+ // have both a project and an organization.
4065
4074
  };
4066
4075
  }
4067
4076
  },
@@ -7993,13 +8002,23 @@ var __publicField = (obj, key, value) => {
7993
8002
  const { store } = this.client;
7994
8003
  const currentUserId = store.getState().userReducer.currentUser.id;
7995
8004
  const activeProjectId = store.getState().projectReducer.activeProjectId;
7996
- const offlineDocument = offline({ ...document2, created_by: currentUserId });
7997
- store.dispatch(addDocuments([offlineDocument]));
8005
+ if (!activeProjectId) {
8006
+ throw new Error("No active project ID while creating document.");
8007
+ }
8008
+ const offlineDocument = offline(document2);
8009
+ const submittedDocument = {
8010
+ ...offlineDocument,
8011
+ created_by: currentUserId,
8012
+ project: activeProjectId,
8013
+ organization: null,
8014
+ children_documents: []
8015
+ };
8016
+ store.dispatch(addDocuments([submittedDocument]));
7998
8017
  const promise = this.enqueueRequest({
7999
8018
  description: "Create Document",
8000
8019
  method: HttpMethod.POST,
8001
- url: `/projects/${activeProjectId}/create-document/`,
8002
- payload: { ...offlineDocument },
8020
+ url: `/projects/${activeProjectId}/documents/`,
8021
+ payload: offlineDocument,
8003
8022
  queryParams: {
8004
8023
  parent_document: offlineDocument.parent_document ?? void 0
8005
8024
  },
@@ -8010,7 +8029,7 @@ var __publicField = (obj, key, value) => {
8010
8029
  promise.catch(() => {
8011
8030
  store.dispatch(removeDocuments([offlineDocument.offline_id]));
8012
8031
  });
8013
- return [offlineDocument, promise];
8032
+ return [submittedDocument, promise];
8014
8033
  }
8015
8034
  update(document2) {
8016
8035
  const { store } = this.client;