mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-01 10:59:45 +00:00
Add attachments to workflow
This commit is contained in:
@@ -83,6 +83,10 @@ export const makeFetch = <Input, Output>(
|
||||
opts = Object.assign(opts, options);
|
||||
}
|
||||
return fetch(url, opts).then((response) => {
|
||||
if (response.status === 204) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
@@ -173,18 +177,26 @@ function _fetchAction<T>(
|
||||
|
||||
throw new Error("other network error");
|
||||
})
|
||||
.catch((reason: any) => {
|
||||
console.error(reason);
|
||||
throw new Error(reason);
|
||||
});
|
||||
.catch(
|
||||
(
|
||||
reason:
|
||||
| NotFoundExceptionInterface
|
||||
| ServerExceptionInterface
|
||||
| ValidationExceptionInterface
|
||||
| TransportExceptionInterface,
|
||||
) => {
|
||||
console.error(reason);
|
||||
throw reason;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export const fetchResults = async <T>(
|
||||
uri: string,
|
||||
params?: FetchParams,
|
||||
): Promise<T[]> => {
|
||||
let promises: Promise<T[]>[] = [],
|
||||
page = 1;
|
||||
const promises: Promise<T[]>[] = [];
|
||||
let page = 1;
|
||||
const firstData: PaginationResponse<T> = (await _fetchAction(
|
||||
page,
|
||||
uri,
|
||||
@@ -229,6 +241,7 @@ const ValidationException = (
|
||||
return error;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const AccessException = (response: Response): AccessExceptionInterface => {
|
||||
const error = {} as AccessExceptionInterface;
|
||||
error.name = "AccessException";
|
||||
@@ -237,6 +250,7 @@ const AccessException = (response: Response): AccessExceptionInterface => {
|
||||
return error;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const NotFoundException = (response: Response): NotFoundExceptionInterface => {
|
||||
const error = {} as NotFoundExceptionInterface;
|
||||
error.name = "NotFoundException";
|
||||
@@ -257,6 +271,7 @@ const ServerException = (
|
||||
};
|
||||
|
||||
const ConflictHttpException = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
response: Response,
|
||||
): ConflictHttpExceptionInterface => {
|
||||
const error = {} as ConflictHttpExceptionInterface;
|
||||
|
@@ -0,0 +1,22 @@
|
||||
import { WorkflowAttachment } from "ChillMainAssets/types";
|
||||
import { GenericDocForAccompanyingPeriod } from "ChillDocStoreAssets/types/generic_doc";
|
||||
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
||||
|
||||
export const find_attachments_by_workflow = async (
|
||||
workflowId: number,
|
||||
): Promise<WorkflowAttachment[]> =>
|
||||
makeFetch("GET", `/api/1.0/main/workflow/${workflowId}/attachment`);
|
||||
|
||||
export const create_attachment = async (
|
||||
workflowId: number,
|
||||
genericDoc: GenericDocForAccompanyingPeriod,
|
||||
): Promise<WorkflowAttachment> =>
|
||||
makeFetch("POST", `/api/1.0/main/workflow/${workflowId}/attachment`, {
|
||||
relatedGenericDocKey: genericDoc.key,
|
||||
relatedGenericDocIdentifiers: genericDoc.identifiers,
|
||||
});
|
||||
|
||||
export const delete_attachment = async (
|
||||
attachment: WorkflowAttachment,
|
||||
): Promise<void> =>
|
||||
makeFetch("DELETE", `/api/1.0/main/workflow/attachment/${attachment.id}`);
|
Reference in New Issue
Block a user