rotacloud 1.1.1 → 1.2.0
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.
- package/dist/cjs/interfaces/index.d.ts +1 -0
- package/dist/cjs/interfaces/index.js +1 -0
- package/dist/cjs/interfaces/query-params/index.d.ts +0 -1
- package/dist/cjs/interfaces/query-params/index.js +0 -1
- package/dist/cjs/interfaces/terminal.interface.d.ts +1 -0
- package/dist/cjs/interfaces/time-zone.interface.d.ts +7 -0
- package/dist/cjs/rotacloud.d.ts +2 -1
- package/dist/cjs/rotacloud.js +1 -0
- package/dist/cjs/services/accounts.service.d.ts +26 -7
- package/dist/cjs/services/accounts.service.js +10 -20
- package/dist/cjs/services/attendance.service.d.ts +30 -11
- package/dist/cjs/services/attendance.service.js +16 -26
- package/dist/cjs/services/auth.service.js +1 -3
- package/dist/cjs/services/availability.service.d.ts +3 -3
- package/dist/cjs/services/availability.service.js +8 -18
- package/dist/cjs/services/daily-budgets.service.d.ts +19 -7
- package/dist/cjs/services/daily-budgets.service.js +12 -22
- package/dist/cjs/services/daily-revenue.service.d.ts +18 -6
- package/dist/cjs/services/daily-revenue.service.js +11 -21
- package/dist/cjs/services/day-notes.service.d.ts +27 -8
- package/dist/cjs/services/day-notes.service.js +15 -25
- package/dist/cjs/services/days-off.service.d.ts +17 -5
- package/dist/cjs/services/days-off.service.js +13 -23
- package/dist/cjs/services/groups.service.d.ts +27 -8
- package/dist/cjs/services/groups.service.js +12 -22
- package/dist/cjs/services/index.d.ts +1 -0
- package/dist/cjs/services/index.js +1 -0
- package/dist/cjs/services/leave-embargoes.service.d.ts +27 -8
- package/dist/cjs/services/leave-embargoes.service.js +16 -26
- package/dist/cjs/services/leave-request.service.d.ts +27 -8
- package/dist/cjs/services/leave-request.service.js +15 -25
- package/dist/cjs/services/leave.service.d.ts +28 -10
- package/dist/cjs/services/leave.service.js +13 -46
- package/dist/cjs/services/locations.service.d.ts +27 -8
- package/dist/cjs/services/locations.service.js +16 -26
- package/dist/cjs/services/pins.service.d.ts +12 -5
- package/dist/cjs/services/pins.service.js +1 -1
- package/dist/cjs/services/roles.service.d.ts +27 -8
- package/dist/cjs/services/roles.service.js +16 -26
- package/dist/cjs/services/service.d.ts +12 -3
- package/dist/cjs/services/service.js +1 -2
- package/dist/cjs/services/settings.service.d.ts +1 -1
- package/dist/cjs/services/settings.service.js +1 -1
- package/dist/cjs/services/shifts.service.d.ts +30 -11
- package/dist/cjs/services/shifts.service.js +21 -31
- package/dist/cjs/services/terminals-active.service.d.ts +20 -8
- package/dist/cjs/services/terminals-active.service.js +16 -26
- package/dist/cjs/services/terminals.service.d.ts +27 -8
- package/dist/cjs/services/terminals.service.js +13 -23
- package/dist/cjs/services/time-zone.service.d.ts +14 -0
- package/dist/cjs/services/time-zone.service.js +82 -0
- package/dist/cjs/services/toil-accruals.service.d.ts +4 -4
- package/dist/cjs/services/toil-accruals.service.js +12 -22
- package/dist/cjs/services/toil-allowance.service.d.ts +3 -3
- package/dist/cjs/services/toil-allowance.service.js +9 -19
- package/dist/cjs/services/users-clock-in.service.d.ts +22 -10
- package/dist/cjs/services/users-clock-in.service.js +5 -5
- package/dist/cjs/services/users.service.d.ts +28 -9
- package/dist/cjs/services/users.service.js +16 -26
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/interfaces/index.d.ts +1 -0
- package/dist/mjs/interfaces/index.js +1 -0
- package/dist/mjs/interfaces/query-params/index.d.ts +0 -1
- package/dist/mjs/interfaces/query-params/index.js +0 -1
- package/dist/mjs/interfaces/terminal.interface.d.ts +1 -0
- package/dist/mjs/interfaces/time-zone.interface.d.ts +7 -0
- package/dist/mjs/rotacloud.d.ts +2 -1
- package/dist/mjs/rotacloud.js +2 -1
- package/dist/mjs/services/accounts.service.d.ts +26 -7
- package/dist/mjs/services/accounts.service.js +2 -4
- package/dist/mjs/services/attendance.service.d.ts +30 -11
- package/dist/mjs/services/attendance.service.js +8 -10
- package/dist/mjs/services/auth.service.js +1 -3
- package/dist/mjs/services/availability.service.d.ts +3 -3
- package/dist/mjs/services/availability.service.js +3 -5
- package/dist/mjs/services/daily-budgets.service.d.ts +19 -7
- package/dist/mjs/services/daily-budgets.service.js +4 -6
- package/dist/mjs/services/daily-revenue.service.d.ts +18 -6
- package/dist/mjs/services/daily-revenue.service.js +3 -5
- package/dist/mjs/services/day-notes.service.d.ts +27 -8
- package/dist/mjs/services/day-notes.service.js +7 -9
- package/dist/mjs/services/days-off.service.d.ts +17 -5
- package/dist/mjs/services/days-off.service.js +5 -7
- package/dist/mjs/services/groups.service.d.ts +27 -8
- package/dist/mjs/services/groups.service.js +4 -6
- package/dist/mjs/services/index.d.ts +1 -0
- package/dist/mjs/services/index.js +1 -0
- package/dist/mjs/services/leave-embargoes.service.d.ts +27 -8
- package/dist/mjs/services/leave-embargoes.service.js +8 -10
- package/dist/mjs/services/leave-request.service.d.ts +27 -8
- package/dist/mjs/services/leave-request.service.js +7 -9
- package/dist/mjs/services/leave.service.d.ts +28 -10
- package/dist/mjs/services/leave.service.js +5 -12
- package/dist/mjs/services/locations.service.d.ts +27 -8
- package/dist/mjs/services/locations.service.js +8 -10
- package/dist/mjs/services/pins.service.d.ts +12 -5
- package/dist/mjs/services/pins.service.js +1 -1
- package/dist/mjs/services/roles.service.d.ts +27 -8
- package/dist/mjs/services/roles.service.js +8 -10
- package/dist/mjs/services/service.d.ts +12 -3
- package/dist/mjs/services/service.js +0 -2
- package/dist/mjs/services/settings.service.d.ts +1 -1
- package/dist/mjs/services/settings.service.js +1 -1
- package/dist/mjs/services/shifts.service.d.ts +30 -11
- package/dist/mjs/services/shifts.service.js +13 -15
- package/dist/mjs/services/terminals-active.service.d.ts +20 -8
- package/dist/mjs/services/terminals-active.service.js +8 -10
- package/dist/mjs/services/terminals.service.d.ts +27 -8
- package/dist/mjs/services/terminals.service.js +5 -7
- package/dist/mjs/services/time-zone.service.d.ts +14 -0
- package/dist/mjs/services/time-zone.service.js +25 -0
- package/dist/mjs/services/toil-accruals.service.d.ts +4 -4
- package/dist/mjs/services/toil-accruals.service.js +4 -6
- package/dist/mjs/services/toil-allowance.service.d.ts +3 -3
- package/dist/mjs/services/toil-allowance.service.js +1 -3
- package/dist/mjs/services/users-clock-in.service.d.ts +22 -10
- package/dist/mjs/services/users-clock-in.service.js +5 -5
- package/dist/mjs/services/users.service.d.ts +28 -9
- package/dist/mjs/services/users.service.js +8 -10
- package/dist/mjs/version.js +1 -1
- package/package.json +1 -1
- package/src/interfaces/index.ts +1 -0
- package/src/interfaces/query-params/index.ts +0 -1
- package/src/interfaces/terminal.interface.ts +1 -0
- package/src/interfaces/time-zone.interface.ts +7 -0
- package/src/rotacloud.ts +2 -0
- package/src/services/accounts.service.ts +30 -14
- package/src/services/attendance.service.ts +57 -28
- package/src/services/auth.service.ts +1 -3
- package/src/services/availability.service.ts +14 -13
- package/src/services/daily-budgets.service.ts +41 -20
- package/src/services/daily-revenue.service.ts +37 -19
- package/src/services/day-notes.service.ts +51 -25
- package/src/services/days-off.service.ts +46 -25
- package/src/services/groups.service.ts +40 -20
- package/src/services/index.ts +1 -0
- package/src/services/leave-embargoes.service.ts +54 -25
- package/src/services/leave-request.service.ts +53 -24
- package/src/services/leave.service.ts +41 -27
- package/src/services/locations.service.ts +54 -25
- package/src/services/pins.service.ts +11 -6
- package/src/services/roles.service.ts +49 -25
- package/src/services/service.ts +35 -9
- package/src/services/settings.service.ts +2 -2
- package/src/services/shifts.service.ts +62 -36
- package/src/services/terminals-active.service.ts +36 -23
- package/src/services/terminals.service.ts +36 -18
- package/src/services/time-zone.service.ts +34 -0
- package/src/services/toil-accruals.service.ts +9 -11
- package/src/services/toil-allowance.service.ts +3 -5
- package/src/services/users-clock-in.service.ts +30 -16
- package/src/services/users.service.ts +49 -26
- package/src/version.ts +1 -1
- package/dist/cjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
- package/dist/mjs/interfaces/query-params/internal-query-params.interface.d.ts +0 -5
- package/src/interfaces/query-params/internal-query-params.interface.ts +0 -5
- /package/dist/cjs/interfaces/{query-params/internal-query-params.interface.js → time-zone.interface.js} +0 -0
- /package/dist/mjs/interfaces/{query-params/internal-query-params.interface.js → time-zone.interface.js} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { Location } from '../interfaces/index.js';
|
|
3
|
-
import { Service, Options, RequirementsOf } from './index.js';
|
|
3
|
+
import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
|
|
4
4
|
|
|
5
5
|
import { LocationsQueryParams } from '../interfaces/query-params/locations-query-params.interface.js';
|
|
6
6
|
|
|
7
7
|
type RequiredProps = 'name';
|
|
8
8
|
|
|
9
|
-
export class LocationsService extends Service {
|
|
9
|
+
export class LocationsService extends Service<Location> {
|
|
10
10
|
private apiPath = '/locations';
|
|
11
11
|
|
|
12
12
|
create(data: RequirementsOf<Location, RequiredProps>): Promise<Location>;
|
|
@@ -17,27 +17,44 @@ export class LocationsService extends Service {
|
|
|
17
17
|
create(data: RequirementsOf<Location, RequiredProps>, options: Options): Promise<Location>;
|
|
18
18
|
create(data: RequirementsOf<Location, RequiredProps>, options?: Options) {
|
|
19
19
|
return super
|
|
20
|
-
.fetch<Location>({ url: `${this.apiPath}`, data, method: 'POST' })
|
|
21
|
-
.then((res) =>
|
|
20
|
+
.fetch<Location>({ url: `${this.apiPath}`, data, method: 'POST' }, options)
|
|
21
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
get(id: number): Promise<Location>;
|
|
25
|
-
get
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
get<F extends keyof Location>(
|
|
26
|
+
id: number,
|
|
27
|
+
options: { fields: F[]; rawResponse: true } & OptionsExtended<Location>,
|
|
28
|
+
): Promise<AxiosResponse<Pick<Location, F>>>;
|
|
29
|
+
get<F extends keyof Location>(
|
|
30
|
+
id: number,
|
|
31
|
+
options: { fields: F[] } & OptionsExtended<Location>,
|
|
32
|
+
): Promise<Pick<Location, F>>;
|
|
33
|
+
get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Location>>;
|
|
34
|
+
get(id: number, options?: OptionsExtended<Location>): Promise<Location>;
|
|
35
|
+
get(id: number, options?: OptionsExtended<Location>) {
|
|
28
36
|
return super
|
|
29
37
|
.fetch<Location>({ url: `${this.apiPath}/${id}` }, options)
|
|
30
|
-
.then((res) =>
|
|
38
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
41
|
+
list(query?: LocationsQueryParams): AsyncGenerator<Location>;
|
|
42
|
+
list<F extends keyof Location>(
|
|
43
|
+
query: LocationsQueryParams,
|
|
44
|
+
options: { fields: F[] } & OptionsExtended<Location>,
|
|
45
|
+
): AsyncGenerator<Pick<Location, F>>;
|
|
46
|
+
list(query?: LocationsQueryParams, options?: OptionsExtended<Location>): AsyncGenerator<Location>;
|
|
47
|
+
async *list(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
|
|
48
|
+
yield* super.iterator({ url: this.apiPath, params: query }, options);
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
listAll(query?: LocationsQueryParams
|
|
40
|
-
|
|
51
|
+
listAll(query?: LocationsQueryParams): Promise<Location[]>;
|
|
52
|
+
listAll<F extends keyof Location>(
|
|
53
|
+
query: LocationsQueryParams,
|
|
54
|
+
options: { fields: F[] } & OptionsExtended<Location>,
|
|
55
|
+
): Promise<Pick<Location, F>[]>;
|
|
56
|
+
listAll(query?: LocationsQueryParams, options?: OptionsExtended<Location>): Promise<Location[]>;
|
|
57
|
+
async listAll(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
|
|
41
58
|
const locations = [] as Location[];
|
|
42
59
|
for await (const location of this.list(query, options)) {
|
|
43
60
|
locations.push(location);
|
|
@@ -45,8 +62,17 @@ export class LocationsService extends Service {
|
|
|
45
62
|
return locations;
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
listByPage(query?: LocationsQueryParams
|
|
49
|
-
|
|
65
|
+
listByPage(query?: LocationsQueryParams): AsyncGenerator<AxiosResponse<Location[]>>;
|
|
66
|
+
listByPage<F extends keyof Location>(
|
|
67
|
+
query: LocationsQueryParams,
|
|
68
|
+
options: { fields: F[] } & OptionsExtended<Location>,
|
|
69
|
+
): AsyncGenerator<AxiosResponse<Pick<Location, F>[]>>;
|
|
70
|
+
listByPage(
|
|
71
|
+
query: LocationsQueryParams,
|
|
72
|
+
options?: OptionsExtended<Location>,
|
|
73
|
+
): AsyncGenerator<AxiosResponse<Location[]>>;
|
|
74
|
+
listByPage(query?: LocationsQueryParams, options?: OptionsExtended<Location>) {
|
|
75
|
+
return super.iterator({ url: this.apiPath, params: query }, options).byPage();
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
update(id: number, data: Partial<Location>): Promise<Location>;
|
|
@@ -58,20 +84,23 @@ export class LocationsService extends Service {
|
|
|
58
84
|
update(id: number, data: Partial<Location>, options: Options): Promise<Location>;
|
|
59
85
|
update(id: number, data: Partial<Location>, options?: Options) {
|
|
60
86
|
return super
|
|
61
|
-
.fetch<Location>(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
87
|
+
.fetch<Location>(
|
|
88
|
+
{
|
|
89
|
+
url: `${this.apiPath}/${id}`,
|
|
90
|
+
data,
|
|
91
|
+
method: 'POST',
|
|
92
|
+
},
|
|
93
|
+
options,
|
|
94
|
+
)
|
|
95
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
67
96
|
}
|
|
68
97
|
|
|
69
98
|
delete(id: number): Promise<number>;
|
|
70
|
-
delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<
|
|
99
|
+
delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
|
|
71
100
|
delete(id: number, options: Options): Promise<number>;
|
|
72
101
|
delete(id: number, options?: Options) {
|
|
73
102
|
return super
|
|
74
|
-
.fetch<
|
|
75
|
-
.then((res) =>
|
|
103
|
+
.fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' }, options)
|
|
104
|
+
.then((res) => (options?.rawResponse ? res : res.status));
|
|
76
105
|
}
|
|
77
106
|
}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { Pin } from '../interfaces/index.js';
|
|
3
|
-
import { Service, Options } from './index.js';
|
|
3
|
+
import { Service, Options, OptionsExtended } from './index.js';
|
|
4
4
|
|
|
5
|
-
export class PinsService extends Service {
|
|
5
|
+
export class PinsService extends Service<Pin> {
|
|
6
6
|
private apiPath = '/pins';
|
|
7
7
|
|
|
8
8
|
get(id: string): Promise<Pin>;
|
|
9
|
-
get
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
get<F extends keyof Pin>(
|
|
10
|
+
id: string,
|
|
11
|
+
options: { fields: F[]; rawResponse: true } & OptionsExtended<Pin>,
|
|
12
|
+
): Promise<AxiosResponse<Pick<Pin, F>>>;
|
|
13
|
+
get<F extends keyof Pin>(id: string, options: { fields: F[] } & OptionsExtended<Pin>): Promise<Pick<Pin, F>>;
|
|
14
|
+
get(id: string, options: { rawResponse: true } & Options): Promise<AxiosResponse<Pin>>;
|
|
15
|
+
get(id: string, options?: OptionsExtended<Pin>): Promise<Pin>;
|
|
16
|
+
get(id: string, options?: OptionsExtended<Pin>) {
|
|
12
17
|
return super
|
|
13
18
|
.fetch<Pin>({ url: `${this.apiPath}/${id}` }, options)
|
|
14
|
-
.then((res) =>
|
|
19
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
15
20
|
}
|
|
16
21
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { Role } from '../interfaces/index.js';
|
|
3
|
-
import { Service, Options, RequirementsOf } from './index.js';
|
|
3
|
+
import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
|
|
4
4
|
|
|
5
5
|
import { RolesQueryParams } from '../interfaces/query-params/roles-query-params.interface.js';
|
|
6
6
|
|
|
7
7
|
type RequiredProps = 'name';
|
|
8
8
|
|
|
9
|
-
export class RolesService extends Service {
|
|
9
|
+
export class RolesService extends Service<Role> {
|
|
10
10
|
private apiPath = '/roles';
|
|
11
11
|
|
|
12
12
|
create(data: RequirementsOf<Role, RequiredProps>): Promise<Role>;
|
|
@@ -17,27 +17,41 @@ export class RolesService extends Service {
|
|
|
17
17
|
create(data: RequirementsOf<Role, RequiredProps>, options: Options): Promise<Role>;
|
|
18
18
|
create(data: RequirementsOf<Role, RequiredProps>, options?: Options) {
|
|
19
19
|
return super
|
|
20
|
-
.fetch<Role>({ url: this.apiPath, data, method: 'POST' })
|
|
21
|
-
.then((res) =>
|
|
20
|
+
.fetch<Role>({ url: this.apiPath, data, method: 'POST' }, options)
|
|
21
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
get(id: number): Promise<Role>;
|
|
25
|
-
get
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
get<F extends keyof Role>(
|
|
26
|
+
id: number,
|
|
27
|
+
options: { fields: F[]; rawResponse: true } & OptionsExtended<Role>,
|
|
28
|
+
): Promise<AxiosResponse<Pick<Role, F>>>;
|
|
29
|
+
get<F extends keyof Role>(id: number, options: { fields: F[] } & OptionsExtended<Role>): Promise<Pick<Role, F>>;
|
|
30
|
+
get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Role>>;
|
|
31
|
+
get(id: number, options?: OptionsExtended<Role>): Promise<Role>;
|
|
32
|
+
get(id: number, options?: OptionsExtended<Role>) {
|
|
28
33
|
return super
|
|
29
34
|
.fetch<Role>({ url: `${this.apiPath}/${id}` }, options)
|
|
30
|
-
.then((res) =>
|
|
35
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
list(query?: RolesQueryParams): AsyncGenerator<Role>;
|
|
39
|
+
list<F extends keyof Role>(
|
|
40
|
+
query: RolesQueryParams,
|
|
41
|
+
options: { fields: F[] } & OptionsExtended<Role>,
|
|
42
|
+
): AsyncGenerator<Pick<Role, F>>;
|
|
43
|
+
list(query?: RolesQueryParams, options?: OptionsExtended<Role>): AsyncGenerator<Role>;
|
|
44
|
+
async *list(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
|
|
45
|
+
yield* super.iterator({ url: this.apiPath, params: query }, options);
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
listAll(query?: RolesQueryParams
|
|
40
|
-
|
|
48
|
+
listAll(query?: RolesQueryParams): Promise<Role[]>;
|
|
49
|
+
listAll<F extends keyof Role>(
|
|
50
|
+
query: RolesQueryParams,
|
|
51
|
+
options: { fields: F[] } & OptionsExtended<Role>,
|
|
52
|
+
): Promise<Pick<Role, F>[]>;
|
|
53
|
+
listAll(query?: RolesQueryParams, options?: OptionsExtended<Role>): Promise<Role[]>;
|
|
54
|
+
async listAll(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
|
|
41
55
|
const roles = [] as Role[];
|
|
42
56
|
for await (const role of this.list(query, options)) {
|
|
43
57
|
roles.push(role);
|
|
@@ -45,28 +59,38 @@ export class RolesService extends Service {
|
|
|
45
59
|
return roles;
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
listByPage(query?: RolesQueryParams
|
|
49
|
-
|
|
62
|
+
listByPage(query?: RolesQueryParams): AsyncGenerator<AxiosResponse<Role[]>>;
|
|
63
|
+
listByPage<F extends keyof Role>(
|
|
64
|
+
query: RolesQueryParams,
|
|
65
|
+
options: { fields: F[] } & OptionsExtended<Role>,
|
|
66
|
+
): AsyncGenerator<AxiosResponse<Pick<Role, F>[]>>;
|
|
67
|
+
listByPage(query?: RolesQueryParams, options?: OptionsExtended<Role>): AsyncGenerator<AxiosResponse<Role[]>>;
|
|
68
|
+
listByPage(query?: RolesQueryParams, options?: OptionsExtended<Role>) {
|
|
69
|
+
return super.iterator({ url: this.apiPath, params: query }, options).byPage();
|
|
50
70
|
}
|
|
71
|
+
|
|
51
72
|
update(id: number, data: Partial<Role>): Promise<Role>;
|
|
52
73
|
update(id: number, data: Partial<Role>, options: { rawResponse: true } & Options): Promise<AxiosResponse<Role, any>>;
|
|
53
74
|
update(id: number, data: Partial<Role>, options: Options): Promise<Role>;
|
|
54
75
|
update(id: number, data: Partial<Role>, options?: Options) {
|
|
55
76
|
return super
|
|
56
|
-
.fetch<Role>(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
.fetch<Role>(
|
|
78
|
+
{
|
|
79
|
+
url: `${this.apiPath}/${id}`,
|
|
80
|
+
data,
|
|
81
|
+
method: 'POST',
|
|
82
|
+
},
|
|
83
|
+
options,
|
|
84
|
+
)
|
|
85
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
62
86
|
}
|
|
63
87
|
|
|
64
88
|
delete(id: number): Promise<number>;
|
|
65
|
-
delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<
|
|
89
|
+
delete(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
|
|
66
90
|
delete(id: number, options: Options): Promise<number>;
|
|
67
91
|
delete(id: number, options?: Options) {
|
|
68
92
|
return super
|
|
69
|
-
.fetch<
|
|
70
|
-
.then((res) =>
|
|
93
|
+
.fetch<void>({ url: `${this.apiPath}/${id}`, method: 'DELETE' }, options)
|
|
94
|
+
.then((res) => (options?.rawResponse ? res : res.status));
|
|
71
95
|
}
|
|
72
96
|
}
|
package/src/services/service.ts
CHANGED
|
@@ -29,13 +29,15 @@ export type RetryOptions =
|
|
|
29
29
|
|
|
30
30
|
export interface Options {
|
|
31
31
|
rawResponse?: boolean;
|
|
32
|
-
expand?: string[];
|
|
33
|
-
fields?: string[];
|
|
34
32
|
limit?: number;
|
|
35
33
|
offset?: number;
|
|
36
34
|
dryRun?: boolean;
|
|
37
35
|
}
|
|
38
36
|
|
|
37
|
+
export type OptionsExtended<T = unknown> = Options & {
|
|
38
|
+
fields?: (keyof T)[];
|
|
39
|
+
};
|
|
40
|
+
|
|
39
41
|
const DEFAULT_RETRIES = 3;
|
|
40
42
|
const DEFAULT_RETRY_DELAY = 2000;
|
|
41
43
|
|
|
@@ -51,7 +53,7 @@ const DEFAULT_RETRY_STRATEGY_OPTIONS: Record<RetryStrategy, RetryOptions> = {
|
|
|
51
53
|
},
|
|
52
54
|
};
|
|
53
55
|
|
|
54
|
-
type ParameterPrimitive = string | boolean | number | null;
|
|
56
|
+
type ParameterPrimitive = string | boolean | number | null | symbol;
|
|
55
57
|
type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
|
|
56
58
|
|
|
57
59
|
export abstract class Service<ApiResponse = any> {
|
|
@@ -65,7 +67,7 @@ export abstract class Service<ApiResponse = any> {
|
|
|
65
67
|
const parsedError = this.parseClientError(error);
|
|
66
68
|
|
|
67
69
|
return Promise.reject(parsedError);
|
|
68
|
-
}
|
|
70
|
+
},
|
|
69
71
|
);
|
|
70
72
|
return client;
|
|
71
73
|
}
|
|
@@ -87,9 +89,11 @@ export abstract class Service<ApiResponse = any> {
|
|
|
87
89
|
return endpoint === '/leave_requests';
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
private buildQueryParams
|
|
92
|
+
private buildQueryParams<T = ApiResponse>(
|
|
93
|
+
options?: OptionsExtended<T>,
|
|
94
|
+
extraParams?: Record<string, ParameterValue>,
|
|
95
|
+
) {
|
|
91
96
|
const queryParams: Record<string, ParameterValue> = {
|
|
92
|
-
expand: options?.expand,
|
|
93
97
|
fields: options?.fields,
|
|
94
98
|
limit: options?.limit,
|
|
95
99
|
offset: options?.offset,
|
|
@@ -109,7 +113,21 @@ export abstract class Service<ApiResponse = any> {
|
|
|
109
113
|
return new URLSearchParams(reducedParams);
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig
|
|
116
|
+
fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig): Promise<AxiosResponse<T>>;
|
|
117
|
+
fetch<T = ApiResponse>(
|
|
118
|
+
reqConfig: AxiosRequestConfig,
|
|
119
|
+
options: { fields: Required<OptionsExtended<T>>['fields'] } & OptionsExtended<T>,
|
|
120
|
+
): Promise<AxiosResponse<Pick<T, (typeof options)['fields'][number]>>>;
|
|
121
|
+
fetch<T extends unknown[] = ApiResponse[], E = T[number]>(
|
|
122
|
+
reqConfig: AxiosRequestConfig,
|
|
123
|
+
options: { fields: Required<OptionsExtended<E>>['fields'] } & OptionsExtended<E>,
|
|
124
|
+
): Promise<AxiosResponse<Pick<E, (typeof options)['fields'][number]>[]>>;
|
|
125
|
+
fetch<T extends unknown[] = ApiResponse[]>(
|
|
126
|
+
reqConfig: AxiosRequestConfig,
|
|
127
|
+
options?: Options,
|
|
128
|
+
): Promise<AxiosResponse<T>>;
|
|
129
|
+
fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options): Promise<AxiosResponse<T | Partial<T>>>;
|
|
130
|
+
fetch<T = ApiResponse>(reqConfig: AxiosRequestConfig, options?: Options) {
|
|
113
131
|
const headers: Record<string, string> = {
|
|
114
132
|
Authorization: RotaCloud.config.apiKey
|
|
115
133
|
? `Bearer ${RotaCloud.config.apiKey}`
|
|
@@ -161,9 +179,17 @@ export abstract class Service<ApiResponse = any> {
|
|
|
161
179
|
}
|
|
162
180
|
|
|
163
181
|
/** Iterates through every page for a potentially paginated request */
|
|
164
|
-
private
|
|
182
|
+
private fetchPages<T = ApiResponse>(
|
|
183
|
+
reqConfig: AxiosRequestConfig<T[]>,
|
|
184
|
+
options: { fields: Required<OptionsExtended<T>>['fields'] } & OptionsExtended<T>,
|
|
185
|
+
): AsyncGenerator<AxiosResponse<Pick<T, (typeof options)['fields'][number]>[]>>;
|
|
186
|
+
private fetchPages<T = ApiResponse>(
|
|
187
|
+
reqConfig: AxiosRequestConfig<T[]>,
|
|
188
|
+
options?: Options,
|
|
189
|
+
): AsyncGenerator<AxiosResponse<T[]>>;
|
|
190
|
+
private async *fetchPages<T = ApiResponse>(
|
|
165
191
|
reqConfig: AxiosRequestConfig<T[]>,
|
|
166
|
-
options
|
|
192
|
+
options?: Options,
|
|
167
193
|
): AsyncGenerator<AxiosResponse<T[]>> {
|
|
168
194
|
const fallbackLimit = 20;
|
|
169
195
|
const res = await this.fetch<T[]>(reqConfig, options);
|
|
@@ -5,7 +5,7 @@ import { Settings } from '../interfaces/index.js';
|
|
|
5
5
|
|
|
6
6
|
import { SettingsQueryParams } from '../rotacloud.js';
|
|
7
7
|
|
|
8
|
-
export class SettingsService extends Service {
|
|
8
|
+
export class SettingsService extends Service<Settings> {
|
|
9
9
|
private apiPath = '/settings';
|
|
10
10
|
|
|
11
11
|
get(query: SettingsQueryParams): Promise<Settings>;
|
|
@@ -14,6 +14,6 @@ export class SettingsService extends Service {
|
|
|
14
14
|
get(query: SettingsQueryParams, options?: Options) {
|
|
15
15
|
return super
|
|
16
16
|
.fetch<Settings>({ url: `${this.apiPath}`, params: query }, options)
|
|
17
|
-
.then((res) =>
|
|
17
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { Shift } from '../interfaces/index.js';
|
|
3
|
-
import { Service, Options, RequirementsOf } from './index.js';
|
|
3
|
+
import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
|
|
4
4
|
|
|
5
5
|
import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
|
|
6
6
|
|
|
7
7
|
type RequiredProps = 'end_time' | 'start_time' | 'location';
|
|
8
8
|
|
|
9
|
-
export class ShiftsService extends Service {
|
|
9
|
+
export class ShiftsService extends Service<Shift> {
|
|
10
10
|
private apiPath = '/shifts';
|
|
11
11
|
|
|
12
12
|
create(data: RequirementsOf<Shift, RequiredProps>): Promise<Shift>;
|
|
@@ -17,27 +17,41 @@ export class ShiftsService extends Service {
|
|
|
17
17
|
create(data: RequirementsOf<Shift, RequiredProps>, options: Options): Promise<Shift>;
|
|
18
18
|
create(data: RequirementsOf<Shift, RequiredProps>, options?: Options) {
|
|
19
19
|
return super
|
|
20
|
-
.fetch<Shift>({ url: this.apiPath, data, method: 'POST' })
|
|
21
|
-
.then((res) =>
|
|
20
|
+
.fetch<Shift>({ url: this.apiPath, data, method: 'POST' }, options)
|
|
21
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
get(id: number): Promise<Shift>;
|
|
25
|
-
get
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
get<F extends keyof Shift>(
|
|
26
|
+
id: number,
|
|
27
|
+
options: { fields: F[]; rawResponse: true } & OptionsExtended<Shift>,
|
|
28
|
+
): Promise<AxiosResponse<Pick<Shift, F>>>;
|
|
29
|
+
get<F extends keyof Shift>(id: number, options: { fields: F[] } & OptionsExtended<Shift>): Promise<Pick<Shift, F>>;
|
|
30
|
+
get(id: number, options: { rawResponse: true } & Options): Promise<AxiosResponse<Shift>>;
|
|
31
|
+
get(id: number, options?: OptionsExtended<Shift>): Promise<Shift>;
|
|
32
|
+
get(id: number, options?: OptionsExtended<Shift>) {
|
|
28
33
|
return super
|
|
29
34
|
.fetch<Shift>({ url: `${this.apiPath}/${id}` }, options)
|
|
30
|
-
.then((res) =>
|
|
35
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
list(query: ShiftsQueryParams): AsyncGenerator<Shift>;
|
|
39
|
+
list<F extends keyof Shift>(
|
|
40
|
+
query: ShiftsQueryParams,
|
|
41
|
+
options: { fields: F[] } & OptionsExtended<Shift>,
|
|
42
|
+
): AsyncGenerator<Pick<Shift, F>>;
|
|
43
|
+
list(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): AsyncGenerator<Shift>;
|
|
44
|
+
async *list(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
|
|
45
|
+
yield* super.iterator({ url: this.apiPath, params: query }, options);
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
listAll(query: ShiftsQueryParams
|
|
40
|
-
|
|
48
|
+
listAll(query: ShiftsQueryParams): Promise<Shift[]>;
|
|
49
|
+
listAll<F extends keyof Shift>(
|
|
50
|
+
query: ShiftsQueryParams,
|
|
51
|
+
options: { fields: F[] } & OptionsExtended<Shift>,
|
|
52
|
+
): Promise<Pick<Shift, F>[]>;
|
|
53
|
+
listAll(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): Promise<Shift[]>;
|
|
54
|
+
async listAll(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
|
|
41
55
|
const shifts = [] as Shift[];
|
|
42
56
|
for await (const shift of this.list(query, options)) {
|
|
43
57
|
shifts.push(shift);
|
|
@@ -45,7 +59,13 @@ export class ShiftsService extends Service {
|
|
|
45
59
|
return shifts;
|
|
46
60
|
}
|
|
47
61
|
|
|
48
|
-
listByPage(query: ShiftsQueryParams
|
|
62
|
+
listByPage(query: ShiftsQueryParams): AsyncGenerator<AxiosResponse<Shift[]>>;
|
|
63
|
+
listByPage<F extends keyof Shift>(
|
|
64
|
+
query: ShiftsQueryParams,
|
|
65
|
+
options: { fields: F[] } & OptionsExtended<Shift>,
|
|
66
|
+
): AsyncGenerator<AxiosResponse<Pick<Shift, F>[]>>;
|
|
67
|
+
listByPage(query: ShiftsQueryParams, options?: OptionsExtended<Shift>): AsyncGenerator<AxiosResponse<Shift[]>>;
|
|
68
|
+
listByPage(query: ShiftsQueryParams, options?: OptionsExtended<Shift>) {
|
|
49
69
|
return super.iterator<Shift>({ url: this.apiPath, params: query }, options).byPage();
|
|
50
70
|
}
|
|
51
71
|
|
|
@@ -65,20 +85,26 @@ export class ShiftsService extends Service {
|
|
|
65
85
|
update(shifts: RequirementsOf<Shift, 'id'> | RequirementsOf<Shift, 'id'>[], options?: Options) {
|
|
66
86
|
if (!Array.isArray(shifts)) {
|
|
67
87
|
return super
|
|
68
|
-
.fetch<Shift>(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
.fetch<Shift>(
|
|
89
|
+
{
|
|
90
|
+
url: `${this.apiPath}/${shifts.id}`,
|
|
91
|
+
data: shifts,
|
|
92
|
+
method: 'POST',
|
|
93
|
+
},
|
|
94
|
+
options,
|
|
95
|
+
)
|
|
73
96
|
.then((res) => (options?.rawResponse ? res : res.data));
|
|
74
97
|
}
|
|
75
98
|
|
|
76
99
|
return super
|
|
77
|
-
.fetch<{ code: number; data?: Shift; error?: string }[]>(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
.fetch<{ code: number; data?: Shift; error?: string }[]>(
|
|
101
|
+
{
|
|
102
|
+
url: this.apiPath,
|
|
103
|
+
data: shifts,
|
|
104
|
+
method: 'POST',
|
|
105
|
+
},
|
|
106
|
+
options,
|
|
107
|
+
)
|
|
82
108
|
.then((res) => {
|
|
83
109
|
if (options?.rawResponse) return res;
|
|
84
110
|
|
|
@@ -94,40 +120,40 @@ export class ShiftsService extends Service {
|
|
|
94
120
|
}
|
|
95
121
|
|
|
96
122
|
delete(ids: number | number[]): Promise<number>;
|
|
97
|
-
delete(ids: number | number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<
|
|
123
|
+
delete(ids: number | number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<void>>;
|
|
98
124
|
delete(ids: number | number[], options: Options): Promise<number>;
|
|
99
125
|
delete(ids: number | number[], options?: Options) {
|
|
100
126
|
const params: AxiosRequestConfig = Array.isArray(ids)
|
|
101
127
|
? { url: this.apiPath, data: { ids }, method: 'DELETE' }
|
|
102
128
|
: { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
|
|
103
129
|
|
|
104
|
-
return super.fetch<
|
|
130
|
+
return super.fetch<void>(params, options).then((res) => (options?.rawResponse ? res : res.status));
|
|
105
131
|
}
|
|
106
132
|
|
|
107
133
|
acknowledge(data: number[]): Promise<number>;
|
|
108
|
-
acknowledge(data: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any
|
|
134
|
+
acknowledge(data: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
|
|
109
135
|
acknowledge(data: number[], options: Options): Promise<number>;
|
|
110
136
|
acknowledge(data: number[], options?: Options) {
|
|
111
137
|
return super
|
|
112
|
-
.fetch<Shift>({ url: '/shifts_acknowledged', data, method: 'POST' })
|
|
113
|
-
.then((res) =>
|
|
138
|
+
.fetch<Shift>({ url: '/shifts_acknowledged', data, method: 'POST' }, options)
|
|
139
|
+
.then((res) => (options?.rawResponse ? res : res.status));
|
|
114
140
|
}
|
|
115
141
|
|
|
116
142
|
publish(data: { shifts: number[] }): Promise<number>;
|
|
117
|
-
publish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any
|
|
143
|
+
publish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
|
|
118
144
|
publish(data: { shifts: number[] }, options: Options): Promise<number>;
|
|
119
145
|
publish(data: { shifts: number[] }, options?: Options) {
|
|
120
146
|
return super
|
|
121
|
-
.fetch<Shift>({ url: '/shifts_published', data, method: 'POST' })
|
|
122
|
-
.then((res) =>
|
|
147
|
+
.fetch<Shift>({ url: '/shifts_published', data, method: 'POST' }, options)
|
|
148
|
+
.then((res) => (options?.rawResponse ? res : res.status));
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
unpublish(data: { shifts: number[] }): Promise<number>;
|
|
126
|
-
unpublish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any
|
|
152
|
+
unpublish(data: { shifts: number[] }, options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
|
|
127
153
|
unpublish(data: { shifts: number[] }, options: Options): Promise<number>;
|
|
128
154
|
unpublish(data: { shifts: number[] }, options?: Options) {
|
|
129
155
|
return super
|
|
130
|
-
.fetch<Shift>({ url: '/shifts_published', data, method: 'DELETE' })
|
|
131
|
-
.then((res) =>
|
|
156
|
+
.fetch<Shift>({ url: '/shifts_published', data, method: 'DELETE' }, options)
|
|
157
|
+
.then((res) => (options?.rawResponse ? res : res.status));
|
|
132
158
|
}
|
|
133
159
|
}
|