rotacloud 1.4.9 → 1.5.1
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/drop-request.interface.d.ts +13 -0
- package/dist/cjs/interfaces/drop-request.interface.js +2 -0
- package/dist/cjs/interfaces/swap-request.interface.d.ts +16 -0
- package/dist/cjs/interfaces/swap-request.interface.js +2 -0
- package/dist/cjs/services/service.d.ts +11 -3
- package/dist/cjs/services/service.js +35 -10
- package/dist/cjs/services/shifts.service.d.ts +21 -1
- package/dist/cjs/services/shifts.service.js +14 -0
- package/dist/cjs/version.js +1 -1
- package/dist/mjs/interfaces/drop-request.interface.d.ts +13 -0
- package/dist/mjs/interfaces/drop-request.interface.js +1 -0
- package/dist/mjs/interfaces/swap-request.interface.d.ts +16 -0
- package/dist/mjs/interfaces/swap-request.interface.js +1 -0
- package/dist/mjs/services/service.d.ts +11 -3
- package/dist/mjs/services/service.js +14 -2
- package/dist/mjs/services/shifts.service.d.ts +21 -1
- package/dist/mjs/services/shifts.service.js +14 -0
- package/dist/mjs/version.js +1 -1
- package/package.json +1 -1
- package/src/interfaces/drop-request.interface.ts +14 -0
- package/src/interfaces/swap-request.interface.ts +17 -0
- package/src/services/service.ts +38 -16
- package/src/services/shifts.service.ts +43 -2
- package/src/version.ts +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
export interface ShiftDropRequest {
|
|
3
|
+
id: number;
|
|
4
|
+
deleted: boolean;
|
|
5
|
+
status: RequestStatus;
|
|
6
|
+
requested_at: number;
|
|
7
|
+
shift: number;
|
|
8
|
+
user: number;
|
|
9
|
+
user_message: string;
|
|
10
|
+
admin?: number;
|
|
11
|
+
admin_message?: string;
|
|
12
|
+
replied_at?: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
export interface ShiftSwapRequest {
|
|
3
|
+
id: number;
|
|
4
|
+
deleted: boolean;
|
|
5
|
+
status: RequestStatus;
|
|
6
|
+
requested_at: number;
|
|
7
|
+
old_user: number;
|
|
8
|
+
new_user: number;
|
|
9
|
+
admin: number | null;
|
|
10
|
+
user_approved: boolean | null;
|
|
11
|
+
user_replied_at: number | null;
|
|
12
|
+
admin_approved: boolean | null;
|
|
13
|
+
admin_replied_at: number | null;
|
|
14
|
+
shift: number;
|
|
15
|
+
swapped_shift: number;
|
|
16
|
+
}
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { SDKConfig } from
|
|
2
|
+
import { SDKConfig } from '../interfaces';
|
|
3
3
|
export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
|
|
4
|
-
export
|
|
4
|
+
export type Options = {
|
|
5
5
|
rawResponse?: boolean;
|
|
6
|
+
maxResults?: number;
|
|
7
|
+
limit?: never;
|
|
8
|
+
offset?: number;
|
|
9
|
+
dryRun?: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
rawResponse?: boolean;
|
|
12
|
+
maxResults?: never;
|
|
13
|
+
/** @deprecated use `maxResults` instead */
|
|
6
14
|
limit?: number;
|
|
7
15
|
offset?: number;
|
|
8
16
|
dryRun?: boolean;
|
|
9
|
-
}
|
|
17
|
+
};
|
|
10
18
|
export type OptionsExtended<T = unknown> = Options & {
|
|
11
19
|
fields?: (keyof T)[];
|
|
12
20
|
};
|
|
@@ -42,7 +42,8 @@ class Service {
|
|
|
42
42
|
return endpoint === '/leave_requests';
|
|
43
43
|
}
|
|
44
44
|
buildQueryParams(options, extraParams) {
|
|
45
|
-
|
|
45
|
+
var _a;
|
|
46
|
+
const queryParams = Object.assign(Object.assign({ fields: options === null || options === void 0 ? void 0 : options.fields, limit: (_a = options === null || options === void 0 ? void 0 : options.maxResults) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.limit, offset: options === null || options === void 0 ? void 0 : options.offset, dry_run: options === null || options === void 0 ? void 0 : options.dryRun }, extraParams), {
|
|
46
47
|
// NOTE: Should not overridable so must come after spread of params
|
|
47
48
|
exclude_link_header: true });
|
|
48
49
|
const reducedParams = Object.entries(queryParams !== null && queryParams !== void 0 ? queryParams : {}).reduce((params, [key, val]) => {
|
|
@@ -96,21 +97,45 @@ class Service {
|
|
|
96
97
|
}
|
|
97
98
|
listResponses(reqConfig, options) {
|
|
98
99
|
return __asyncGenerator(this, arguments, function* listResponses_1() {
|
|
99
|
-
var _a, e_1, _b, _c;
|
|
100
|
+
var _a, e_1, _b, _c, _d, e_2, _e, _f;
|
|
101
|
+
if (!(options === null || options === void 0 ? void 0 : options.maxResults)) {
|
|
102
|
+
try {
|
|
103
|
+
for (var _g = true, _h = __asyncValues(this.fetchPages(reqConfig, options)), _j; _j = yield __await(_h.next()), _a = _j.done, !_a; _g = true) {
|
|
104
|
+
_c = _j.value;
|
|
105
|
+
_g = false;
|
|
106
|
+
const res = _c;
|
|
107
|
+
yield __await(yield* __asyncDelegator(__asyncValues(res.data)));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
111
|
+
finally {
|
|
112
|
+
try {
|
|
113
|
+
if (!_g && !_a && (_b = _h.return)) yield __await(_b.call(_h));
|
|
114
|
+
}
|
|
115
|
+
finally { if (e_1) throw e_1.error; }
|
|
116
|
+
}
|
|
117
|
+
return yield __await(void 0);
|
|
118
|
+
}
|
|
119
|
+
let entityCount = 0;
|
|
100
120
|
try {
|
|
101
|
-
for (var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const res =
|
|
105
|
-
|
|
121
|
+
for (var _k = true, _l = __asyncValues(this.fetchPages(reqConfig, options)), _m; _m = yield __await(_l.next()), _d = _m.done, !_d; _k = true) {
|
|
122
|
+
_f = _m.value;
|
|
123
|
+
_k = false;
|
|
124
|
+
const res = _f;
|
|
125
|
+
for (const entity of res.data) {
|
|
126
|
+
yield yield __await(entity);
|
|
127
|
+
entityCount += 1;
|
|
128
|
+
if (entityCount >= options.maxResults)
|
|
129
|
+
return yield __await(void 0);
|
|
130
|
+
}
|
|
106
131
|
}
|
|
107
132
|
}
|
|
108
|
-
catch (
|
|
133
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
109
134
|
finally {
|
|
110
135
|
try {
|
|
111
|
-
if (!
|
|
136
|
+
if (!_k && !_d && (_e = _l.return)) yield __await(_e.call(_l));
|
|
112
137
|
}
|
|
113
|
-
finally { if (
|
|
138
|
+
finally { if (e_2) throw e_2.error; }
|
|
114
139
|
}
|
|
115
140
|
});
|
|
116
141
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { Shift } from '../interfaces/index.js';
|
|
3
3
|
import { Options, OptionsExtended, RequirementsOf, Service } from './index.js';
|
|
4
|
+
import { ShiftDropRequest } from '../interfaces/drop-request.interface.js';
|
|
4
5
|
import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
|
|
6
|
+
import { ShiftSwapRequest } from '../interfaces/swap-request.interface.js';
|
|
5
7
|
type RequiredProps = 'end_time' | 'start_time' | 'location';
|
|
6
8
|
export declare class ShiftsService extends Service<Shift> {
|
|
7
9
|
private apiPath;
|
|
@@ -49,7 +51,6 @@ export declare class ShiftsService extends Service<Shift> {
|
|
|
49
51
|
error: string;
|
|
50
52
|
}[];
|
|
51
53
|
}>;
|
|
52
|
-
update(shift: RequirementsOf<Shift, 'id'>, options: Options): Promise<Shift>;
|
|
53
54
|
update(shifts: RequirementsOf<Shift, 'id'>[], options: {
|
|
54
55
|
rawResponse: true;
|
|
55
56
|
} & Options): Promise<AxiosResponse<{
|
|
@@ -96,5 +97,24 @@ export declare class ShiftsService extends Service<Shift> {
|
|
|
96
97
|
unpublish(data: {
|
|
97
98
|
shifts: number[];
|
|
98
99
|
}, options: Options): Promise<number>;
|
|
100
|
+
updateSwap(data: ShiftSwapRequest): Promise<ShiftSwapRequest>;
|
|
101
|
+
updateSwap(data: ShiftSwapRequest, options: {
|
|
102
|
+
rawResponse: true;
|
|
103
|
+
} & Options): Promise<AxiosResponse<ShiftSwapRequest>>;
|
|
104
|
+
updateSwap(data: ShiftSwapRequest, options: Options): Promise<ShiftSwapRequest>;
|
|
105
|
+
updateDrop(data: {
|
|
106
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
107
|
+
approved: boolean;
|
|
108
|
+
}): Promise<ShiftDropRequest>;
|
|
109
|
+
updateDrop(data: {
|
|
110
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
111
|
+
approved: boolean;
|
|
112
|
+
}, options: {
|
|
113
|
+
rawResponse: true;
|
|
114
|
+
} & Options): Promise<AxiosResponse<ShiftDropRequest>>;
|
|
115
|
+
updateDrop(data: {
|
|
116
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
117
|
+
approved: boolean;
|
|
118
|
+
}, options: Options): Promise<ShiftDropRequest>;
|
|
99
119
|
}
|
|
100
120
|
export {};
|
|
@@ -136,5 +136,19 @@ class ShiftsService extends index_js_1.Service {
|
|
|
136
136
|
.fetch({ url: '/shifts_published', data, method: 'DELETE' }, options)
|
|
137
137
|
.then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
|
|
138
138
|
}
|
|
139
|
+
updateSwap(data, options) {
|
|
140
|
+
return super
|
|
141
|
+
.fetch({ url: `/swap_requests/${data.id}`, data, method: 'POST' }, options)
|
|
142
|
+
.then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.data));
|
|
143
|
+
}
|
|
144
|
+
updateDrop(data, options) {
|
|
145
|
+
return super
|
|
146
|
+
.fetch({
|
|
147
|
+
url: `/unavailability_requests/${data.request.id}/${data.approved ? 'approve' : 'deny'}`,
|
|
148
|
+
data: { message: data.request.user_message },
|
|
149
|
+
method: 'POST',
|
|
150
|
+
}, options)
|
|
151
|
+
.then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.data));
|
|
152
|
+
}
|
|
139
153
|
}
|
|
140
154
|
exports.ShiftsService = ShiftsService;
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
export interface ShiftDropRequest {
|
|
3
|
+
id: number;
|
|
4
|
+
deleted: boolean;
|
|
5
|
+
status: RequestStatus;
|
|
6
|
+
requested_at: number;
|
|
7
|
+
shift: number;
|
|
8
|
+
user: number;
|
|
9
|
+
user_message: string;
|
|
10
|
+
admin?: number;
|
|
11
|
+
admin_message?: string;
|
|
12
|
+
replied_at?: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
export interface ShiftSwapRequest {
|
|
3
|
+
id: number;
|
|
4
|
+
deleted: boolean;
|
|
5
|
+
status: RequestStatus;
|
|
6
|
+
requested_at: number;
|
|
7
|
+
old_user: number;
|
|
8
|
+
new_user: number;
|
|
9
|
+
admin: number | null;
|
|
10
|
+
user_approved: boolean | null;
|
|
11
|
+
user_replied_at: number | null;
|
|
12
|
+
admin_approved: boolean | null;
|
|
13
|
+
admin_replied_at: number | null;
|
|
14
|
+
shift: number;
|
|
15
|
+
swapped_shift: number;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { SDKConfig } from
|
|
2
|
+
import { SDKConfig } from '../interfaces';
|
|
3
3
|
export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
|
|
4
|
-
export
|
|
4
|
+
export type Options = {
|
|
5
5
|
rawResponse?: boolean;
|
|
6
|
+
maxResults?: number;
|
|
7
|
+
limit?: never;
|
|
8
|
+
offset?: number;
|
|
9
|
+
dryRun?: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
rawResponse?: boolean;
|
|
12
|
+
maxResults?: never;
|
|
13
|
+
/** @deprecated use `maxResults` instead */
|
|
6
14
|
limit?: number;
|
|
7
15
|
offset?: number;
|
|
8
16
|
dryRun?: boolean;
|
|
9
|
-
}
|
|
17
|
+
};
|
|
10
18
|
export type OptionsExtended<T = unknown> = Options & {
|
|
11
19
|
fields?: (keyof T)[];
|
|
12
20
|
};
|
|
@@ -16,7 +16,7 @@ export class Service {
|
|
|
16
16
|
buildQueryParams(options, extraParams) {
|
|
17
17
|
const queryParams = {
|
|
18
18
|
fields: options?.fields,
|
|
19
|
-
limit: options?.limit,
|
|
19
|
+
limit: options?.maxResults ?? options?.limit,
|
|
20
20
|
offset: options?.offset,
|
|
21
21
|
dry_run: options?.dryRun,
|
|
22
22
|
...extraParams,
|
|
@@ -76,8 +76,20 @@ export class Service {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
async *listResponses(reqConfig, options) {
|
|
79
|
+
if (!options?.maxResults) {
|
|
80
|
+
for await (const res of this.fetchPages(reqConfig, options)) {
|
|
81
|
+
yield* res.data;
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
let entityCount = 0;
|
|
79
86
|
for await (const res of this.fetchPages(reqConfig, options)) {
|
|
80
|
-
|
|
87
|
+
for (const entity of res.data) {
|
|
88
|
+
yield entity;
|
|
89
|
+
entityCount += 1;
|
|
90
|
+
if (entityCount >= options.maxResults)
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
81
93
|
}
|
|
82
94
|
}
|
|
83
95
|
iterator(reqConfig, options) {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { Shift } from '../interfaces/index.js';
|
|
3
3
|
import { Options, OptionsExtended, RequirementsOf, Service } from './index.js';
|
|
4
|
+
import { ShiftDropRequest } from '../interfaces/drop-request.interface.js';
|
|
4
5
|
import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
|
|
6
|
+
import { ShiftSwapRequest } from '../interfaces/swap-request.interface.js';
|
|
5
7
|
type RequiredProps = 'end_time' | 'start_time' | 'location';
|
|
6
8
|
export declare class ShiftsService extends Service<Shift> {
|
|
7
9
|
private apiPath;
|
|
@@ -49,7 +51,6 @@ export declare class ShiftsService extends Service<Shift> {
|
|
|
49
51
|
error: string;
|
|
50
52
|
}[];
|
|
51
53
|
}>;
|
|
52
|
-
update(shift: RequirementsOf<Shift, 'id'>, options: Options): Promise<Shift>;
|
|
53
54
|
update(shifts: RequirementsOf<Shift, 'id'>[], options: {
|
|
54
55
|
rawResponse: true;
|
|
55
56
|
} & Options): Promise<AxiosResponse<{
|
|
@@ -96,5 +97,24 @@ export declare class ShiftsService extends Service<Shift> {
|
|
|
96
97
|
unpublish(data: {
|
|
97
98
|
shifts: number[];
|
|
98
99
|
}, options: Options): Promise<number>;
|
|
100
|
+
updateSwap(data: ShiftSwapRequest): Promise<ShiftSwapRequest>;
|
|
101
|
+
updateSwap(data: ShiftSwapRequest, options: {
|
|
102
|
+
rawResponse: true;
|
|
103
|
+
} & Options): Promise<AxiosResponse<ShiftSwapRequest>>;
|
|
104
|
+
updateSwap(data: ShiftSwapRequest, options: Options): Promise<ShiftSwapRequest>;
|
|
105
|
+
updateDrop(data: {
|
|
106
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
107
|
+
approved: boolean;
|
|
108
|
+
}): Promise<ShiftDropRequest>;
|
|
109
|
+
updateDrop(data: {
|
|
110
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
111
|
+
approved: boolean;
|
|
112
|
+
}, options: {
|
|
113
|
+
rawResponse: true;
|
|
114
|
+
} & Options): Promise<AxiosResponse<ShiftDropRequest>>;
|
|
115
|
+
updateDrop(data: {
|
|
116
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
117
|
+
approved: boolean;
|
|
118
|
+
}, options: Options): Promise<ShiftDropRequest>;
|
|
99
119
|
}
|
|
100
120
|
export {};
|
|
@@ -79,4 +79,18 @@ export class ShiftsService extends Service {
|
|
|
79
79
|
.fetch({ url: '/shifts_published', data, method: 'DELETE' }, options)
|
|
80
80
|
.then((res) => (options?.rawResponse ? res : res.status));
|
|
81
81
|
}
|
|
82
|
+
updateSwap(data, options) {
|
|
83
|
+
return super
|
|
84
|
+
.fetch({ url: `/swap_requests/${data.id}`, data, method: 'POST' }, options)
|
|
85
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
86
|
+
}
|
|
87
|
+
updateDrop(data, options) {
|
|
88
|
+
return super
|
|
89
|
+
.fetch({
|
|
90
|
+
url: `/unavailability_requests/${data.request.id}/${data.approved ? 'approve' : 'deny'}`,
|
|
91
|
+
data: { message: data.request.user_message },
|
|
92
|
+
method: 'POST',
|
|
93
|
+
}, options)
|
|
94
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
95
|
+
}
|
|
82
96
|
}
|
package/dist/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const Version = { version: '1.
|
|
1
|
+
export const Version = { version: '1.5.1' };
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
|
|
3
|
+
export interface ShiftDropRequest {
|
|
4
|
+
id: number;
|
|
5
|
+
deleted: boolean;
|
|
6
|
+
status: RequestStatus;
|
|
7
|
+
requested_at: number;
|
|
8
|
+
shift: number;
|
|
9
|
+
user: number;
|
|
10
|
+
user_message: string;
|
|
11
|
+
admin?: number;
|
|
12
|
+
admin_message?: string;
|
|
13
|
+
replied_at?: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type RequestStatus = 'expired' | 'shift_changed' | 'approved' | 'denied' | 'requested';
|
|
2
|
+
|
|
3
|
+
export interface ShiftSwapRequest {
|
|
4
|
+
id: number;
|
|
5
|
+
deleted: boolean;
|
|
6
|
+
status: RequestStatus;
|
|
7
|
+
requested_at: number;
|
|
8
|
+
old_user: number;
|
|
9
|
+
new_user: number;
|
|
10
|
+
admin: number | null;
|
|
11
|
+
user_approved: boolean | null;
|
|
12
|
+
user_replied_at: number | null;
|
|
13
|
+
admin_approved: boolean | null;
|
|
14
|
+
admin_replied_at: number | null;
|
|
15
|
+
shift: number;
|
|
16
|
+
swapped_shift: number;
|
|
17
|
+
}
|
package/src/services/service.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
2
|
import { Version } from '../version.js';
|
|
3
|
-
import { SDKConfig } from
|
|
3
|
+
import { SDKConfig } from '../interfaces';
|
|
4
4
|
|
|
5
5
|
export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
export type Options =
|
|
8
|
+
| {
|
|
9
|
+
rawResponse?: boolean;
|
|
10
|
+
maxResults?: number;
|
|
11
|
+
limit?: never;
|
|
12
|
+
offset?: number;
|
|
13
|
+
dryRun?: boolean;
|
|
14
|
+
}
|
|
15
|
+
| {
|
|
16
|
+
rawResponse?: boolean;
|
|
17
|
+
maxResults?: never;
|
|
18
|
+
/** @deprecated use `maxResults` instead */
|
|
19
|
+
limit?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
};
|
|
13
23
|
|
|
14
24
|
export type OptionsExtended<T = unknown> = Options & {
|
|
15
25
|
fields?: (keyof T)[];
|
|
@@ -20,13 +30,13 @@ type ParameterValue = ParameterPrimitive | ParameterPrimitive[] | undefined;
|
|
|
20
30
|
|
|
21
31
|
export abstract class Service<ApiResponse = any> {
|
|
22
32
|
constructor(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
protected client: AxiosInstance,
|
|
34
|
+
// opt to use options object here, so we could
|
|
35
|
+
// define the config property as a getter
|
|
36
|
+
// in RotaCloud class. With this change config in
|
|
37
|
+
// this class will always be up-to-date with
|
|
38
|
+
// RotaCloud client config
|
|
39
|
+
protected readonly options: { config: SDKConfig },
|
|
30
40
|
) {}
|
|
31
41
|
|
|
32
42
|
private isLeaveRequest(endpoint?: string): boolean {
|
|
@@ -39,7 +49,7 @@ export abstract class Service<ApiResponse = any> {
|
|
|
39
49
|
) {
|
|
40
50
|
const queryParams: Record<string, ParameterValue> = {
|
|
41
51
|
fields: options?.fields,
|
|
42
|
-
limit: options?.limit,
|
|
52
|
+
limit: options?.maxResults ?? options?.limit,
|
|
43
53
|
offset: options?.offset,
|
|
44
54
|
dry_run: options?.dryRun,
|
|
45
55
|
...extraParams,
|
|
@@ -132,8 +142,20 @@ export abstract class Service<ApiResponse = any> {
|
|
|
132
142
|
}
|
|
133
143
|
|
|
134
144
|
private async *listResponses<T = ApiResponse>(reqConfig: AxiosRequestConfig<T[]>, options?: Options) {
|
|
145
|
+
if (!options?.maxResults) {
|
|
146
|
+
for await (const res of this.fetchPages<T>(reqConfig, options)) {
|
|
147
|
+
yield* res.data;
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
let entityCount = 0;
|
|
135
153
|
for await (const res of this.fetchPages<T>(reqConfig, options)) {
|
|
136
|
-
|
|
154
|
+
for (const entity of res.data) {
|
|
155
|
+
yield entity;
|
|
156
|
+
entityCount += 1;
|
|
157
|
+
if (entityCount >= options.maxResults) return;
|
|
158
|
+
}
|
|
137
159
|
}
|
|
138
160
|
}
|
|
139
161
|
|
|
@@ -2,7 +2,9 @@ import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
|
2
2
|
import { Shift } from '../interfaces/index.js';
|
|
3
3
|
import { Options, OptionsExtended, RequirementsOf, Service } from './index.js';
|
|
4
4
|
|
|
5
|
+
import { ShiftDropRequest } from '../interfaces/drop-request.interface.js';
|
|
5
6
|
import { ShiftsQueryParams } from '../interfaces/query-params/shifts-query-params.interface.js';
|
|
7
|
+
import { ShiftSwapRequest } from '../interfaces/swap-request.interface.js';
|
|
6
8
|
|
|
7
9
|
type RequiredProps = 'end_time' | 'start_time' | 'location';
|
|
8
10
|
|
|
@@ -73,7 +75,6 @@ export class ShiftsService extends Service<Shift> {
|
|
|
73
75
|
update(shift: RequirementsOf<Shift, 'id'>, options: { rawResponse: true } & Options): Promise<AxiosResponse<Shift>>;
|
|
74
76
|
update(shift: RequirementsOf<Shift, 'id'>, options: Options): Promise<Shift>;
|
|
75
77
|
update(shifts: RequirementsOf<Shift, 'id'>[]): Promise<{ success: Shift[]; failed: { id: number; error: string }[] }>;
|
|
76
|
-
update(shift: RequirementsOf<Shift, 'id'>, options: Options): Promise<Shift>;
|
|
77
78
|
update(
|
|
78
79
|
shifts: RequirementsOf<Shift, 'id'>[],
|
|
79
80
|
options: { rawResponse: true } & Options,
|
|
@@ -135,7 +136,7 @@ export class ShiftsService extends Service<Shift> {
|
|
|
135
136
|
acknowledge(shifts: number[], options: Options): Promise<number>;
|
|
136
137
|
acknowledge(shifts: number[], options?: Options) {
|
|
137
138
|
return super
|
|
138
|
-
.fetch<Shift>({ url: '/shifts_acknowledged', data: {shifts}, method: 'POST' }, options)
|
|
139
|
+
.fetch<Shift>({ url: '/shifts_acknowledged', data: { shifts }, method: 'POST' }, options)
|
|
139
140
|
.then((res) => (options?.rawResponse ? res : res.status));
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -156,4 +157,44 @@ export class ShiftsService extends Service<Shift> {
|
|
|
156
157
|
.fetch<Shift>({ url: '/shifts_published', data, method: 'DELETE' }, options)
|
|
157
158
|
.then((res) => (options?.rawResponse ? res : res.status));
|
|
158
159
|
}
|
|
160
|
+
|
|
161
|
+
updateSwap(data: ShiftSwapRequest): Promise<ShiftSwapRequest>;
|
|
162
|
+
updateSwap(
|
|
163
|
+
data: ShiftSwapRequest,
|
|
164
|
+
options: { rawResponse: true } & Options,
|
|
165
|
+
): Promise<AxiosResponse<ShiftSwapRequest>>;
|
|
166
|
+
updateSwap(data: ShiftSwapRequest, options: Options): Promise<ShiftSwapRequest>;
|
|
167
|
+
updateSwap(data: ShiftSwapRequest, options?: Options) {
|
|
168
|
+
return super
|
|
169
|
+
.fetch<Shift>({ url: `/swap_requests/${data.id}`, data, method: 'POST' }, options)
|
|
170
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
updateDrop(data: {
|
|
174
|
+
request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>;
|
|
175
|
+
approved: boolean;
|
|
176
|
+
}): Promise<ShiftDropRequest>;
|
|
177
|
+
updateDrop(
|
|
178
|
+
data: { request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>; approved: boolean },
|
|
179
|
+
options: { rawResponse: true } & Options,
|
|
180
|
+
): Promise<AxiosResponse<ShiftDropRequest>>;
|
|
181
|
+
updateDrop(
|
|
182
|
+
data: { request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>; approved: boolean },
|
|
183
|
+
options: Options,
|
|
184
|
+
): Promise<ShiftDropRequest>;
|
|
185
|
+
updateDrop(
|
|
186
|
+
data: { request: RequirementsOf<ShiftDropRequest, 'id' | 'user_message'>; approved: boolean },
|
|
187
|
+
options?: Options,
|
|
188
|
+
) {
|
|
189
|
+
return super
|
|
190
|
+
.fetch<Shift>(
|
|
191
|
+
{
|
|
192
|
+
url: `/unavailability_requests/${data.request.id}/${data.approved ? 'approve' : 'deny'}`,
|
|
193
|
+
data: { message: data.request.user_message },
|
|
194
|
+
method: 'POST',
|
|
195
|
+
},
|
|
196
|
+
options,
|
|
197
|
+
)
|
|
198
|
+
.then((res) => (options?.rawResponse ? res : res.data));
|
|
199
|
+
}
|
|
159
200
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const Version = { version: '1.
|
|
1
|
+
export const Version = { version: '1.5.1' };
|