91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
|
|
import { getCookiesDecrypt } from "@/lib/utils";
|
||
|
|
import { httpPost } from "../http-config/http-base-service";
|
||
|
|
import {
|
||
|
|
httpDeleteInterceptor,
|
||
|
|
httpGetInterceptor,
|
||
|
|
httpPostInterceptor,
|
||
|
|
} from "../http-config/http-interceptor-service";
|
||
|
|
|
||
|
|
interface GetCategoriesParams {
|
||
|
|
UserLevelId?: number;
|
||
|
|
UserLevelNumber?: number;
|
||
|
|
description?: string;
|
||
|
|
isPublish?: boolean;
|
||
|
|
parentId?: number;
|
||
|
|
statusId?: number;
|
||
|
|
title?: string;
|
||
|
|
count?: number;
|
||
|
|
limit?: number;
|
||
|
|
nextPage?: number;
|
||
|
|
page?: number;
|
||
|
|
previousPage?: number;
|
||
|
|
sort?: string;
|
||
|
|
sortBy?: string;
|
||
|
|
totalPage?: number;
|
||
|
|
region?: string; // kalau ada publishedLocation
|
||
|
|
}
|
||
|
|
|
||
|
|
interface CreateCategoryPayload {
|
||
|
|
createdById: number;
|
||
|
|
description: string;
|
||
|
|
oldCategoryId: number;
|
||
|
|
parentId: number;
|
||
|
|
slug: string;
|
||
|
|
statusId: number;
|
||
|
|
title: string;
|
||
|
|
tags: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getCategories(params: GetCategoriesParams) {
|
||
|
|
const query = new URLSearchParams();
|
||
|
|
|
||
|
|
if (params.UserLevelId)
|
||
|
|
query.append("UserLevelId", params.UserLevelId.toString());
|
||
|
|
if (params.UserLevelNumber)
|
||
|
|
query.append("UserLevelNumber", params.UserLevelNumber.toString());
|
||
|
|
if (params.description) query.append("description", params.description);
|
||
|
|
if (params.isPublish !== undefined)
|
||
|
|
query.append("isPublish", String(params.isPublish));
|
||
|
|
if (params.parentId) query.append("parentId", params.parentId.toString());
|
||
|
|
if (params.statusId) query.append("statusId", params.statusId.toString());
|
||
|
|
if (params.title) query.append("title", params.title);
|
||
|
|
if (params.count) query.append("count", params.count.toString());
|
||
|
|
if (params.limit) query.append("limit", params.limit.toString());
|
||
|
|
if (params.nextPage) query.append("nextPage", params.nextPage.toString());
|
||
|
|
if (params.page) query.append("page", params.page.toString());
|
||
|
|
if (params.previousPage)
|
||
|
|
query.append("previousPage", params.previousPage.toString());
|
||
|
|
if (params.sort) query.append("sort", params.sort);
|
||
|
|
if (params.sortBy) query.append("sortBy", params.sortBy);
|
||
|
|
if (params.totalPage) query.append("totalPage", params.totalPage.toString());
|
||
|
|
if (params.region) query.append("publishedLocation", params.region);
|
||
|
|
|
||
|
|
const url = `/article-categories?${query.toString()}`;
|
||
|
|
|
||
|
|
return httpGetInterceptor(url);
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function deleteCategories(id: number) {
|
||
|
|
const clientKey = getCookiesDecrypt("clientKey");
|
||
|
|
const csrfToken = getCookiesDecrypt("csrfToken");
|
||
|
|
const url = `/article-categories/${id}`;
|
||
|
|
|
||
|
|
return httpDeleteInterceptor(url, {
|
||
|
|
headers: {
|
||
|
|
"X-Client-Key": clientKey,
|
||
|
|
"X-Csrf-Token": csrfToken,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function createCategories(data: CreateCategoryPayload) {
|
||
|
|
const url = "/article-categories";
|
||
|
|
|
||
|
|
const headers = {
|
||
|
|
"Content-Type": "application/json",
|
||
|
|
"X-Client-Key": process.env.NEXT_PUBLIC_CLIENT_KEY || "",
|
||
|
|
};
|
||
|
|
|
||
|
|
return httpPostInterceptor(url, data, headers);
|
||
|
|
}
|