161 lines
4.3 KiB
TypeScript
161 lines
4.3 KiB
TypeScript
import axiosClient from '../axios/axios';
|
|
import { API_ROUTES } from '@/constants/apiRoutes';
|
|
import type {
|
|
AssignTicketPayload,
|
|
AssignableTicketUsersResponse,
|
|
AssignableTicketUsersParams,
|
|
CloseTicketPayload,
|
|
RequestTicketExtensionPayload,
|
|
ReviewTicketExtensionPayload,
|
|
SseTokenResponse,
|
|
TicketDetail,
|
|
TicketExtensionRequestsResponse,
|
|
TicketOverviewDetail,
|
|
TicketDefectClassesResponse,
|
|
TicketListParams,
|
|
TicketListResponse,
|
|
} from '@/types';
|
|
|
|
export const ticketService = {
|
|
getTickets: async (
|
|
params?: TicketListParams,
|
|
): Promise<TicketListResponse> => {
|
|
const response = await axiosClient.get<TicketListResponse>(
|
|
API_ROUTES.TICKETS.BASE,
|
|
{
|
|
params: {
|
|
skip: params?.skip ?? 0,
|
|
limit: params?.limit ?? 10,
|
|
chainage_id: params?.chainage_id,
|
|
},
|
|
},
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getTicketOverview: async (
|
|
ticketId: string,
|
|
): Promise<TicketOverviewDetail> => {
|
|
const response = await axiosClient.get<TicketOverviewDetail>(
|
|
API_ROUTES.TICKETS.DETAIL(ticketId),
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getTicketClassDetail: async (
|
|
ticketId: string,
|
|
defectClass: string,
|
|
): Promise<TicketDetail> => {
|
|
const response = await axiosClient.get<TicketDetail>(
|
|
API_ROUTES.TICKETS.CLASS_DETAIL(ticketId, defectClass),
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getTicketDefectClasses: async (
|
|
ticketId: string,
|
|
): Promise<TicketDefectClassesResponse> => {
|
|
const response = await axiosClient.get<TicketDefectClassesResponse>(
|
|
API_ROUTES.TICKETS.DEFECT_CLASSES(ticketId),
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getAssignableUsers: async (
|
|
params?: AssignableTicketUsersParams,
|
|
): Promise<AssignableTicketUsersResponse> => {
|
|
const response = await axiosClient.get<AssignableTicketUsersResponse>(
|
|
API_ROUTES.TICKETS.ASSIGNABLE_USERS,
|
|
{
|
|
params: {
|
|
skip: params?.skip ?? 0,
|
|
limit: params?.limit ?? 20,
|
|
search_term: params?.search_term,
|
|
},
|
|
},
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
assignTicket: async (
|
|
ticketId: string,
|
|
payload: AssignTicketPayload,
|
|
): Promise<TicketDetail> => {
|
|
const response = await axiosClient.post<TicketDetail>(
|
|
API_ROUTES.TICKETS.ASSIGNMENTS(ticketId),
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
requestTicketExtension: async (
|
|
ticketId: string,
|
|
assignmentId: number,
|
|
payload: RequestTicketExtensionPayload,
|
|
): Promise<unknown> => {
|
|
const response = await axiosClient.post<unknown>(
|
|
API_ROUTES.TICKETS.REQUEST_EXTENSION(ticketId, assignmentId),
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getTicketExtensionRequest: async (
|
|
ticketId: string,
|
|
assignmentId: number,
|
|
): Promise<TicketExtensionRequestsResponse> => {
|
|
const response = await axiosClient.get<TicketExtensionRequestsResponse>(
|
|
API_ROUTES.TICKETS.EXTENSION_REQUESTS(ticketId),
|
|
{
|
|
params: { assignment_id: assignmentId },
|
|
},
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
reviewTicketExtension: async (
|
|
ticketId: string,
|
|
assignmentId: number,
|
|
payload: ReviewTicketExtensionPayload,
|
|
): Promise<unknown> => {
|
|
const response = await axiosClient.post<unknown>(
|
|
API_ROUTES.TICKETS.REVIEW_EXTENSION_REQUEST(ticketId, assignmentId),
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
closeTicket: async (
|
|
ticketId: string,
|
|
payload: CloseTicketPayload,
|
|
): Promise<TicketDetail> => {
|
|
const response = await axiosClient.post<TicketDetail>(
|
|
API_ROUTES.TICKETS.CLOSE(ticketId),
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
createTicketEventsToken: async (
|
|
ticketId: string,
|
|
): Promise<SseTokenResponse> => {
|
|
const response = await axiosClient.post<SseTokenResponse>(
|
|
API_ROUTES.TICKETS.DETAIL_EVENTS_TOKEN(ticketId),
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
createTenantTicketEventsToken: async (): Promise<SseTokenResponse> => {
|
|
const response = await axiosClient.post<SseTokenResponse>(
|
|
API_ROUTES.TICKET_EVENTS.TENANT_TOKEN,
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
createUserEventsToken: async (): Promise<SseTokenResponse> => {
|
|
const response = await axiosClient.post<SseTokenResponse>(
|
|
API_ROUTES.TICKET_EVENTS.USER_TOKEN,
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|