@omniumretail/shared-resources 0.2.20 → 0.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import { UseQueryOptions } from '@tanstack/react-query';
2
+ import { ResponseList, EmployeesWorklog } from '../../../../interfaces';
3
+ interface EmployeesWithTimekeepingProps extends UseQueryOptions<ResponseList<"EmployeesWorkLog", EmployeesWorklog>> {
4
+ storeId?: string;
5
+ startDate?: number;
6
+ endDate?: number;
7
+ search?: string;
8
+ page?: number;
9
+ records?: number;
10
+ sortBy?: string;
11
+ sortDirection?: string;
12
+ employeeId?: string;
13
+ }
14
+ export declare const useEmployeeTimekeepingDetails: ({ storeId, startDate, endDate, search, employeeId, page, records, sortBy, sortDirection, ...options }: EmployeesWithTimekeepingProps) => import("@tanstack/react-query").UseQueryResult<ResponseList<"EmployeesWorklog", EmployeesWorklog>, unknown>;
15
+ export {};
@@ -0,0 +1,11 @@
1
+ import { UseQueryOptions } from "@tanstack/react-query";
2
+ import { ResponseList, Store } from "../../../../interfaces";
3
+ interface StoreQueryOptions extends UseQueryOptions<ResponseList<'Locations', Store>> {
4
+ page: number;
5
+ records: number;
6
+ sortBy: string;
7
+ sortDirection: string;
8
+ query: string;
9
+ }
10
+ export declare const useStoresQueryHook: ({ page, records, sortBy, sortDirection, query, ...options }: StoreQueryOptions) => import("@tanstack/react-query").UseQueryResult<ResponseList<"Locations", Store>, unknown>;
11
+ export {};
@@ -0,0 +1,2 @@
1
+ import { AttendanceRange } from "../../../../interfaces";
2
+ export declare const postAttendanceRange: () => import("@tanstack/react-query").UseMutationResult<AttendanceRange, unknown, AttendanceRange, unknown>;
@@ -117,6 +117,9 @@ export * from './OSUA/get/vouchers/getGngVoucher.hook';
117
117
  export * from './OSUA/get/vouchers/getSitooVouchers.hook';
118
118
  export * from './OSUA/get/vouchers/getVoucherIntegrationRequestStatus.hook';
119
119
  export * from './OSUA/mutate/postCreateIntegrationRequest.hook';
120
+ export * from './ATIM/BackOffice/get/useEmployeeTimekeepingDetails.hook';
121
+ export * from './ATIM/BackOffice/get/useStoresQueryHook.hook';
122
+ export * from './ATIM/BackOffice/mutate/postAttendanceRange.hook';
120
123
  export * from './Others/useJobTitlesQuery.hook';
121
124
  export * from './Others/useContractStatesQuery.hook';
122
125
  export * from './Others/useApplicationDataQuery.hook';
@@ -0,0 +1,35 @@
1
+ export interface WorkLogDetail {
2
+ Id: string;
3
+ Type: number;
4
+ Date: number;
5
+ }
6
+ export interface Breaks {
7
+ Number: number;
8
+ Time: number;
9
+ }
10
+ export interface WorkDayLog {
11
+ WorkDay: number;
12
+ TimeWorked: number;
13
+ Breaks: Breaks;
14
+ Details: WorkLogDetail[];
15
+ }
16
+ export interface EmployeesWorklog {
17
+ Id: string;
18
+ Code: string;
19
+ Name: string;
20
+ JobTitle: string;
21
+ IsWorking: boolean;
22
+ TimeWorked: number;
23
+ Breaks: Breaks;
24
+ WorkDayLogs: WorkDayLog[];
25
+ }
26
+ export interface Location {
27
+ Id: string;
28
+ Name: string;
29
+ Code: string;
30
+ Status: string;
31
+ }
32
+ export interface UserBackoffice {
33
+ UserId: string;
34
+ FullName: string;
35
+ }
@@ -3,4 +3,5 @@ export interface Configuration {
3
3
  ApiPath: string;
4
4
  token?: string;
5
5
  tokenAuth0?: string;
6
+ basic?: string;
6
7
  }
@@ -21,3 +21,9 @@ export interface Attendance {
21
21
  CreateDate: string;
22
22
  UpdateDate: string;
23
23
  }
24
+ export interface AttendanceRange {
25
+ StoreID: string;
26
+ EmployeeID: string;
27
+ EntryDate: number;
28
+ ExitDate: number;
29
+ }
@@ -52,3 +52,4 @@ export * from './AstsStockInfo';
52
52
  export * from './AstsStock';
53
53
  export * from './UserAuthentication';
54
54
  export * from './OUSA';
55
+ export * from './BackofficeAtim';
@@ -1,6 +1,7 @@
1
1
  import 'whatwg-fetch';
2
2
  export declare const get: <T>(path: string, params?: Record<string, unknown>) => Promise<T>;
3
3
  export declare const getAuth0: <T>(path: string, params?: Record<string, unknown>) => Promise<T>;
4
+ export declare const getBasic: <T>(path: string, params?: Record<string, unknown>) => Promise<T>;
4
5
  export declare const putAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string) => Promise<T>;
5
6
  export declare const patchAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string) => Promise<T>;
6
7
  export declare const postAuth0: <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string) => Promise<T>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/shared-resources",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "private": false,
5
5
  "description": "Shared Components and services or utils to the frontend versions",
6
6
  "main": "dist/bundle.js",
@@ -0,0 +1,38 @@
1
+ import { useQuery , UseQueryOptions} from '@tanstack/react-query';
2
+ import { getDateToUnix } from "../../../../helpers/date-unix.helper";
3
+ import { getAuth0 } from "../../../../services/ApiService";
4
+ import { ResponseList, EmployeesWorklog } from '../../../../interfaces';
5
+
6
+
7
+ interface EmployeesWithTimekeepingProps extends UseQueryOptions<ResponseList<"EmployeesWorkLog", EmployeesWorklog>> {
8
+ storeId?: string;
9
+ startDate?: number;
10
+ endDate?: number;
11
+ search?: string;
12
+ page?: number;
13
+ records?: number;
14
+ sortBy?: string;
15
+ sortDirection?: string;
16
+ employeeId?: string;
17
+
18
+ }
19
+
20
+ export const useEmployeeTimekeepingDetails = ({storeId, startDate, endDate, search, employeeId, page, records, sortBy, sortDirection, ...options}: EmployeesWithTimekeepingProps) => {
21
+ return useQuery(
22
+ ['EMPLOYEES_WITH_TIMEKEEPING', storeId, startDate, endDate, search, page, records, sortBy, sortDirection],
23
+ () => getAuth0<ResponseList<"EmployeesWorklog", EmployeesWorklog>>('/ATIM/EmployeesWorklogDetails', {
24
+ pStoreId: storeId,
25
+ pStartDate: startDate || getDateToUnix(new Date()),
26
+ pEndDate: endDate || getDateToUnix(new Date()),
27
+ pEmployeeId: employeeId,
28
+ pPage: page || 1,
29
+ pRecords: records,
30
+ pSortBy: sortBy,
31
+ pSortDirection: sortDirection,
32
+ pSearch: search
33
+ }),
34
+ {
35
+ keepPreviousData: true,
36
+ }
37
+ );
38
+ }
@@ -0,0 +1,27 @@
1
+ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
2
+ import { get } from "../../../../services";
3
+ import { ResponseList, Store } from "../../../../interfaces";
4
+
5
+ interface StoreQueryOptions extends UseQueryOptions<ResponseList<'Locations', Store>> {
6
+ page: number;
7
+ records: number;
8
+ sortBy: string;
9
+ sortDirection: string;
10
+ query: string;
11
+ }
12
+
13
+ export const useStoresQueryHook = ({page, records, sortBy, sortDirection, query, ...options }:StoreQueryOptions) => {
14
+ return useQuery<ResponseList<'Locations', Store>>(
15
+ ['STORE_QUERY'],
16
+ () => get('/Franchise/Locations', {
17
+ pPage: page,
18
+ pRecords: records,
19
+ pSortBy: sortBy,
20
+ pSortDirection: sortDirection,
21
+ pQuery: query,
22
+ }),
23
+ {
24
+ ...options
25
+ }
26
+ );
27
+ }
@@ -0,0 +1,16 @@
1
+ import { useQueryClient, useMutation } from '@tanstack/react-query';
2
+ import { AttendanceRange } from "../../../../interfaces";
3
+ import { postAuth0} from "../../../../services/ApiService";
4
+
5
+
6
+ export const postAttendanceRange = () => {
7
+ const queryClient = useQueryClient();
8
+ return useMutation<AttendanceRange, unknown, AttendanceRange>((data: AttendanceRange) => {
9
+ return postAuth0('/ATIM/Attendances/Range', undefined, data);
10
+ }, {
11
+ onSuccess: (data: AttendanceRange) => {
12
+ queryClient.setQueryData(
13
+ ['POST_ATTENDANCE'], data);
14
+ },
15
+ });
16
+ }
@@ -1,5 +1,5 @@
1
1
  import { useQuery, UseQueryOptions } from '@tanstack/react-query';
2
- import { get } from "../../../../services/ApiService";
2
+ import { getBasic } from "../../../../services/ApiService";
3
3
  import { SitooVoucher } from '../../../../interfaces';
4
4
 
5
5
  interface GetSitooVouchersProps extends UseQueryOptions<SitooVoucher>{
@@ -10,7 +10,7 @@ export const getSitooVouchers = ({ id, ...options }: GetSitooVouchersProps) => {
10
10
  return useQuery(
11
11
  ['SITOO_VOUCHERS', id],
12
12
 
13
- () => get<SitooVoucher>(`/GNG/GiftCard/SPIGiftCard/giftcards/${id}.json`),
13
+ () => getBasic<SitooVoucher>(`/GNG/GiftCard/SPIGiftCard/giftcards/${id}.json`),
14
14
  {
15
15
  ...options,
16
16
  retry: false,
@@ -157,6 +157,13 @@ export * from './OSUA/get/vouchers/getVoucherIntegrationRequestStatus.hook';
157
157
 
158
158
  export * from './OSUA/mutate/postCreateIntegrationRequest.hook';
159
159
 
160
+ //BackofficeAtim
161
+
162
+ export * from './ATIM/BackOffice/get/useEmployeeTimekeepingDetails.hook';
163
+ export * from './ATIM/BackOffice/get/useStoresQueryHook.hook';
164
+ export * from './ATIM/BackOffice/mutate/postAttendanceRange.hook';
165
+
166
+
160
167
  //Others
161
168
  export * from './Others/useJobTitlesQuery.hook';
162
169
  export * from './Others/useContractStatesQuery.hook';
@@ -0,0 +1,48 @@
1
+ import { Store } from './Store';
2
+
3
+
4
+
5
+ export interface WorkLogDetail {
6
+ Id: string;
7
+ Type: number;
8
+ Date: number;
9
+ }
10
+
11
+ export interface Breaks {
12
+ Number: number;
13
+ Time: number;
14
+ }
15
+
16
+ export interface WorkDayLog {
17
+ WorkDay: number;
18
+ TimeWorked: number;
19
+ Breaks: Breaks;
20
+ Details: WorkLogDetail[];
21
+ }
22
+
23
+ export interface EmployeesWorklog {
24
+ Id: string;
25
+ Code: string;
26
+ Name: string;
27
+ JobTitle: string;
28
+ IsWorking: boolean;
29
+ TimeWorked: number;
30
+ Breaks: Breaks;
31
+ WorkDayLogs: WorkDayLog[];
32
+ }
33
+
34
+
35
+ export interface Location {
36
+ Id: string;
37
+ Name: string;
38
+ Code: string;
39
+ Status: string;
40
+
41
+ }
42
+
43
+ export interface UserBackoffice {
44
+ UserId: string;
45
+ FullName: string;
46
+
47
+
48
+ }
@@ -4,4 +4,5 @@ export interface Configuration {
4
4
  ApiPath: string;
5
5
  token?: string;
6
6
  tokenAuth0?: string;
7
+ basic?: string;
7
8
  }
@@ -30,6 +30,13 @@ export interface Attendance {
30
30
 
31
31
  }
32
32
 
33
+ export interface AttendanceRange {
34
+ StoreID: string;
35
+ EmployeeID: string;
36
+ EntryDate: number;
37
+ ExitDate: number;
38
+ }
39
+
33
40
 
34
41
 
35
42
 
@@ -51,4 +51,5 @@ export * from './GetMonths';
51
51
  export * from './AstsStockInfo';
52
52
  export * from './AstsStock';
53
53
  export * from './UserAuthentication';
54
- export * from './OUSA';
54
+ export * from './OUSA';
55
+ export * from './BackofficeAtim';
@@ -9,6 +9,10 @@ export const getAuth0 = <T>(path: string, params?: Record<string, unknown>): Pro
9
9
  return buildApiRequestForAuth0<T>(`${path}?${buildParams(params || {})}`, 'GET');
10
10
  }
11
11
 
12
+ export const getBasic = <T>(path: string, params?: Record<string, unknown>): Promise<T> => {
13
+ return buildApiRequestForBasic<T>(`${path}?${buildParams(params || {})}`, 'GET');
14
+ }
15
+
12
16
  export const putAuth0 = <T>(path: string, params?: Record<string, unknown>, body?: unknown, bodyType?: string): Promise<T> => {
13
17
  return buildApiRequestForAuth0<T>(`${path}${buildParams(params || {})}`, 'PUT', body, bodyType);
14
18
  }
@@ -128,6 +132,44 @@ const buildApiRequestForAuth0 = <T>(path: string, method = 'GET', data?: unknown
128
132
  });
129
133
  }
130
134
 
135
+ /**
136
+ * Build the api request with auth
137
+ * @param path
138
+ * @param method
139
+ * @param data
140
+ * @returns
141
+ */
142
+ const buildApiRequestForBasic = <T>(path: string, method = 'GET', data?: unknown, bodyType?: string): Promise<T> => {
143
+ const requestUri = buildPath(path);
144
+
145
+ const headers: HeadersInit = {
146
+ Authorization: appConfig.basic ? `Basic ${appConfig.basic}` : undefined,
147
+ };
148
+
149
+ let body: FormData | string | undefined | any;
150
+
151
+ if (['POST', 'PUT', 'PATCH'].includes(method)) {
152
+ if (bodyType === 'formdata') {
153
+ // Não é necessário dar set do contentType porque o fetch faz isso por nós quando usamos o fetch
154
+ body = data;
155
+ } else {
156
+ headers['Content-Type'] = 'application/json';
157
+ body = JSON.stringify(data);
158
+ }
159
+ }
160
+
161
+ return fetch(requestUri, {
162
+ method,
163
+ headers,
164
+ body,
165
+ }).then((response) => {
166
+ if (response.status >= 200 && response.status <= 300) {
167
+ return response.json();
168
+ }
169
+ return response.json().then((data) => Promise.reject(data));
170
+ });
171
+ }
172
+
131
173
  /**
132
174
  * Builds the path to access the api
133
175
  * @param path