Below is a detailed description of the MarianaTek endpoints used, their purposes, and how they are implemented.
### Configuration
The base URL for the MarianaTek API is configured using the `apiConfig` module. The URL includes a placeholder for the tenant identifier, which is dynamically replaced in the `getMarianaTekUrl` method.
private getMarianaTekUrl(tenant: string) {
return apiConfig.marianatek.apiUrl.replace('_tenant_', tenant);
}
### Endpoints
#### 1. Get User Details
**Endpoint:** `/users/self`
**Method:** `getUserDetails`
**Purpose:** Retrieves details about the currently authenticated user.
**Implementation:**
```typescript
getUserDetails(tenant: string, accessToken: string) {
return axios.get(`${this.getMarianaTekUrl(tenant)}/users/self`, {
headers: { Authorization: `Bearer ${accessToken}` },
});
}
```
#### 2. Get Employee Details
**Endpoint:** `/employees?user={userId}&include=pay_rates`
**Method:** `getEmployeeDetails`
**Purpose:** Fetches details about an employee, including their pay rates, based on the user ID.
**Implementation:**
```typescript
getEmployeeDetails(tenant: string, accessToken: string, userId: string) {
return axios.get<GetEmployeeResponse>(
`${this.getMarianaTekUrl(tenant)}/employees?user=${userId}&include=pay_rates`,
{ headers: { Authorization: `Bearer ${accessToken}` } }
);
}
```
#### 3. Get Employee Public Profile
**Endpoint:** `/employee_public_profiles?employee={employeeId}`
**Method:** `getEmployeePublicProfile`
**Purpose:** Retrieves the public profile of an employee using their employee ID.
**Implementation:**
```typescript
getEmployeePublicProfile(tenant: string, accessToken: string, employeeId: string) {
return axios.get<GetEmployeeResponse>(
`${this.getMarianaTekUrl(tenant)}/employee_public_profiles?employee=${employeeId}`,
{ headers: { Authorization: `Bearer ${accessToken}` } }
);
}
```
#### 4. Get Class Session Types
**Endpoint:** `/class_session_types?page={page}&page_size=1000`
**Method:** `getClassSessionTypes`
**Purpose:** Fetches a paginated list of class session types.
**Implementation:**
```typescript
async getClassSessionTypes(tenant: string, accessToken: string) {
let page = 1;
const types: GetClassSessionType[] = [];
while (page) {
const response = await axios.get<GetClassSessionTypesResponse>(
`${this.getMarianaTekUrl(tenant)}/class_session_types?page=${page}&page_size=1000`,
{ headers: { Authorization: `Bearer ${accessToken}` } }
);
types.push(...response.data.data);
if (response.data.meta.pagination.pages === response.data.meta.pagination.page) {
break;
}
page++;
}
return types;
}
```
#### 5. Get Class Session Type
**Endpoint:** `/class_session_types/{classSessionTypeId}`
**Method:** `getClassSessionType`
**Purpose:** Retrieves details of a specific class session type by its ID.
**Implementation:**
```typescript
async getClassSessionType(tenant: string, classSessionTypeId: string) {
const response = await axios.get<GetClassSessionTypeResponse>(
`${this.getMarianaTekUrl(tenant)}/class_session_types/${classSessionTypeId}`
);
return response.data.data;
}
```
#### 6. Get Class Sessions
**Endpoint:** `/class_sessions?{params}`
**Method:** `getClassSessions`
**Purpose:** Fetches a paginated list of class sessions based on various query parameters.
**Implementation:**
```typescript
async getClassSessions(data: GetClassSessionsDto) {
let page = 1;
const sessions: GetClassSession[] = [];
const includedRelations: GetClassSessionsResponse['included'] = [];
while (page) {
const params = new URLSearchParams({
employee_public_profiles: data.remoteEmployeeId,
min_date: data.from,
page_size: '1000',
page: page.toString(),
include: 'class_session_type,location',
});
if (data.to) {
params.append('max_date', data.to);
}
const response = await axios.get<GetClassSessionsResponse>(
`${this.getMarianaTekUrl(data.tenant)}/class_sessions?${params.toString()}`,
{ headers: { Authorization: `Bearer ${data.accessToken}` } }
);
sessions.push(...response.data.data);
includedRelations.push(...(response.data.included ?? []));
if (response.data.meta.pagination.pages === response.data.meta.pagination.page) {
break;
}
page++;
}
return { sessions, includedRelations };
}
```
#### 7. Get Class Session
**Endpoint:** `/class_sessions/{classSessionId}?include=class_session_type,location`
**Method:** `getClassSession`
**Purpose:** Retrieves details of a specific class session, including its type and location.
**Implementation:**
```typescript
async getClassSession(tenant: string, classSessionId: string) {
const response = await axios.get<GetClassSessionResponse>(
`${this.getMarianaTekUrl(tenant)}/class_sessions/${classSessionId}?include=class_session_type,location`
);
return response.data;
}
```
### Summary
The `MarianaTekApi` class utilizes several endpoints from the MarianaTek API to perform various operations such as retrieving user details, employee details, class session types, and class sessions. The methods use the `axios` library to make HTTP GET requests, passing necessary headers and query parameters to fetch the required data.
---