narasi-ahli/service/user.ts

159 lines
3.8 KiB
TypeScript

import {
httpGetInterceptor,
httpPostInterceptor,
httpPutInterceptor,
} from "./http-config/http-interceptor-services";
export interface UserData {
id?: number;
username: string;
email: string;
fullname: string;
address: string;
phoneNumber: string;
whatsappNumber: string;
password: string;
dateOfBirth: string;
genderType: "male" | "female";
degree?: string;
userLevelId: number;
userRoleId: number;
}
export interface WorkHistoryData {
userId: number;
companyName: string;
jobTitle: string;
startDate: string;
endDate: string;
}
export interface EducationHistoryData {
userId: number;
schoolName: string;
major: string;
educationLevel: string;
graduationYear: number;
}
export interface UserDetailResponse {
success: boolean;
code: number;
messages: string[];
data: {
id: number;
username: string;
email: string;
fullname: string;
address: string;
phoneNumber: string;
workType: string | null;
genderType: string;
identityType: string | null;
identityGroup: string | null;
identityGroupNumber: string | null;
identityNumber: string | null;
dateOfBirth: string;
lastEducation: string | null;
degree: string | null;
whatsappNumber: string;
lastJobTitle: string | null;
userRoleId: number;
userLevelId: number;
userLevels: any;
keycloakId: string;
statusId: number;
createdById: number;
profilePicturePath: string | null;
tempPassword: string;
isEmailUpdated: boolean;
isActive: boolean;
createdAt: string;
updatedAt: string;
};
}
// Create new user
export async function createUser(userData: UserData) {
const response = await httpPostInterceptor("/users", userData);
return response;
}
// Update existing user
export async function updateUser(id: number, userData: Partial<UserData>) {
const response = await httpPutInterceptor(`/users/${id}`, userData);
return response;
}
// Get user detail
export async function getUserDetail(id: number): Promise<UserDetailResponse> {
const response = await httpGetInterceptor(`/users/detail/${id}`);
return response.data;
}
// Get all users
export async function getAllUsers(data: any) {
const response = await httpGetInterceptor(
`/users?limit=${data?.limit || ""}&page=${data?.page || ""}&userRoleId=${data.userRoleId}`,
);
return response;
}
// Create work history
export async function createWorkHistory(workData: WorkHistoryData) {
const response = await httpPostInterceptor("/work-history", workData);
return response;
}
// Create education history
export async function createEducationHistory(
educationData: EducationHistoryData,
) {
const response = await httpPostInterceptor(
"/education-history",
educationData,
);
return response;
}
// Get user work history
export async function getUserWorkHistory(userId: number) {
const response = await httpGetInterceptor(`/work-history?userId=${userId}`);
return response;
}
// Get user education history
export async function getUserEducationHistory(userId: number) {
const response = await httpGetInterceptor(
`/education-history?userId=${userId}`,
);
return response;
}
export async function getUserResearchJournal(userId: number) {
const response = await httpGetInterceptor(
`/research-journals?userId=${userId}`,
);
return response;
}
export async function getAllExperts(name: string, type: string) {
const response = await httpGetInterceptor(
`/users/experts?name=${name}&type=${type}`,
);
return response;
}
export async function getUserExpert(id: number) {
const response = await httpGetInterceptor(`/user-agent?user_id=${id}`);
return response;
}
export async function saveUserExpert(data: {
agent_id: Number[];
user_id: number;
}) {
const response = await httpPutInterceptor(`/user-agent`, data);
return response;
}