rotacloud 1.4.8 → 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.
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,12 +1,20 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
- import { SDKConfig } from "../interfaces";
2
+ import { SDKConfig } from '../interfaces';
3
3
  export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
4
- export interface Options {
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
- const queryParams = Object.assign(Object.assign({ fields: options === null || options === void 0 ? void 0 : options.fields, limit: 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), {
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 _d = true, _e = __asyncValues(this.fetchPages(reqConfig, options)), _f; _f = yield __await(_e.next()), _a = _f.done, !_a; _d = true) {
102
- _c = _f.value;
103
- _d = false;
104
- const res = _c;
105
- yield __await(yield* __asyncDelegator(__asyncValues(res.data)));
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 (e_1_1) { e_1 = { error: e_1_1 }; }
133
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
109
134
  finally {
110
135
  try {
111
- if (!_d && !_a && (_b = _e.return)) yield __await(_b.call(_e));
136
+ if (!_k && !_d && (_e = _l.return)) yield __await(_e.call(_l));
112
137
  }
113
- finally { if (e_1) throw e_1.error; }
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
- import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
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<{
@@ -69,11 +70,11 @@ export declare class ShiftsService extends Service<Shift> {
69
70
  rawResponse: true;
70
71
  } & Options): Promise<AxiosResponse<void>>;
71
72
  delete(ids: number | number[], options: Options): Promise<number>;
72
- acknowledge(data: number[]): Promise<number>;
73
- acknowledge(data: number[], options: {
73
+ acknowledge(shifts: number[]): Promise<number>;
74
+ acknowledge(shifts: number[], options: {
74
75
  rawResponse: true;
75
76
  } & Options): Promise<AxiosResponse<any>>;
76
- acknowledge(data: number[], options: Options): Promise<number>;
77
+ acknowledge(shifts: number[], options: Options): Promise<number>;
77
78
  publish(data: {
78
79
  shifts: number[];
79
80
  }): Promise<number>;
@@ -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 {};
@@ -121,9 +121,9 @@ class ShiftsService extends index_js_1.Service {
121
121
  : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
122
122
  return super.fetch(params, options).then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
123
123
  }
124
- acknowledge(data, options) {
124
+ acknowledge(shifts, options) {
125
125
  return super
126
- .fetch({ url: '/shifts_acknowledged', data, method: 'POST' }, options)
126
+ .fetch({ url: '/shifts_acknowledged', data: { shifts }, method: 'POST' }, options)
127
127
  .then((res) => ((options === null || options === void 0 ? void 0 : options.rawResponse) ? res : res.status));
128
128
  }
129
129
  publish(data, options) {
@@ -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;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Version = void 0;
4
- exports.Version = { version: '1.4.8' };
4
+ exports.Version = { version: '1.5.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 @@
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 "../interfaces";
2
+ import { SDKConfig } from '../interfaces';
3
3
  export type RequirementsOf<T, K extends keyof T> = Required<Pick<T, K>> & Partial<T>;
4
- export interface Options {
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
- yield* res.data;
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
- import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
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<{
@@ -69,11 +70,11 @@ export declare class ShiftsService extends Service<Shift> {
69
70
  rawResponse: true;
70
71
  } & Options): Promise<AxiosResponse<void>>;
71
72
  delete(ids: number | number[], options: Options): Promise<number>;
72
- acknowledge(data: number[]): Promise<number>;
73
- acknowledge(data: number[], options: {
73
+ acknowledge(shifts: number[]): Promise<number>;
74
+ acknowledge(shifts: number[], options: {
74
75
  rawResponse: true;
75
76
  } & Options): Promise<AxiosResponse<any>>;
76
- acknowledge(data: number[], options: Options): Promise<number>;
77
+ acknowledge(shifts: number[], options: Options): Promise<number>;
77
78
  publish(data: {
78
79
  shifts: number[];
79
80
  }): Promise<number>;
@@ -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 {};
@@ -64,9 +64,9 @@ export class ShiftsService extends Service {
64
64
  : { url: `${this.apiPath}/${ids}`, method: 'DELETE' };
65
65
  return super.fetch(params, options).then((res) => (options?.rawResponse ? res : res.status));
66
66
  }
67
- acknowledge(data, options) {
67
+ acknowledge(shifts, options) {
68
68
  return super
69
- .fetch({ url: '/shifts_acknowledged', data, method: 'POST' }, options)
69
+ .fetch({ url: '/shifts_acknowledged', data: { shifts }, method: 'POST' }, options)
70
70
  .then((res) => (options?.rawResponse ? res : res.status));
71
71
  }
72
72
  publish(data, options) {
@@ -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
  }
@@ -1 +1 @@
1
- export const Version = { version: '1.4.8' };
1
+ export const Version = { version: '1.5.1' };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rotacloud",
3
- "version": "1.4.8",
3
+ "version": "1.5.1",
4
4
  "description": "The RotaCloud SDK for the RotaCloud API",
5
5
  "engines": {
6
6
  "node": ">=16.10.0"
@@ -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
+ }
@@ -1,15 +1,25 @@
1
1
  import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { Version } from '../version.js';
3
- import { SDKConfig } from "../interfaces";
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 interface Options {
8
- rawResponse?: boolean;
9
- limit?: number;
10
- offset?: number;
11
- dryRun?: boolean;
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
- protected client: AxiosInstance,
24
- // opt to use options object here, so we could
25
- // define the config property as a getter
26
- // in RotaCloud class. With this change config in
27
- // this class will always be up-to-date with
28
- // RotaCloud client config
29
- protected readonly options: { config: SDKConfig }
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
- yield* res.data;
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
 
@@ -1,8 +1,10 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { Shift } from '../interfaces/index.js';
3
- import { Service, Options, RequirementsOf, OptionsExtended } from './index.js';
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,
@@ -130,12 +131,12 @@ export class ShiftsService extends Service<Shift> {
130
131
  return super.fetch<void>(params, options).then((res) => (options?.rawResponse ? res : res.status));
131
132
  }
132
133
 
133
- acknowledge(data: number[]): Promise<number>;
134
- acknowledge(data: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
135
- acknowledge(data: number[], options: Options): Promise<number>;
136
- acknowledge(data: number[], options?: Options) {
134
+ acknowledge(shifts: number[]): Promise<number>;
135
+ acknowledge(shifts: number[], options: { rawResponse: true } & Options): Promise<AxiosResponse<any>>;
136
+ acknowledge(shifts: number[], options: Options): Promise<number>;
137
+ acknowledge(shifts: number[], options?: Options) {
137
138
  return super
138
- .fetch<Shift>({ url: '/shifts_acknowledged', data, 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.4.8' };
1
+ export const Version = { version: '1.5.1' };