File "updateArticle.ts"
Full Path: /var/www/html/gitep_front/src/entities/project/api/updateArticle.ts
File size: 3.48 KB
MIME-type: text/x-java
Charset: utf-8
import { $modelStore } from '@shared/index';
import { axiosInstance } from "@shared/api";
import { notification } from 'antd';
export const updateArticle = async (articleID: number, articleType: string) => {
try {
const modelId = $modelStore.getState().model;
if (!modelId) {
throw new Error("modelId не задана");
}
const params = {
article_type: articleType
};
const result = await axiosInstance.post(`article/${modelId}/${articleID}/update`, params);
notification.success({
message: 'Успех',
description: 'Статья успешно добавлена',
});
return result
} catch (error) {
console.error('getProgects error', error)
notification.error({
message: 'Ошибка',
description: 'Не удалось добавить статью',
})
}
}
export const addArticle = async (projectId: number, articleId: number) => {
try {
const modelId = $modelStore.getState().model;
if (!modelId) {
throw new Error("modelId не задана");
}
const params = {
article_id: articleId,
project_id: projectId
}
const result = await axiosInstance.post(`article-project/${modelId}/${articleId}`, params);
notification.success({
message: 'Успех',
description: 'Статья успешно добавлена',
});
return result
} catch (error) {
console.error('getProgects error', error)
notification.error({
message: 'Ошибка',
description: 'Не удалось добавить статью',
})
}
}
export const addArticleCash = async (name: string, articleType: string, articleGroupId?: string) => {
try {
const modelId = $modelStore.getState().model;
if (!modelId) {
throw new Error("modelId не задана");
}
const params = {
name: name,
article_type: articleType,
article_group_id: articleGroupId
}
const result = await axiosInstance.post(`article/${modelId}/create`, params);
notification.success({
message: 'Успех',
description: 'Статья успешно добавлена',
});
return result
} catch (error) {
console.error('getProgects error', error)
notification.error({
message: 'Ошибка',
description: 'Не удалось добавить статью',
})
}
}
export const updateArticleCash = async (name: string, articleType: string, articleId: number) => {
try {
const modelId = $modelStore.getState().model;
if (!modelId) {
throw new Error("modelId не задана");
}
const params = {
name: name,
article_type: articleType
}
const result = await axiosInstance.post(`article/${modelId}/${articleId}/update`, params);
notification.success({
message: 'Успех',
description: 'Статья успешно добавлена',
});
return result
} catch (error) {
console.error('getProgects error', error)
notification.error({
message: 'Ошибка',
description: 'Не удалось добавить статью',
})
}
}