2025-01-23 19:41:31 +03:00
|
|
|
import { queryOptions } from '@tanstack/react-query';
|
|
|
|
|
2025-02-12 21:36:03 +03:00
|
|
|
import { IConstituentaReference, ITargetCst } from '@/features/rsform/models/rsform';
|
|
|
|
|
2025-02-11 12:34:28 +03:00
|
|
|
import { axiosGet, axiosPatch, axiosPost } from '@/backend/apiTransport';
|
2025-02-12 20:53:01 +03:00
|
|
|
import { DELAYS, KEYS } from '@/backend/configuration';
|
2025-02-12 01:34:35 +03:00
|
|
|
import { infoMsg } from '@/utils/labels';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
2025-02-12 20:53:01 +03:00
|
|
|
import {
|
|
|
|
ICstRelocateDTO,
|
|
|
|
IInputCreatedResponse,
|
|
|
|
IInputUpdateDTO,
|
|
|
|
IOperationCreatedResponse,
|
|
|
|
IOperationCreateDTO,
|
|
|
|
IOperationDeleteDTO,
|
|
|
|
IOperationPosition,
|
|
|
|
IOperationSchemaDTO,
|
|
|
|
IOperationUpdateDTO,
|
|
|
|
ITargetOperation
|
|
|
|
} from './types';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
|
|
|
export const ossApi = {
|
2025-02-12 20:53:01 +03:00
|
|
|
baseKey: KEYS.oss,
|
2025-01-23 19:41:31 +03:00
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
getOssQueryOptions: ({ itemID }: { itemID?: number }) => {
|
2025-01-23 19:41:31 +03:00
|
|
|
return queryOptions({
|
2025-02-12 20:53:01 +03:00
|
|
|
queryKey: KEYS.composite.ossItem({ itemID }),
|
2025-01-23 19:41:31 +03:00
|
|
|
staleTime: DELAYS.staleShort,
|
|
|
|
queryFn: meta =>
|
|
|
|
!itemID
|
|
|
|
? undefined
|
2025-01-30 19:55:24 +03:00
|
|
|
: axiosGet<IOperationSchemaDTO>({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: `/api/oss/${itemID}/details`,
|
|
|
|
options: { signal: meta.signal }
|
|
|
|
})
|
2025-01-23 19:41:31 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2025-01-28 19:45:31 +03:00
|
|
|
updatePositions: ({
|
|
|
|
itemID,
|
|
|
|
positions,
|
|
|
|
isSilent
|
|
|
|
}: {
|
2025-02-12 15:12:59 +03:00
|
|
|
itemID: number;
|
2025-01-28 19:45:31 +03:00
|
|
|
positions: IOperationPosition[];
|
|
|
|
isSilent?: boolean;
|
|
|
|
}) =>
|
|
|
|
axiosPatch({
|
|
|
|
endpoint: `/api/oss/${itemID}/update-positions`,
|
|
|
|
request: {
|
|
|
|
data: { positions: positions },
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: isSilent ? undefined : infoMsg.changesSaved
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-01-23 19:41:31 +03:00
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
operationCreate: ({ itemID, data }: { itemID: number; data: IOperationCreateDTO }) =>
|
2025-01-28 19:45:31 +03:00
|
|
|
axiosPost<IOperationCreateDTO, IOperationCreatedResponse>({
|
|
|
|
endpoint: `/api/oss/${itemID}/create-operation`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: response => infoMsg.newOperation(response.new_operation.alias)
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:12:59 +03:00
|
|
|
operationDelete: ({ itemID, data }: { itemID: number; data: IOperationDeleteDTO }) =>
|
2025-02-11 12:34:28 +03:00
|
|
|
axiosPatch<IOperationDeleteDTO, IOperationSchemaDTO>({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: `/api/oss/${itemID}/delete-operation`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.operationDestroyed
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:12:59 +03:00
|
|
|
inputCreate: ({ itemID, data }: { itemID: number; data: ITargetOperation }) =>
|
2025-01-28 19:45:31 +03:00
|
|
|
axiosPatch<ITargetOperation, IInputCreatedResponse>({
|
|
|
|
endpoint: `/api/oss/${itemID}/create-input`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.newLibraryItem
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:12:59 +03:00
|
|
|
inputUpdate: ({ itemID, data }: { itemID: number; data: IInputUpdateDTO }) =>
|
2025-01-30 19:55:24 +03:00
|
|
|
axiosPatch<IInputUpdateDTO, IOperationSchemaDTO>({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: `/api/oss/${itemID}/set-input`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:12:59 +03:00
|
|
|
operationUpdate: ({ itemID, data }: { itemID: number; data: IOperationUpdateDTO }) =>
|
2025-01-30 19:55:24 +03:00
|
|
|
axiosPatch<IOperationUpdateDTO, IOperationSchemaDTO>({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: `/api/oss/${itemID}/update-operation`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:12:59 +03:00
|
|
|
operationExecute: ({ itemID, data }: { itemID: number; data: ITargetOperation }) =>
|
2025-01-30 19:55:24 +03:00
|
|
|
axiosPost<ITargetOperation, IOperationSchemaDTO>({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: `/api/oss/${itemID}/execute-operation`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.operationExecuted
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2025-02-10 15:48:58 +03:00
|
|
|
relocateConstituents: (data: ICstRelocateDTO) =>
|
2025-01-30 19:55:24 +03:00
|
|
|
axiosPost<ICstRelocateDTO, IOperationSchemaDTO>({
|
2025-02-10 15:48:58 +03:00
|
|
|
endpoint: `/api/oss/relocate-constituents`,
|
2025-01-28 19:45:31 +03:00
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:45:31 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-01-23 19:41:31 +03:00
|
|
|
getPredecessor: (data: ITargetCst) =>
|
2025-01-28 19:45:31 +03:00
|
|
|
axiosPost<ITargetCst, IConstituentaReference>({
|
|
|
|
endpoint: '/api/oss/get-predecessor',
|
|
|
|
request: { data: data }
|
|
|
|
})
|
2025-01-23 19:41:31 +03:00
|
|
|
};
|