Files
SSA-Admin-Panel/src/Redux/Service/manage.aboutus.service.ts
2025-02-12 12:02:54 +05:30

96 lines
1.7 KiB
TypeScript

import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithReauth } from "./apiSlice";
export const aboutUs = createApi({
reducerPath: "aboutUs",
baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
endpoints: (builder) => ({
// 🔹 GET: Fetch all posts
getAboutUs: builder.query<AboutUs[], void>({
query: () => "/about-us",
}),
// 🔹 GET: Fetch a single post by ID
getPostById: builder.query<Post, number>({
query: (id) => `/posts/${id}`,
}),
// 🔹 POST: Create a new post
createPost: builder.mutation<Post, Partial<Post>>({
query: (data) => ({
url: "/posts",
method: "POST",
body: data,
}),
}),
// 🔹 PUT: Update an existing post
updateAboutUs: builder.mutation<UpdateAboutUsResponse, UpdateAboutUsRequest>({
query: ({ id, updatedData }) => ({
url: `/posts/${id}`,
method: "POST",
body: updatedData,
}),
}),
// 🔹 DELETE: Remove a post by ID
deletePost: builder.mutation<{ success: boolean }, number>({
query: (id) => ({
url: `/posts/${id}`,
method: "DELETE",
}),
}),
}),
});
export const {
useGetAboutUsQuery,
useUpdateAboutUsMutation,
useGetPostByIdQuery,
useCreatePostMutation,
useDeletePostMutation
} = aboutUs;
// Define Post type
export type Post = {
id: number;
title: string;
body: string;
};
export type UpdateAboutUsRequest={
id: number; updatedData: string
}
export type UpdateAboutUsResponse={
id: number; updatedData: string
}
export type AboutUs = {
id: number;
language_master_xid: number;
content: string;
is_active: boolean;
};