@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.
@@ -4069,9 +4069,18 @@ const documentSlice = createSlice({
4069
4069
  }
4070
4070
  }
4071
4071
  for (const document2 of action.payload) {
4072
+ const existingDocument = state.documents[document2.offline_id];
4073
+ if (document2.organization !== void 0 && document2.organization !== existingDocument.organization) {
4074
+ throw new Error("organization cannot be updated");
4075
+ }
4076
+ if (document2.project !== void 0 && document2.project !== existingDocument.project) {
4077
+ throw new Error("project cannot be updated");
4078
+ }
4072
4079
  state.documents[document2.offline_id] = {
4073
- ...state.documents[document2.offline_id],
4080
+ ...existingDocument,
4074
4081
  ...document2
4082
+ // Without the cast, TypeScript doesn't realize that we have guaranteed that the document doesn't
4083
+ // have both a project and an organization.
4075
4084
  };
4076
4085
  }
4077
4086
  },
@@ -8003,13 +8012,23 @@ class DocumentService extends BaseApiService {
8003
8012
  const { store } = this.client;
8004
8013
  const currentUserId = store.getState().userReducer.currentUser.id;
8005
8014
  const activeProjectId = store.getState().projectReducer.activeProjectId;
8006
- const offlineDocument = offline({ ...document2, created_by: currentUserId });
8007
- store.dispatch(addDocuments([offlineDocument]));
8015
+ if (!activeProjectId) {
8016
+ throw new Error("No active project ID while creating document.");
8017
+ }
8018
+ const offlineDocument = offline(document2);
8019
+ const submittedDocument = {
8020
+ ...offlineDocument,
8021
+ created_by: currentUserId,
8022
+ project: activeProjectId,
8023
+ organization: null,
8024
+ children_documents: []
8025
+ };
8026
+ store.dispatch(addDocuments([submittedDocument]));
8008
8027
  const promise = this.enqueueRequest({
8009
8028
  description: "Create Document",
8010
8029
  method: HttpMethod.POST,
8011
- url: `/projects/${activeProjectId}/create-document/`,
8012
- payload: { ...offlineDocument },
8030
+ url: `/projects/${activeProjectId}/documents/`,
8031
+ payload: offlineDocument,
8013
8032
  queryParams: {
8014
8033
  parent_document: offlineDocument.parent_document ?? void 0
8015
8034
  },
@@ -8020,7 +8039,7 @@ class DocumentService extends BaseApiService {
8020
8039
  promise.catch(() => {
8021
8040
  store.dispatch(removeDocuments([offlineDocument.offline_id]));
8022
8041
  });
8023
- return [offlineDocument, promise];
8042
+ return [submittedDocument, promise];
8024
8043
  }
8025
8044
  update(document2) {
8026
8045
  const { store } = this.client;