Skip to content

Commit

Permalink
Draft scheme statement, #151
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Jan 15, 2025
1 parent bd40a04 commit e0bbe60
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 52 deletions.
76 changes: 71 additions & 5 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import arches from "arches";
import Cookies from "js-cookie";
import type { AppellativeStatus, SchemeInstance, SchemeRights } from "@/arches_lingo/types";
import type { AppellativeStatus, SchemeInstance, SchemeRights, SchemeRightStatement } from "@/arches_lingo/types";

function getToken() {
const token = Cookies.get("csrftoken");
Expand Down Expand Up @@ -223,8 +223,21 @@ export const updateSchemeNamespace = async (
return parsed;
};

export const fetchSchemeRightStatement = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_right_statement_tile(schemeId, tileid1, tileid2));
export const createSchemeRights = async (
schemeId: string,
schemeRightsValue: SchemeRights,
) => {
const response = await fetch(arches.urls.api_scheme_rights_tile_create, {
method: "POST",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify({
resourceinstance: schemeId,
...schemeRightsValue,
}),
});
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
Expand All @@ -248,13 +261,50 @@ export const updateSchemeRights = async (
return parsed;
};

export const deleteSchemeRights = async (
schemeId: string,
tileId: string,
) => {
const response = await fetch(
arches.urls.api_scheme_rights_tile(schemeId, tileId),
{
method: "DELETE",
headers: { "X-CSRFTOKEN": getToken() },
},
);

if (!response.ok) {
const parsed = await response.json();
throw new Error(parsed.message || response.statusText);
} else {
return true;
}
};

export const createSchemeRightStatement = async (
schemeId: string,
tileId: string,
schemeRightStatementValue: SchemeRightStatement,
) => {
const response = await fetch(arches.urls.api_scheme_right_statement_tile_create(schemeId, tileId), {
method: "PATCH",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify(schemeRightStatementValue),
});
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const updateSchemeRightStatement = async (
schemeId: string,
tileId: string,
childTileId: string,
schemeRightStatementValue: SchemeRightStatement,
) => {
const response = await fetch(arches.urls.api_scheme_right_statement_tile(schemeId, tileId, childTileId), {
const response = await fetch(arches.urls.api_scheme_right_statement_tile(schemeId, tileId), {
method: "PATCH",
headers: {
"X-CSRFTOKEN": getToken(),
Expand All @@ -267,6 +317,22 @@ export const updateSchemeRightStatement = async (
return parsed;
};

export const deleteSchemeRightStatement = async (
schemeId: string,
tileId: string,
) => {
const response = await fetch(arches.urls.api_scheme_right_statement_tile(schemeId, tileId), {
method: "DELETE",
headers: { "X-CSRFTOKEN": getToken() },
});
if (!response.ok) {
const parsed = await response.json();
throw new Error(parsed.message || response.statusText);
} else {
return true;
}
};

export const fetchSearchResults = async (
searchTerm: string,
items: number,
Expand Down
Loading

0 comments on commit e0bbe60

Please sign in to comment.