2025-01-27 15:03:48 +03:00
|
|
|
import { queryOptions } from '@tanstack/react-query';
|
|
|
|
|
2025-02-05 12:43:16 +03:00
|
|
|
import { axiosGet, axiosPatch, axiosPost } from '@/backend/apiTransport';
|
2025-02-12 20:53:31 +03:00
|
|
|
import { DELAYS, KEYS } from '@/backend/configuration';
|
|
|
|
import { infoMsg } from '@/utils/labels';
|
2025-02-10 01:32:55 +03:00
|
|
|
|
2025-02-17 14:40:18 +03:00
|
|
|
import { IConstituentaList } from '../models/rsform';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-01-27 15:03:48 +03:00
|
|
|
import {
|
2025-02-12 20:53:31 +03:00
|
|
|
ICheckConstituentaDTO,
|
2025-02-17 14:40:18 +03:00
|
|
|
IConstituentaBasicsDTO,
|
2025-02-12 20:53:31 +03:00
|
|
|
ICstCreatedResponse,
|
|
|
|
ICstCreateDTO,
|
|
|
|
ICstMoveDTO,
|
|
|
|
ICstRenameDTO,
|
|
|
|
ICstSubstitutionsDTO,
|
|
|
|
ICstUpdateDTO,
|
2025-02-17 14:40:18 +03:00
|
|
|
IExpressionParseDTO,
|
2025-02-12 20:53:31 +03:00
|
|
|
IInlineSynthesisDTO,
|
|
|
|
IProduceStructureResponse,
|
|
|
|
IRSFormDTO,
|
2025-02-17 14:40:18 +03:00
|
|
|
IRSFormUploadDTO,
|
|
|
|
ITargetCst,
|
|
|
|
schemaConstituentaBasics,
|
|
|
|
schemaCstCreatedResponse,
|
|
|
|
schemaExpressionParse,
|
|
|
|
schemaProduceStructureResponse,
|
|
|
|
schemaRSForm
|
2025-02-12 20:53:31 +03:00
|
|
|
} from './types';
|
2025-02-12 02:12:08 +03:00
|
|
|
|
2025-01-27 15:03:48 +03:00
|
|
|
export const rsformsApi = {
|
2025-02-12 20:53:31 +03:00
|
|
|
baseKey: KEYS.rsform,
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
getRSFormQueryOptions: ({ itemID, version }: { itemID?: number; version?: number }) => {
|
2025-01-27 15:03:48 +03:00
|
|
|
return queryOptions({
|
2025-02-12 20:53:31 +03:00
|
|
|
queryKey: KEYS.composite.rsItem({ itemID, version }),
|
2025-01-27 15:03:48 +03:00
|
|
|
staleTime: DELAYS.staleShort,
|
|
|
|
queryFn: meta =>
|
|
|
|
!itemID
|
|
|
|
? undefined
|
2025-01-30 19:55:38 +03:00
|
|
|
: axiosGet<IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: version ? `/api/library/${itemID}/versions/${version}` : `/api/rsforms/${itemID}/details`,
|
|
|
|
options: { signal: meta.signal }
|
|
|
|
})
|
2025-01-27 15:03:48 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
download: ({ itemID, version }: { itemID: number; version?: number }) =>
|
2025-01-28 19:47:24 +03:00
|
|
|
axiosGet<Blob>({
|
|
|
|
endpoint: version ? `/api/versions/${version}/export-file` : `/api/rsforms/${itemID}/export-trs`,
|
|
|
|
options: { responseType: 'blob' }
|
|
|
|
}),
|
2025-01-27 15:03:48 +03:00
|
|
|
upload: (data: IRSFormUploadDTO) =>
|
2025-01-30 19:55:38 +03:00
|
|
|
axiosPatch<IRSFormUploadDTO, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${data.itemID}/load-trs`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.uploadSuccess
|
2025-01-28 19:47:24 +03:00
|
|
|
},
|
|
|
|
options: {
|
2025-01-27 15:03:48 +03:00
|
|
|
headers: {
|
|
|
|
'Content-Type': 'multipart/form-data'
|
|
|
|
}
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
cstCreate: ({ itemID, data }: { itemID: number; data: ICstCreateDTO }) =>
|
2025-01-28 19:47:24 +03:00
|
|
|
axiosPost<ICstCreateDTO, ICstCreatedResponse>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaCstCreatedResponse,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/create-cst`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: response => infoMsg.newConstituent(response.new_cst.alias)
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
cstUpdate: ({ itemID, data }: { itemID: number; data: ICstUpdateDTO }) =>
|
2025-02-17 14:40:18 +03:00
|
|
|
axiosPatch<ICstUpdateDTO, IConstituentaBasicsDTO>({
|
|
|
|
schema: schemaConstituentaBasics,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/update-cst`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
cstDelete: ({ itemID, data }: { itemID: number; data: IConstituentaList }) =>
|
2025-02-05 12:43:16 +03:00
|
|
|
axiosPatch<IConstituentaList, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/delete-multiple-cst`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.constituentsDestroyed(data.items.length)
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
cstRename: ({ itemID, data }: { itemID: number; data: ICstRenameDTO }) =>
|
2025-01-28 19:47:24 +03:00
|
|
|
axiosPatch<ICstRenameDTO, ICstCreatedResponse>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaCstCreatedResponse,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/rename-cst`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
cstSubstitute: ({ itemID, data }: { itemID: number; data: ICstSubstitutionsDTO }) =>
|
2025-02-12 02:12:08 +03:00
|
|
|
axiosPatch<ICstSubstitutionsDTO, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/substitute`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.substituteSingle
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
cstMove: ({ itemID, data }: { itemID: number; data: ICstMoveDTO }) =>
|
2025-01-30 19:55:38 +03:00
|
|
|
axiosPatch<ICstMoveDTO, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/move-cst`,
|
|
|
|
request: { data: data }
|
|
|
|
}),
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
produceStructure: ({ itemID, data }: { itemID: number; data: ITargetCst }) =>
|
2025-02-12 02:12:08 +03:00
|
|
|
axiosPatch<ITargetCst, IProduceStructureResponse>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaProduceStructureResponse,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/produce-structure`,
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: response => infoMsg.addedConstituents(response.cst_list.length)
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 12:21:19 +03:00
|
|
|
inlineSynthesis: (data: IInlineSynthesisDTO) =>
|
|
|
|
axiosPatch<IInlineSynthesisDTO, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-02-12 12:21:19 +03:00
|
|
|
endpoint: `/api/rsforms/inline-synthesis`,
|
2025-01-28 19:47:24 +03:00
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.inlineSynthesisComplete
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
restoreOrder: ({ itemID }: { itemID: number }) =>
|
2025-01-30 19:55:38 +03:00
|
|
|
axiosPatch<undefined, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/restore-order`,
|
2025-02-12 01:35:41 +03:00
|
|
|
request: { successMessage: infoMsg.reorderComplete }
|
2025-01-28 19:47:24 +03:00
|
|
|
}),
|
2025-02-12 15:13:37 +03:00
|
|
|
resetAliases: ({ itemID }: { itemID: number }) =>
|
2025-01-30 19:55:38 +03:00
|
|
|
axiosPatch<undefined, IRSFormDTO>({
|
2025-02-17 14:40:18 +03:00
|
|
|
schema: schemaRSForm,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/reset-aliases`,
|
2025-02-12 01:35:41 +03:00
|
|
|
request: { successMessage: infoMsg.reindexComplete }
|
2025-01-28 19:47:24 +03:00
|
|
|
}),
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
checkConstituenta: ({ itemID, data }: { itemID: number; data: ICheckConstituentaDTO }) =>
|
2025-02-17 14:40:18 +03:00
|
|
|
axiosPost<ICheckConstituentaDTO, IExpressionParseDTO>({
|
|
|
|
schema: schemaExpressionParse,
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: `/api/rsforms/${itemID}/check-constituenta`,
|
|
|
|
request: { data: data }
|
|
|
|
})
|
2025-01-27 15:03:48 +03:00
|
|
|
};
|