-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(work-scheme): set real api call
- Loading branch information
Showing
1 changed file
with
37 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,44 @@ | ||
import { format } from "date-fns"; | ||
|
||
import { NuxtAxiosInstance } from "@nuxtjs/axios"; | ||
|
||
export default class WorkSchemeService { | ||
getWorkScheme(params: { | ||
employeeId: string; | ||
axios: NuxtAxiosInstance; | ||
ApiUrl = "/api/v1"; | ||
|
||
constructor(axios: NuxtAxiosInstance) { | ||
this.axios = axios; | ||
} | ||
|
||
async getWorkScheme(params: { | ||
bridgeUid: string; | ||
startDate: Date; | ||
endDate: Date; | ||
}) { | ||
console.log("retrieve real data from Intracto API with params", params); | ||
const { bridgeUid, startDate, endDate } = params; | ||
|
||
try { | ||
const response = await this.axios.$get<WorkSchemeResponse>( | ||
`${this.ApiUrl}/users/${bridgeUid}/worktime?date_from=${format( | ||
startDate, | ||
"yyyy-MM-dd" | ||
)}&date_to=${format(endDate, "yyyy-MM-dd")}`, | ||
{ | ||
withCredentials: true, | ||
} | ||
); | ||
|
||
return [ | ||
{ | ||
date: "2020-03-08", | ||
theoreticalHours: 8, | ||
absenceHours: 0, | ||
workHours: 8, | ||
holiday: 0, | ||
}, | ||
{ | ||
date: "2020-03-09", | ||
theoreticalHours: 8, | ||
absenceHours: 4, | ||
workHours: 4, | ||
holiday: 0, | ||
}, | ||
{ | ||
date: "2020-03-10", | ||
theoreticalHours: 8, | ||
absenceHours: 0, | ||
workHours: 0, | ||
holiday: 8, | ||
}, | ||
{ | ||
date: "2020-03-11", | ||
theoreticalHours: 8, | ||
absenceHours: 0, | ||
workHours: 8, | ||
holiday: 0, | ||
}, | ||
{ | ||
date: "2020-03-12", | ||
theoreticalHours: 8, | ||
absenceHours: 0, | ||
workHours: 8, | ||
holiday: 0, | ||
}, | ||
{ | ||
date: "2020-03-13", | ||
theoreticalHours: 0, | ||
absenceHours: 0, | ||
workHours: 0, | ||
holiday: 0, | ||
}, | ||
{ | ||
date: "2020-03-14", | ||
theoreticalHours: 0, | ||
absenceHours: 0, | ||
workHours: 0, | ||
holiday: 0, | ||
}, | ||
]; | ||
/* map API response to expected format */ | ||
return response.data.map((ws) => ({ | ||
date: ws.date, | ||
theoreticalHours: ws.theoretical_hours, | ||
absenceHours: ws.absence_hours, | ||
workHours: ws.work_hours, | ||
holiday: ws.holiday, | ||
})); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error("API error", error); | ||
} | ||
} | ||
} |