461 lines
11 KiB
TypeScript
461 lines
11 KiB
TypeScript
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
|
|
|
export interface LearnersForHrQueryParams {
|
|
limit: number;
|
|
offset: number;
|
|
search_term?: string;
|
|
status?: string;
|
|
from_date?: string;
|
|
to_date?: string;
|
|
}
|
|
|
|
interface LearnerPrincipalType {
|
|
id: string;
|
|
type_name: string;
|
|
type_code: string;
|
|
display_order: number;
|
|
is_active: boolean;
|
|
}
|
|
|
|
interface LearnerOrganization {
|
|
id: string;
|
|
company_name: string;
|
|
company_phone_number: string;
|
|
phone_country_code: string;
|
|
address: string;
|
|
remark: string;
|
|
notes: string | null;
|
|
joined_date: string;
|
|
is_draft: boolean;
|
|
}
|
|
|
|
export interface LearnerItem {
|
|
id: string;
|
|
first_name: string;
|
|
last_name: string;
|
|
email_address: string;
|
|
phone_country_code: string;
|
|
phone_number: string;
|
|
profile_image_url: string | null;
|
|
joined_date: string;
|
|
is_active: boolean;
|
|
principal_type: LearnerPrincipalType;
|
|
principal_organization: LearnerOrganization;
|
|
}
|
|
|
|
interface LearnersForHrData {
|
|
total_count: number;
|
|
limit: number;
|
|
offset: number;
|
|
items: LearnerItem[];
|
|
}
|
|
|
|
export interface LearnersForHrResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: LearnersForHrData;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
export interface CreateLearnerRequest {
|
|
first_name: string;
|
|
last_name: string;
|
|
email_address: string;
|
|
phone_country_code: string;
|
|
phone_number: string;
|
|
}
|
|
|
|
export interface CreateLearnerResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: LearnerItem;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
export interface BulkCreateLearnersResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: LearnerItem[];
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface ExistsResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: {
|
|
exists: boolean;
|
|
};
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
export interface ProgrammeListQueryParams {
|
|
limit: number;
|
|
offset: number;
|
|
search_term?: string;
|
|
programme_status?: string;
|
|
public_status?: string;
|
|
}
|
|
|
|
interface ProgrammeItem {
|
|
id: string;
|
|
programme_title: string;
|
|
programme_owner_xid: string | null;
|
|
programme_summary: string;
|
|
public_status: string;
|
|
start_date: string;
|
|
end_date: string;
|
|
programme_status: string;
|
|
is_active: boolean;
|
|
created_at: string;
|
|
updated_at: string;
|
|
created_by: string | null;
|
|
updated_by: string | null;
|
|
is_deleted: boolean;
|
|
deleted_at: string | null;
|
|
deleted_by: string | null;
|
|
}
|
|
|
|
interface ProgrammeListResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: ProgrammeItem[];
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface BulkAssignProgrammeRequest {
|
|
principal_xids: string[];
|
|
programme_xids: string[];
|
|
start_date: string;
|
|
end_date: string;
|
|
}
|
|
|
|
interface BulkAssignProgrammeResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: unknown;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
export interface CourseListQueryParams {
|
|
limit: number;
|
|
offset: number;
|
|
search_query?: string;
|
|
course_category?: string[];
|
|
price_range?: string;
|
|
duration_range?: string;
|
|
min_rating?: number;
|
|
sort_by?: string;
|
|
}
|
|
|
|
export interface CourseItem {
|
|
id: string;
|
|
course_name: string;
|
|
course_desc: string;
|
|
thumbnail_img: string | null;
|
|
course_category_xid: string;
|
|
course_category_name: string;
|
|
best_value: number;
|
|
avg_rating: number;
|
|
total_reviews: number;
|
|
retail_type: string;
|
|
price: number;
|
|
is_certificate_available: boolean;
|
|
course_status: string;
|
|
updated_at: string;
|
|
total_duration: number | null;
|
|
no_of_modules: number;
|
|
media_id: string | null;
|
|
media_file_type: string | null;
|
|
media_file_extension: string | null;
|
|
media_file_name: string | null;
|
|
}
|
|
|
|
interface CourseListResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: {
|
|
pagination_info: {
|
|
total_count: number;
|
|
limit: number;
|
|
offset: number;
|
|
applied_filters: {
|
|
status: string | null;
|
|
course_category_xid: string | null;
|
|
content_types_xid: string | null;
|
|
search_query: string | null;
|
|
price_range: string | null;
|
|
duration_range: string | null;
|
|
min_rating: number | null;
|
|
sort_by: string | null;
|
|
};
|
|
};
|
|
items: CourseItem[];
|
|
};
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface BulkAssignCourseRequest {
|
|
principal_xids: string[];
|
|
course_xids: string[];
|
|
start_date: string;
|
|
end_date: string;
|
|
principal_organization_course_link_xid?: string;
|
|
}
|
|
|
|
interface BulkAssignCourseResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: unknown;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface BulkRevokeCourseRequest {
|
|
principal_xids: string[];
|
|
course_xids: string[];
|
|
principal_organization_course_link_xid?: string;
|
|
}
|
|
|
|
interface BulkRevokeCourseResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: unknown;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface AssignedCoursesResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: CourseItem[];
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface LearnerCourseMappingItem {
|
|
id: string;
|
|
principal_xid: string;
|
|
first_name: string;
|
|
last_name: string;
|
|
company_name: string;
|
|
course_xid: string;
|
|
course_name: string;
|
|
course_desc: string;
|
|
is_hr: boolean | null;
|
|
principal_organization_course_link_xid: string | null;
|
|
}
|
|
|
|
interface LearnerCoursesResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: LearnerCourseMappingItem[];
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
interface UpdateLearnerRequest {
|
|
id: string;
|
|
first_name: string;
|
|
last_name: string;
|
|
phone_country_code: string;
|
|
phone_number: string;
|
|
}
|
|
|
|
interface UpdateLearnerResponse {
|
|
success: boolean;
|
|
status: number;
|
|
message: string;
|
|
data: LearnerItem;
|
|
errors: unknown;
|
|
correlation_id: string;
|
|
}
|
|
|
|
const API_BASE_URL = import.meta.env.VITE_API_URL;
|
|
|
|
export const learnersApi = createApi({
|
|
reducerPath: 'learnersApi',
|
|
tagTypes: ['Learners'],
|
|
baseQuery: fetchBaseQuery({
|
|
baseUrl: API_BASE_URL,
|
|
prepareHeaders: (headers) => {
|
|
const token = localStorage.getItem('token');
|
|
if (token) {
|
|
headers.set('authorization', `Bearer ${token}`);
|
|
}
|
|
return headers;
|
|
},
|
|
}),
|
|
endpoints: (builder) => ({
|
|
getLearnersForHr: builder.query<LearnersForHrResponse, LearnersForHrQueryParams>({
|
|
query: (params) => ({
|
|
url: '/hr/learners/learners_for_hr',
|
|
method: 'GET',
|
|
params: {
|
|
limit: params.limit,
|
|
offset: params.offset,
|
|
status: params.status ?? 'all',
|
|
search_term: params.search_term || undefined,
|
|
from_date: params.from_date || undefined,
|
|
to_date: params.to_date || undefined,
|
|
},
|
|
}),
|
|
providesTags: ['Learners'],
|
|
}),
|
|
createLearner: builder.mutation<CreateLearnerResponse, CreateLearnerRequest>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/create',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
bulkCreateLearnersForHr: builder.mutation<
|
|
BulkCreateLearnersResponse,
|
|
CreateLearnerRequest[]
|
|
>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/bulk-create-learners-for-hr',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
checkEmailExists: builder.query<ExistsResponse, string>({
|
|
query: (email) => ({
|
|
url: '/hr/learners/check-email-exists',
|
|
method: 'GET',
|
|
params: { email },
|
|
}),
|
|
}),
|
|
checkMobileExists: builder.query<
|
|
ExistsResponse,
|
|
{ phone_country_code: string; phone_number: string }
|
|
>({
|
|
query: ({ phone_country_code, phone_number }) => ({
|
|
url: '/hr/learners/check-mobile-exists',
|
|
method: 'GET',
|
|
params: { phone_country_code, phone_number },
|
|
}),
|
|
}),
|
|
getProgrammesForHr: builder.query<ProgrammeListResponse, ProgrammeListQueryParams>({
|
|
query: (params) => ({
|
|
url: '/hr/organization/list/assigned-programmes',
|
|
method: 'GET',
|
|
params: {
|
|
limit: params.limit,
|
|
offset: params.offset,
|
|
search_term: params.search_term || undefined,
|
|
programme_status: params.programme_status || undefined,
|
|
public_status: params.public_status || undefined,
|
|
},
|
|
}),
|
|
}),
|
|
bulkAssignProgramme: builder.mutation<
|
|
BulkAssignProgrammeResponse,
|
|
BulkAssignProgrammeRequest
|
|
>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/bulk-assign-programme',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
getCoursesForHr: builder.query<CourseListResponse, CourseListQueryParams>({
|
|
query: (params) => ({
|
|
url: '/hr/programme-course/course/list',
|
|
method: 'GET',
|
|
params: {
|
|
limit: params.limit,
|
|
offset: params.offset,
|
|
search_query: params.search_query || undefined,
|
|
course_category: params.course_category?.length ? params.course_category : undefined,
|
|
price_range: params.price_range || undefined,
|
|
duration_range: params.duration_range || undefined,
|
|
min_rating: params.min_rating ?? undefined,
|
|
sort_by: params.sort_by || undefined,
|
|
},
|
|
}),
|
|
}),
|
|
bulkAssignCourse: builder.mutation<BulkAssignCourseResponse, BulkAssignCourseRequest>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/bulk-assign-course',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
bulkRevokeCourse: builder.mutation<BulkRevokeCourseResponse, BulkRevokeCourseRequest>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/bulk-revoke-course',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
getAssignedCoursesForOrganization: builder.query<
|
|
AssignedCoursesResponse,
|
|
{ limit: number; offset: number; search_query?: string }
|
|
>({
|
|
query: (params) => ({
|
|
url: '/hr/organization/list/assigned-courses',
|
|
method: 'GET',
|
|
params: {
|
|
limit: params.limit,
|
|
offset: params.offset,
|
|
search_query: params.search_query || undefined,
|
|
},
|
|
}),
|
|
}),
|
|
getLearnerCourses: builder.query<LearnerCoursesResponse, string>({
|
|
query: (learnerId) => ({
|
|
url: `/hr/learners/courses/${learnerId}`,
|
|
method: 'GET',
|
|
}),
|
|
providesTags: ['Learners'],
|
|
}),
|
|
updateLearner: builder.mutation<UpdateLearnerResponse, UpdateLearnerRequest>({
|
|
query: (payload) => ({
|
|
url: '/hr/learners/update-learner',
|
|
method: 'POST',
|
|
body: payload,
|
|
}),
|
|
invalidatesTags: ['Learners'],
|
|
}),
|
|
}),
|
|
});
|
|
|
|
export const {
|
|
useGetLearnersForHrQuery,
|
|
useCreateLearnerMutation,
|
|
useBulkCreateLearnersForHrMutation,
|
|
useLazyCheckEmailExistsQuery,
|
|
useLazyCheckMobileExistsQuery,
|
|
useGetProgrammesForHrQuery,
|
|
useBulkAssignProgrammeMutation,
|
|
useGetCoursesForHrQuery,
|
|
useBulkAssignCourseMutation,
|
|
useBulkRevokeCourseMutation,
|
|
useGetAssignedCoursesForOrganizationQuery,
|
|
useGetLearnerCoursesQuery,
|
|
useUpdateLearnerMutation,
|
|
} = learnersApi;
|