Skip to content

Commit

Permalink
feat(work-scheme): set real api call
Browse files Browse the repository at this point in the history
  • Loading branch information
italoteix committed Jul 14, 2021
1 parent 8e4d735 commit a68b734
Showing 1 changed file with 37 additions and 54 deletions.
91 changes: 37 additions & 54 deletions services/work-scheme-service.ts
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);
}
}
}

0 comments on commit a68b734

Please sign in to comment.