/**
* Generated API client for Employee API
* Based on OpenAPI 3.0 specification
*/
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import { CreateEmployeeDTO, Employee, EmployeeSearchParams, UpdateEmployeeDTO } from "./models.js";
export class EmployeeApi {
private baseURL: string;
private apiKey: string;
constructor(baseURL?: string, apiKey?: string) {
this.baseURL = baseURL || process.env.EMPLOYEE_API_HOST_URL || "https://api.development.myradius.ru/employees";
this.apiKey = apiKey || process.env.EMPLOYEE_API_KEY || "";
}
private getHeaders(): Record<string, string> {
return {
Authorization: this.apiKey,
Accept: "application/json",
"Content-Type": "application/json",
};
}
private async request<T>(config: AxiosRequestConfig): Promise<T> {
const response: AxiosResponse<T> = await axios({
...config,
headers: {
...this.getHeaders(),
...config.headers,
},
});
return response.data;
}
/**
* Create employee
* POST /
*/
async createEmployee(createEmployeeDTO: CreateEmployeeDTO): Promise<Employee> {
return this.request<Employee>({
method: "POST",
url: this.baseURL,
data: createEmployeeDTO,
});
}
/**
* Search employees
* GET /search
*/
async searchEmployees(params: EmployeeSearchParams): Promise<Employee[]> {
const queryParams = new URLSearchParams();
if (params.lastName) queryParams.append("lastName", params.lastName);
if (params.firstName) queryParams.append("firstName", params.firstName);
if (params.email) queryParams.append("email", params.email);
return this.request<Employee[]>({
method: "GET",
url: `${this.baseURL}/search?${queryParams.toString()}`,
});
}
/**
* Get employee by ID
* GET /{id}
*/
async getEmployee(id: string): Promise<Employee> {
return this.request<Employee>({
method: "GET",
url: `${this.baseURL}/${id}`,
});
}
/**
* Update employee
* PUT /{id}
*/
async updateEmployee(id: string, updateEmployeeDTO: UpdateEmployeeDTO): Promise<Employee> {
return this.request<Employee>({
method: "PUT",
url: `${this.baseURL}/${id}`,
data: updateEmployeeDTO,
});
}
/**
* Delete employee
* DELETE /{id}
*/
async deleteEmployee(id: string): Promise<void> {
return this.request<void>({
method: "DELETE",
url: `${this.baseURL}/${id}`,
});
}
}
export default EmployeeApi;