604 lines
16 KiB
TypeScript
604 lines
16 KiB
TypeScript
import { httpPost } from "../http-config/http-base-service";
|
|
import {
|
|
httpDeleteInterceptor,
|
|
httpGetInterceptor,
|
|
httpPostInterceptor,
|
|
httpPutInterceptor,
|
|
} from "../http-config/http-interceptor-service";
|
|
|
|
// Interface for Articles API filters
|
|
export interface ArticleFilters {
|
|
page?: number;
|
|
totalPage?: number;
|
|
title?: string;
|
|
description?: string;
|
|
categoryId?: number;
|
|
category?: string;
|
|
typeId?: number;
|
|
tags?: string;
|
|
createdById?: number;
|
|
statusId?: number;
|
|
isBanner?: boolean;
|
|
isPublish?: boolean;
|
|
isDraft?: boolean;
|
|
startDate?: string;
|
|
endDate?: string;
|
|
}
|
|
|
|
// types/article.ts
|
|
|
|
export interface UpdateArticleData {
|
|
aiArticleId?: number;
|
|
categoryIDs: string;
|
|
createdAt?: string;
|
|
createdById?: number;
|
|
description?: string;
|
|
htmlDescription?: string;
|
|
isDraft: boolean;
|
|
isPublish: boolean;
|
|
slug?: string;
|
|
statusId?: number;
|
|
tags?: string;
|
|
title: string;
|
|
typeId?: number;
|
|
}
|
|
|
|
// Interface for creating new article
|
|
export interface CreateArticleData {
|
|
aiArticleId: number;
|
|
categoryIds: string;
|
|
createdAt: string;
|
|
createdById: number;
|
|
description: string;
|
|
htmlDescription: string;
|
|
isDraft: boolean;
|
|
isPublish: boolean;
|
|
oldId: number;
|
|
slug: string;
|
|
tags: string;
|
|
title: string;
|
|
typeId: number;
|
|
publishedFor: string;
|
|
}
|
|
|
|
// Interface for Article Category
|
|
export interface ArticleCategory {
|
|
id: number;
|
|
title: string;
|
|
description: string;
|
|
thumbnailUrl: string;
|
|
slug: string | null;
|
|
tags: string[];
|
|
thumbnailPath: string | null;
|
|
parentId: number;
|
|
oldCategoryId: number | null;
|
|
createdById: number;
|
|
statusId: number;
|
|
isPublish: boolean;
|
|
publishedAt: string | null;
|
|
isEnabled: boolean | null;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
// export async function listDataAll(
|
|
// isForSelf,
|
|
// isApproval,
|
|
// page,
|
|
// limit,
|
|
// search,
|
|
// fileTypeFilter,
|
|
// statusFilter,
|
|
// startDate,
|
|
// endDate,
|
|
// needApprovalFromLevel
|
|
// ) {
|
|
// const name = search || "";
|
|
// const url = `media/list?title=${name}&enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&isForSelf=${isForSelf}&isApproval=${isApproval}&typeId=${fileTypeFilter}&statusId=${statusFilter}&startDate=${
|
|
// startDate == undefined ? "" : startDate
|
|
// }&endDate=${
|
|
// endDate == undefined ? "" : endDate
|
|
// }&needApprovalFromLevel=${needApprovalFromLevel}`;
|
|
// return httpGetInterceptor({ url });
|
|
// }
|
|
|
|
export async function listDataAll(
|
|
isForSelf: any,
|
|
isApproval: any,
|
|
page: any,
|
|
limit: any,
|
|
search: any,
|
|
fileTypeFilter: any,
|
|
statusFilter: any,
|
|
needApprovalFromLevel: any,
|
|
creator: any,
|
|
source: any,
|
|
startDate: any,
|
|
endDate: any,
|
|
title: string = ""
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${limit}&page=${page}&isForSelf=${isForSelf}&isApproval=${isApproval}&typeId=${fileTypeFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&title=${title}`
|
|
);
|
|
}
|
|
|
|
export async function listDataImage(
|
|
size: any = "",
|
|
page: any = "",
|
|
isForSelf: any = "",
|
|
isApproval: any = "",
|
|
categoryFilter: any = "",
|
|
statusFilter: any = "",
|
|
needApprovalFromLevel: any = "",
|
|
creator: any = "",
|
|
source: any = "",
|
|
startDate: any = "",
|
|
endDate: any = "",
|
|
title: string = "",
|
|
creatorGroup: string = "",
|
|
isInt: boolean = false
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/list?enablePage=1&size=${size}&sortBy=createdAt&sort=desc&page=${page}&typeId=1&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}&needApprovalFromLevel=${needApprovalFromLevel}&isInt=${isInt}`
|
|
);
|
|
}
|
|
|
|
export async function listDataVideo(
|
|
size: any,
|
|
page: any,
|
|
isForSelf: any,
|
|
isApproval: any,
|
|
categoryFilter: any,
|
|
statusFilter: any,
|
|
needApprovalFromLevel: any,
|
|
creator: any,
|
|
source: any,
|
|
startDate: any,
|
|
endDate: any,
|
|
title: string = "",
|
|
creatorGroup: string = ""
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${size}&page=${page}&typeId=2&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}`
|
|
);
|
|
}
|
|
|
|
export async function listDataTeks(
|
|
size: any,
|
|
page: any,
|
|
isForSelf: any,
|
|
isApproval: any,
|
|
categoryFilter: any,
|
|
statusFilter: any,
|
|
needApprovalFromLevel: any,
|
|
creator: any,
|
|
source: any,
|
|
startDate: any,
|
|
endDate: any,
|
|
title: string = "",
|
|
creatorGroup: string = ""
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${size}&page=${page}&typeId=3&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}`
|
|
);
|
|
}
|
|
|
|
export async function listDataAudio(
|
|
size: any,
|
|
page: any,
|
|
isForSelf: any,
|
|
isApproval: any,
|
|
categoryFilter: any,
|
|
statusFilter: any,
|
|
needApprovalFromLevel: any,
|
|
creator: any,
|
|
source: any,
|
|
startDate: any,
|
|
endDate: any,
|
|
title: string = "",
|
|
creatorGroup: string = ""
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/list?enablePage=1&sortBy=createdAt&sort=desc&size=${size}&page=${page}&typeId=4&isForSelf=${isForSelf}&isApproval=${isApproval}&categoryId=${categoryFilter}&statusId=${statusFilter}&needApprovalFromLevel=${needApprovalFromLevel}&creatorUserLevelName=${source}&creatorName=${creator}&startDate=${startDate}&endDate=${endDate}&title=${title}&creatorGroupLevelName=${creatorGroup}`
|
|
);
|
|
}
|
|
|
|
export async function listSPIT(
|
|
size: any,
|
|
page: any,
|
|
title = "",
|
|
contentCreatedDate = "",
|
|
isPublish: any
|
|
) {
|
|
return await httpGetInterceptor(
|
|
`media/spit/pagination?enablePage=1&page=${page}&size=${size}&sort=desc&sortBy=contentTitleId&title=${title}& contentCreatedDate=${contentCreatedDate}&isPublish=${isPublish}`
|
|
);
|
|
}
|
|
|
|
export async function listNulisAI(limit: any, page: any, title: string = "") {
|
|
return await httpGetInterceptor(
|
|
`media/nulis-ai/pagination?enablePage=1&page=${page}&size=${limit}&title=${title}`
|
|
);
|
|
}
|
|
|
|
export async function getTagsBySubCategoryId(subCategory: any) {
|
|
return await httpGetInterceptor(
|
|
`media/tags/list?subCategoryId=${subCategory}`
|
|
);
|
|
}
|
|
|
|
export async function listEnableCategory(type: any) {
|
|
const url = `media/categories/list?enablePage=0&sort=desc&sortBy=id&type=${type}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function listCategory(type: any) {
|
|
const url = `media/categories/list?enablePage=0&sort=desc&sortBy=id&categoryId=${type}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function getTags() {
|
|
const url = "media/tags/list";
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function createMedia(data: any) {
|
|
const url = "media";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function updateArticle(id: number, data: any) {
|
|
const url = `articles/${id}`;
|
|
return httpPutInterceptor(url, data);
|
|
}
|
|
|
|
// New Articles API - Create Article
|
|
export async function createArticle(data: CreateArticleData) {
|
|
const url = "articles";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function uploadThumbnail(id: any, data: any) {
|
|
const url = `media/upload?id=${id}&operation=thumbnail`;
|
|
const headers = {
|
|
"Content-Type": "multipart/form-data",
|
|
};
|
|
return httpPostInterceptor(url, data, headers);
|
|
}
|
|
|
|
// New Articles API - Upload Article Files
|
|
export async function uploadArticleFiles(
|
|
articleId: string | number,
|
|
files: FormData
|
|
) {
|
|
const url = `article-files/${articleId}`;
|
|
const headers = {
|
|
"Content-Type": "multipart/form-data",
|
|
};
|
|
return httpPostInterceptor(url, files, headers);
|
|
}
|
|
|
|
// New Articles API - Upload Article Thumbnail
|
|
export async function uploadArticleThumbnail(
|
|
articleId: string | number,
|
|
thumbnail: FormData
|
|
) {
|
|
const url = `articles/thumbnail/${articleId}`;
|
|
const headers = {
|
|
"Content-Type": "multipart/form-data",
|
|
};
|
|
return httpPostInterceptor(url, thumbnail, headers);
|
|
}
|
|
|
|
// New Articles API - Get Article Categories
|
|
export async function listArticleCategories(
|
|
page: number = 1,
|
|
limit: number = 100
|
|
) {
|
|
const url = `article-categories?page=${page}&limit=${limit}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function detailSPIT(id: any) {
|
|
const url = `media/spit?id=${id}`;
|
|
return httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function convertSPIT(data: any) {
|
|
const url = "media/spit/convert";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function submitApproval(id: string, data: any) {
|
|
const url = `article-approval-flows/articles/${id}/approve`;
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function rejectFiles(data: any) {
|
|
const url = "media/file/rejects";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function publishMedia(id: any) {
|
|
const url = `media/public/publish-to-mabes?id=${id}`;
|
|
return httpPostInterceptor(url);
|
|
}
|
|
|
|
export async function saveContentRewrite(data: any) {
|
|
const url = "media/rewrite";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
export async function saveUserReports(data: any) {
|
|
const url = "public/users/reports";
|
|
return httpPostInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteMedia(data: any) {
|
|
const url = `media`;
|
|
return httpDeleteInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteArticle(id: number) {
|
|
const url = `articles/${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
export async function deleteFile(data: any) {
|
|
const url = "media/file";
|
|
return httpDeleteInterceptor(url, data);
|
|
}
|
|
|
|
export async function deleteArticleFile(id: number) {
|
|
const url = `article-files/${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
|
|
export async function deleteSPIT(id: any) {
|
|
const url = `media/spit?id=${id}`;
|
|
return httpDeleteInterceptor(url);
|
|
}
|
|
|
|
export async function postActivityLog(data: any) {
|
|
const url = `activity`;
|
|
return httpPost(url, data);
|
|
}
|
|
|
|
// New Articles API function with complete filter support
|
|
export async function listArticles(
|
|
page: number = 1,
|
|
totalPage: number = 10,
|
|
title?: string,
|
|
description?: string,
|
|
categoryId?: number,
|
|
category?: string,
|
|
typeId?: number,
|
|
tags?: string,
|
|
createdById?: number,
|
|
statusId?: number,
|
|
isBanner?: boolean,
|
|
isPublish?: boolean,
|
|
isDraft?: boolean,
|
|
startDate?: string,
|
|
endDate?: string
|
|
) {
|
|
let url = `articles?page=${page}&totalPage=${totalPage}`;
|
|
|
|
// Add optional query parameters based on available filters
|
|
if (title) url += `&title=${encodeURIComponent(title)}`;
|
|
if (description) url += `&description=${encodeURIComponent(description)}`;
|
|
if (categoryId !== undefined) url += `&categoryId=${categoryId}`;
|
|
if (category) url += `&category=${encodeURIComponent(category)}`;
|
|
if (typeId !== undefined) url += `&typeId=${typeId}`;
|
|
if (tags) url += `&tags=${encodeURIComponent(tags)}`;
|
|
if (createdById !== undefined) url += `&createdById=${createdById}`;
|
|
if (statusId !== undefined) url += `&statusId=${statusId}`;
|
|
if (isBanner !== undefined) url += `&isBanner=${isBanner}`;
|
|
if (isPublish !== undefined) url += `&isPublish=${isPublish}`;
|
|
if (isDraft !== undefined) url += `&isDraft=${isDraft}`;
|
|
if (startDate) url += `&startDate=${startDate}`;
|
|
if (endDate) url += `&endDate=${endDate}`;
|
|
|
|
return await httpGetInterceptor(url);
|
|
}
|
|
|
|
// Alternative function using interface for better type safety
|
|
export async function listArticlesWithFilters(filters: ArticleFilters) {
|
|
return await listArticles(
|
|
filters.page,
|
|
filters.totalPage,
|
|
filters.title,
|
|
filters.description,
|
|
filters.categoryId,
|
|
filters.category,
|
|
filters.typeId,
|
|
filters.tags,
|
|
filters.createdById,
|
|
filters.statusId,
|
|
filters.isBanner,
|
|
filters.isPublish,
|
|
filters.isDraft,
|
|
filters.startDate,
|
|
filters.endDate
|
|
);
|
|
}
|
|
|
|
// Backward compatible wrapper for listDataTeks with new articles API
|
|
export async function listDataTeksNew(
|
|
size: any,
|
|
page: any,
|
|
isForSelf: any,
|
|
isApproval: any,
|
|
categoryFilter: any,
|
|
statusFilter: any,
|
|
needApprovalFromLevel: any,
|
|
creator: any,
|
|
source: any,
|
|
startDate: any,
|
|
endDate: any,
|
|
title: string = "",
|
|
creatorGroup: string = ""
|
|
) {
|
|
// Convert old parameters to new API format
|
|
const categoryId = categoryFilter ? Number(categoryFilter) : undefined;
|
|
const statusId =
|
|
statusFilter?.length > 0 ? Number(statusFilter[0]) : undefined;
|
|
|
|
return await listArticles(
|
|
page + 1, // API expects 1-based page
|
|
Number(size),
|
|
title,
|
|
undefined, // description
|
|
categoryId,
|
|
undefined, // category name
|
|
3, // typeId for text content
|
|
undefined, // tags
|
|
undefined, // createdById
|
|
statusId,
|
|
undefined, // isBanner
|
|
undefined, // isPublish
|
|
undefined, // isDraft
|
|
startDate,
|
|
endDate
|
|
);
|
|
}
|
|
|
|
// Interface for pending approval data
|
|
export interface PendingApprovalData {
|
|
id: number;
|
|
title: string;
|
|
slug: string;
|
|
description: string;
|
|
categoryName: string;
|
|
authorName: string;
|
|
submittedAt: string;
|
|
currentStep: number;
|
|
totalSteps: number;
|
|
priority: string;
|
|
daysInQueue: number;
|
|
workflowName: string;
|
|
canApprove: boolean;
|
|
estimatedTime: string;
|
|
}
|
|
|
|
export interface PendingApprovalResponse {
|
|
success: boolean;
|
|
code: number;
|
|
messages: string[];
|
|
data: PendingApprovalData[];
|
|
}
|
|
|
|
// Function to fetch pending approval data
|
|
export async function listPendingApproval(
|
|
page: number = 1,
|
|
limit: number = 10,
|
|
typeId?: number
|
|
) {
|
|
const url = `articles/pending-approval?page=${page}&limit=${limit}&typeId=${typeId}`;
|
|
return await httpGetInterceptor(url);
|
|
}
|
|
|
|
// Interface for article file data
|
|
export interface ArticleFileData {
|
|
id: number;
|
|
articleId: number;
|
|
filePath: string;
|
|
fileUrl: string;
|
|
fileName: string;
|
|
fileThumbnail: string | null;
|
|
fileAlt: string;
|
|
widthPixel: number | null;
|
|
heightPixel: number | null;
|
|
size: string;
|
|
downloadCount: number;
|
|
createdById: number;
|
|
statusId: number;
|
|
isPublish: boolean;
|
|
publishedAt: string | null;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
// Interface for article category data
|
|
export interface ArticleCategoryData {
|
|
id: number;
|
|
title: string;
|
|
description: string;
|
|
thumbnailUrl: string;
|
|
slug: string | null;
|
|
tags: string[];
|
|
thumbnailPath: string | null;
|
|
parentId: number;
|
|
oldCategoryId: number | null;
|
|
createdById: number;
|
|
statusId: number;
|
|
isPublish: boolean;
|
|
publishedAt: string | null;
|
|
isEnabled: boolean | null;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
// Interface for article detail data
|
|
export interface ArticleDetailData {
|
|
id: number;
|
|
title: string;
|
|
slug: string;
|
|
description: string;
|
|
htmlDescription: string;
|
|
categoryId: number;
|
|
categoryName: string;
|
|
typeId: number;
|
|
tags: string;
|
|
thumbnailUrl: string;
|
|
pageUrl: string | null;
|
|
createdById: number;
|
|
createdByName: string;
|
|
shareCount: number;
|
|
viewCount: number;
|
|
commentCount: number;
|
|
aiArticleId: number | null;
|
|
oldId: number;
|
|
statusId: number;
|
|
isBanner: boolean;
|
|
isPublish: boolean;
|
|
publishedAt: string | null;
|
|
isActive: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
files: ArticleFileData[];
|
|
categories: ArticleCategoryData[];
|
|
}
|
|
|
|
export interface ArticleDetailResponse {
|
|
success: boolean;
|
|
code: number;
|
|
messages: string[];
|
|
data: ArticleDetailData;
|
|
}
|
|
|
|
// Function to fetch article detail
|
|
export async function getArticleDetail(id: number) {
|
|
const url = `articles/${id}`;
|
|
return await httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function createArticleComment(payload: {
|
|
articleId: number;
|
|
message: string;
|
|
}) {
|
|
const url = `article-comments`;
|
|
return await httpPostInterceptor(url, payload);
|
|
}
|
|
|
|
export async function getArticleComments(articleId: number) {
|
|
const url = `article-comments?articleId=${articleId}`;
|
|
return await httpGetInterceptor(url);
|
|
}
|
|
|
|
export async function deleteArticleComment(id: number) {
|
|
const url = `article-comments/${id}`;
|
|
return await httpDeleteInterceptor(url);
|
|
}
|