@gymspace/sdk 1.2.14 → 1.2.16
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/.tsbuildinfo +1 -1
- package/dist/index.d.mts +432 -1
- package/dist/index.d.ts +432 -1
- package/dist/index.js +272 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +264 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +26 -4
- package/src/models/clients.ts +13 -0
- package/src/models/commissions.ts +332 -0
- package/src/models/index.ts +1 -0
- package/src/resources/commission-calculations.ts +93 -0
- package/src/resources/commission-config.ts +66 -0
- package/src/resources/commission-promotions.ts +76 -0
- package/src/resources/commission-reports.ts +69 -0
- package/src/resources/commission-rules.ts +91 -0
- package/src/resources/index.ts +5 -0
- package/src/sdk.ts +15 -0
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -35,6 +35,28 @@ export class ApiClient {
|
|
|
35
35
|
'Content-Type': 'application/json',
|
|
36
36
|
...config.headers,
|
|
37
37
|
},
|
|
38
|
+
paramsSerializer: (params) => {
|
|
39
|
+
const parts: string[] = [];
|
|
40
|
+
|
|
41
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
42
|
+
if (value === undefined || value === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Convert arrays to comma-separated strings
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
if (value.length > 0) {
|
|
49
|
+
// Encode each array element individually, then join with comma
|
|
50
|
+
const encodedValues = value.map((v) => encodeURIComponent(String(v))).join(',');
|
|
51
|
+
parts.push(`${encodeURIComponent(key)}=${encodedValues}`);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return parts.join('&');
|
|
59
|
+
},
|
|
38
60
|
});
|
|
39
61
|
|
|
40
62
|
this.setupInterceptors();
|
|
@@ -67,21 +89,21 @@ export class ApiClient {
|
|
|
67
89
|
// Check if backend refreshed tokens
|
|
68
90
|
const newAccessToken = response.headers['x-new-access-token'];
|
|
69
91
|
const newRefreshToken = response.headers['x-new-refresh-token'];
|
|
70
|
-
|
|
92
|
+
|
|
71
93
|
if (newAccessToken) {
|
|
72
94
|
console.log('Tokens refreshed by backend, updating SDK...');
|
|
73
95
|
this.setAuthToken(newAccessToken);
|
|
74
|
-
|
|
96
|
+
|
|
75
97
|
if (newRefreshToken) {
|
|
76
98
|
this.setRefreshToken(newRefreshToken);
|
|
77
99
|
}
|
|
78
|
-
|
|
100
|
+
|
|
79
101
|
// Notify client about token refresh
|
|
80
102
|
if (this.onTokenRefreshed) {
|
|
81
103
|
this.onTokenRefreshed(newAccessToken, newRefreshToken);
|
|
82
104
|
}
|
|
83
105
|
}
|
|
84
|
-
|
|
106
|
+
|
|
85
107
|
return response;
|
|
86
108
|
},
|
|
87
109
|
async (error: AxiosError) => {
|
package/src/models/clients.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// Tag-related types
|
|
2
|
+
export interface ClientTag {
|
|
3
|
+
tag: {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
color: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
export interface CreateClientDto {
|
|
2
11
|
name: string;
|
|
3
12
|
email?: string;
|
|
@@ -78,6 +87,7 @@ export interface Client {
|
|
|
78
87
|
name: string;
|
|
79
88
|
};
|
|
80
89
|
}>;
|
|
90
|
+
clientTags?: ClientTag[];
|
|
81
91
|
_count?: {
|
|
82
92
|
evaluations: number;
|
|
83
93
|
checkIns: number;
|
|
@@ -135,4 +145,7 @@ export interface SearchClientsParams {
|
|
|
135
145
|
includeContractStatus?: boolean;
|
|
136
146
|
notCheckedInToday?: boolean;
|
|
137
147
|
checkedInToday?: boolean;
|
|
148
|
+
tagIds?: string[];
|
|
149
|
+
tagOperator?: 'and' | 'or';
|
|
150
|
+
includeTags?: boolean;
|
|
138
151
|
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
export enum CommissionRuleType {
|
|
2
|
+
PLAN = 'PLAN',
|
|
3
|
+
AMOUNT = 'AMOUNT',
|
|
4
|
+
PROMOTION = 'PROMOTION',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export enum CommissionStatus {
|
|
8
|
+
PENDING = 'PENDING',
|
|
9
|
+
CONFIRMED = 'CONFIRMED',
|
|
10
|
+
PAID = 'PAID',
|
|
11
|
+
REVERSED = 'REVERSED',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum CommissionChangeType {
|
|
15
|
+
CREATED = 'CREATED',
|
|
16
|
+
UPDATED = 'UPDATED',
|
|
17
|
+
DELETED = 'DELETED',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum CommissionEntityType {
|
|
21
|
+
CONFIG = 'CONFIG',
|
|
22
|
+
RULE = 'RULE',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RuleCriteria {
|
|
26
|
+
planId?: string;
|
|
27
|
+
minAmount?: number;
|
|
28
|
+
maxAmount?: number;
|
|
29
|
+
planIds?: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CommissionConfigDto {
|
|
33
|
+
id: string;
|
|
34
|
+
gymId: string;
|
|
35
|
+
defaultPercentage: number;
|
|
36
|
+
reversalPeriodDays: number;
|
|
37
|
+
minimumContractDays: number;
|
|
38
|
+
isActive: boolean;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CreateCommissionConfigDto {
|
|
44
|
+
defaultPercentage: number;
|
|
45
|
+
reversalPeriodDays: number;
|
|
46
|
+
minimumContractDays: number;
|
|
47
|
+
isActive: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UpdateCommissionConfigDto {
|
|
51
|
+
defaultPercentage?: number;
|
|
52
|
+
reversalPeriodDays?: number;
|
|
53
|
+
minimumContractDays?: number;
|
|
54
|
+
isActive?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CommissionRuleDto {
|
|
58
|
+
id: string;
|
|
59
|
+
gymId: string;
|
|
60
|
+
name: string;
|
|
61
|
+
type: CommissionRuleType;
|
|
62
|
+
percentage: number;
|
|
63
|
+
priority: number;
|
|
64
|
+
criteria: RuleCriteria;
|
|
65
|
+
startDate?: string;
|
|
66
|
+
endDate?: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
isActive: boolean;
|
|
69
|
+
createdAt: string;
|
|
70
|
+
updatedAt: string;
|
|
71
|
+
usageCount: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface CreateCommissionRuleDto {
|
|
75
|
+
name: string;
|
|
76
|
+
type: CommissionRuleType;
|
|
77
|
+
percentage: number;
|
|
78
|
+
criteria?: RuleCriteria;
|
|
79
|
+
startDate?: string;
|
|
80
|
+
endDate?: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface UpdateCommissionRuleDto {
|
|
85
|
+
name?: string;
|
|
86
|
+
percentage?: number;
|
|
87
|
+
criteria?: RuleCriteria;
|
|
88
|
+
startDate?: string;
|
|
89
|
+
endDate?: string;
|
|
90
|
+
description?: string;
|
|
91
|
+
isActive?: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface CommissionRuleFiltersDto {
|
|
95
|
+
type?: CommissionRuleType;
|
|
96
|
+
isActive?: boolean;
|
|
97
|
+
search?: string;
|
|
98
|
+
page: number;
|
|
99
|
+
limit: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface CommissionCalculationDto {
|
|
103
|
+
id: string;
|
|
104
|
+
gymId: string;
|
|
105
|
+
contractId: string;
|
|
106
|
+
collaboratorId: string;
|
|
107
|
+
ruleId: string | null;
|
|
108
|
+
percentage: number;
|
|
109
|
+
baseAmount: number;
|
|
110
|
+
amount: number;
|
|
111
|
+
status: CommissionStatus;
|
|
112
|
+
saleDate: string;
|
|
113
|
+
createdAt: string;
|
|
114
|
+
updatedAt: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface CommissionFiltersDto {
|
|
118
|
+
status?: CommissionStatus;
|
|
119
|
+
collaboratorId?: string;
|
|
120
|
+
startDate?: string;
|
|
121
|
+
endDate?: string;
|
|
122
|
+
page: number;
|
|
123
|
+
limit: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface CommissionSummaryDto {
|
|
127
|
+
period: {
|
|
128
|
+
start: string;
|
|
129
|
+
end: string;
|
|
130
|
+
};
|
|
131
|
+
totals: {
|
|
132
|
+
totalCommissions: number;
|
|
133
|
+
totalContracts: number;
|
|
134
|
+
averageCommission: number;
|
|
135
|
+
totalPaid: number;
|
|
136
|
+
totalPending: number;
|
|
137
|
+
};
|
|
138
|
+
byStatus: {
|
|
139
|
+
status: CommissionStatus;
|
|
140
|
+
count: number;
|
|
141
|
+
total: number;
|
|
142
|
+
}[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface SimulateCommissionDto {
|
|
146
|
+
collaboratorId: string;
|
|
147
|
+
planId: string;
|
|
148
|
+
baseAmount: number;
|
|
149
|
+
saleDate: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface CommissionSimulationDto {
|
|
153
|
+
percentage: number;
|
|
154
|
+
baseAmount: number;
|
|
155
|
+
amount: number;
|
|
156
|
+
appliedRule: {
|
|
157
|
+
id: string;
|
|
158
|
+
name: string;
|
|
159
|
+
type: CommissionRuleType;
|
|
160
|
+
percentage: number;
|
|
161
|
+
} | null;
|
|
162
|
+
isDefault: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface CommissionComparisonDto {
|
|
166
|
+
scenarios: CommissionSimulationDto[];
|
|
167
|
+
bestScenario: {
|
|
168
|
+
index: number;
|
|
169
|
+
amount: number;
|
|
170
|
+
difference: number;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface ReportFiltersDto {
|
|
175
|
+
startDate?: string;
|
|
176
|
+
endDate?: string;
|
|
177
|
+
period?: 'week' | 'month' | 'quarter' | 'year';
|
|
178
|
+
ruleId?: string;
|
|
179
|
+
collaboratorId?: string;
|
|
180
|
+
limit?: number;
|
|
181
|
+
offset?: number;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface CommissionSummaryReportDto {
|
|
185
|
+
period: {
|
|
186
|
+
start: string;
|
|
187
|
+
end: string;
|
|
188
|
+
};
|
|
189
|
+
totals: {
|
|
190
|
+
totalCommissions: number;
|
|
191
|
+
totalContracts: number;
|
|
192
|
+
averageCommission: number;
|
|
193
|
+
totalPaid: number;
|
|
194
|
+
totalPending: number;
|
|
195
|
+
};
|
|
196
|
+
byStatus: {
|
|
197
|
+
status: string;
|
|
198
|
+
count: number;
|
|
199
|
+
total: number;
|
|
200
|
+
}[];
|
|
201
|
+
byRule: {
|
|
202
|
+
ruleId: string;
|
|
203
|
+
ruleName: string;
|
|
204
|
+
ruleType: string;
|
|
205
|
+
contractsCount: number;
|
|
206
|
+
totalCommissions: number;
|
|
207
|
+
averageCommission: number;
|
|
208
|
+
}[];
|
|
209
|
+
byCollaborator: {
|
|
210
|
+
collaboratorId: string;
|
|
211
|
+
collaboratorName: string;
|
|
212
|
+
contractsCount: number;
|
|
213
|
+
totalCommissions: number;
|
|
214
|
+
averageCommission: number;
|
|
215
|
+
}[];
|
|
216
|
+
trend: {
|
|
217
|
+
date: string;
|
|
218
|
+
commissions: number;
|
|
219
|
+
contracts: number;
|
|
220
|
+
}[];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface RuleReportDto {
|
|
224
|
+
ruleId: string;
|
|
225
|
+
ruleName: string;
|
|
226
|
+
ruleType: string;
|
|
227
|
+
percentage: number;
|
|
228
|
+
contractsCount: number;
|
|
229
|
+
totalCommissions: number;
|
|
230
|
+
averageCommission: number;
|
|
231
|
+
minCommission: number;
|
|
232
|
+
maxCommission: number;
|
|
233
|
+
effectiveness: {
|
|
234
|
+
usageRate: number;
|
|
235
|
+
conversionImpact: number;
|
|
236
|
+
roi: number;
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface CollaboratorReportDto {
|
|
241
|
+
collaboratorId: string;
|
|
242
|
+
collaboratorName: string;
|
|
243
|
+
roleName: string;
|
|
244
|
+
contractsCount: number;
|
|
245
|
+
totalCommissions: number;
|
|
246
|
+
averageCommission: number;
|
|
247
|
+
totalPaid: number;
|
|
248
|
+
totalPending: number;
|
|
249
|
+
performance: {
|
|
250
|
+
rank: number;
|
|
251
|
+
percentile: number;
|
|
252
|
+
comparisonWithAverage: number;
|
|
253
|
+
};
|
|
254
|
+
rulesUsed: {
|
|
255
|
+
ruleId: string;
|
|
256
|
+
ruleName: string;
|
|
257
|
+
count: number;
|
|
258
|
+
total: number;
|
|
259
|
+
}[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export interface PromotionReportFiltersDto {
|
|
263
|
+
promotionId?: string;
|
|
264
|
+
status?: 'active' | 'scheduled' | 'expired';
|
|
265
|
+
startDate?: string;
|
|
266
|
+
endDate?: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface PromotionReportDto {
|
|
270
|
+
promotionId: string;
|
|
271
|
+
promotionName: string;
|
|
272
|
+
percentage: number;
|
|
273
|
+
startDate: string;
|
|
274
|
+
endDate: string;
|
|
275
|
+
status: string;
|
|
276
|
+
impact: {
|
|
277
|
+
contractsCreated: number;
|
|
278
|
+
totalCommissions: number;
|
|
279
|
+
averageCommission: number;
|
|
280
|
+
comparisonWithNormal: {
|
|
281
|
+
normalCommissions: number;
|
|
282
|
+
promotionalCommissions: number;
|
|
283
|
+
additionalCost: number;
|
|
284
|
+
percentageIncrease: number;
|
|
285
|
+
};
|
|
286
|
+
salesIncrease: {
|
|
287
|
+
contractsBeforePromotion: number;
|
|
288
|
+
contractsDuringPromotion: number;
|
|
289
|
+
percentageIncrease: number;
|
|
290
|
+
};
|
|
291
|
+
roi: {
|
|
292
|
+
additionalRevenue: number;
|
|
293
|
+
additionalCost: number;
|
|
294
|
+
netBenefit: number;
|
|
295
|
+
roiPercentage: number;
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface CommissionHistoryFiltersDto {
|
|
301
|
+
entityType?: CommissionEntityType;
|
|
302
|
+
changeType?: CommissionChangeType;
|
|
303
|
+
startDate?: string;
|
|
304
|
+
endDate?: string;
|
|
305
|
+
page: number;
|
|
306
|
+
limit: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface CommissionHistoryDto {
|
|
310
|
+
id: string;
|
|
311
|
+
configId: string | null;
|
|
312
|
+
ruleId: string | null;
|
|
313
|
+
changeType: CommissionChangeType;
|
|
314
|
+
entityType: CommissionEntityType;
|
|
315
|
+
previousValue: any;
|
|
316
|
+
newValue: any;
|
|
317
|
+
changedBy: {
|
|
318
|
+
id: string;
|
|
319
|
+
name: string;
|
|
320
|
+
email: string;
|
|
321
|
+
};
|
|
322
|
+
changedAt: string;
|
|
323
|
+
reason: string | null;
|
|
324
|
+
impact: string | null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface PaginatedCommissionResult<T> {
|
|
328
|
+
items: T[];
|
|
329
|
+
total: number;
|
|
330
|
+
limit: number;
|
|
331
|
+
offset: number;
|
|
332
|
+
}
|
package/src/models/index.ts
CHANGED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import {
|
|
3
|
+
CommissionCalculationDto,
|
|
4
|
+
CommissionFiltersDto,
|
|
5
|
+
CommissionSummaryDto,
|
|
6
|
+
SimulateCommissionDto,
|
|
7
|
+
CommissionSimulationDto,
|
|
8
|
+
} from '../models/commissions';
|
|
9
|
+
import { RequestOptions, PaginatedResponseDto } from '../types';
|
|
10
|
+
|
|
11
|
+
export class CommissionCalculationsResource extends BaseResource {
|
|
12
|
+
private basePath = 'commissions/calculations';
|
|
13
|
+
|
|
14
|
+
async createCalculation(
|
|
15
|
+
data: { contractId: string; collaboratorId: string },
|
|
16
|
+
options?: RequestOptions,
|
|
17
|
+
): Promise<CommissionCalculationDto> {
|
|
18
|
+
return this.client.post<CommissionCalculationDto>(this.basePath, data, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getCalculation(id: string, options?: RequestOptions): Promise<CommissionCalculationDto> {
|
|
22
|
+
return this.client.get<CommissionCalculationDto>(`${this.basePath}/${id}`, undefined, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getCalculations(
|
|
26
|
+
params?: CommissionFiltersDto,
|
|
27
|
+
options?: RequestOptions,
|
|
28
|
+
): Promise<PaginatedResponseDto<CommissionCalculationDto>> {
|
|
29
|
+
return this.paginate<CommissionCalculationDto>(this.basePath, params, options);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getCollaboratorCalculations(
|
|
33
|
+
collaboratorId: string,
|
|
34
|
+
params?: CommissionFiltersDto,
|
|
35
|
+
options?: RequestOptions,
|
|
36
|
+
): Promise<PaginatedResponseDto<CommissionCalculationDto>> {
|
|
37
|
+
return this.paginate<CommissionCalculationDto>(
|
|
38
|
+
`${this.basePath}/collaborator/${collaboratorId}`,
|
|
39
|
+
params,
|
|
40
|
+
options,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async confirmCalculation(
|
|
45
|
+
id: string,
|
|
46
|
+
data: { note?: string },
|
|
47
|
+
options?: RequestOptions,
|
|
48
|
+
): Promise<CommissionCalculationDto> {
|
|
49
|
+
return this.client.put<CommissionCalculationDto>(
|
|
50
|
+
`${this.basePath}/${id}/confirm`,
|
|
51
|
+
data,
|
|
52
|
+
options,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async reverseCalculation(
|
|
57
|
+
id: string,
|
|
58
|
+
data: { reason: string },
|
|
59
|
+
options?: RequestOptions,
|
|
60
|
+
): Promise<CommissionCalculationDto> {
|
|
61
|
+
return this.client.put<CommissionCalculationDto>(
|
|
62
|
+
`${this.basePath}/${id}/reverse`,
|
|
63
|
+
data,
|
|
64
|
+
options,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async markAsPaid(
|
|
69
|
+
id: string,
|
|
70
|
+
data: { paidDate: string; note?: string },
|
|
71
|
+
options?: RequestOptions,
|
|
72
|
+
): Promise<CommissionCalculationDto> {
|
|
73
|
+
return this.client.put<CommissionCalculationDto>(`${this.basePath}/${id}/paid`, data, options);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async simulate(
|
|
77
|
+
data: SimulateCommissionDto,
|
|
78
|
+
options?: RequestOptions,
|
|
79
|
+
): Promise<CommissionSimulationDto> {
|
|
80
|
+
return this.client.post<CommissionSimulationDto>('commissions/simulator', data, options);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async getMyCommissions(
|
|
84
|
+
params?: CommissionFiltersDto,
|
|
85
|
+
options?: RequestOptions,
|
|
86
|
+
): Promise<PaginatedResponseDto<CommissionCalculationDto>> {
|
|
87
|
+
return this.paginate<CommissionCalculationDto>('commissions/me', params, options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getMyCommissionsSummary(options?: RequestOptions): Promise<CommissionSummaryDto> {
|
|
91
|
+
return this.client.get<CommissionSummaryDto>('commissions/me/summary', undefined, options);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import {
|
|
3
|
+
CommissionConfigDto,
|
|
4
|
+
CreateCommissionConfigDto,
|
|
5
|
+
UpdateCommissionConfigDto,
|
|
6
|
+
CommissionHistoryDto,
|
|
7
|
+
CommissionHistoryFiltersDto,
|
|
8
|
+
} from '../models/commissions';
|
|
9
|
+
import { RequestOptions, PaginatedResponseDto } from '../types';
|
|
10
|
+
|
|
11
|
+
export class CommissionConfigResource extends BaseResource {
|
|
12
|
+
private basePath = 'commissions/config';
|
|
13
|
+
|
|
14
|
+
async createConfig(
|
|
15
|
+
data: CreateCommissionConfigDto,
|
|
16
|
+
options?: RequestOptions,
|
|
17
|
+
): Promise<CommissionConfigDto> {
|
|
18
|
+
return this.client.post<CommissionConfigDto>(this.basePath, data, options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async getActiveConfig(options?: RequestOptions): Promise<CommissionConfigDto> {
|
|
22
|
+
return this.client.get<CommissionConfigDto>(`${this.basePath}/active`, undefined, options);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async getConfig(id: string, options?: RequestOptions): Promise<CommissionConfigDto> {
|
|
26
|
+
return this.client.get<CommissionConfigDto>(`${this.basePath}/${id}`, undefined, options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async listConfigs(
|
|
30
|
+
params?: { page: number; limit: number },
|
|
31
|
+
options?: RequestOptions,
|
|
32
|
+
): Promise<PaginatedResponseDto<CommissionConfigDto>> {
|
|
33
|
+
return this.paginate<CommissionConfigDto>(this.basePath, params, options);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async updateConfig(
|
|
37
|
+
id: string,
|
|
38
|
+
data: UpdateCommissionConfigDto,
|
|
39
|
+
options?: RequestOptions,
|
|
40
|
+
): Promise<CommissionConfigDto> {
|
|
41
|
+
return this.client.put<CommissionConfigDto>(`${this.basePath}/${id}`, data, options);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async deactivateConfig(id: string, options?: RequestOptions): Promise<CommissionConfigDto> {
|
|
45
|
+
return this.client.put<CommissionConfigDto>(`${this.basePath}/${id}/deactivate`, {}, options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getConfigHistory(
|
|
49
|
+
id: string,
|
|
50
|
+
params?: CommissionHistoryFiltersDto,
|
|
51
|
+
options?: RequestOptions,
|
|
52
|
+
): Promise<PaginatedResponseDto<CommissionHistoryDto>> {
|
|
53
|
+
return this.paginate<CommissionHistoryDto>(`${this.basePath}/${id}/history`, params, options);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async validateConfig(
|
|
57
|
+
data: CreateCommissionConfigDto,
|
|
58
|
+
options?: RequestOptions,
|
|
59
|
+
): Promise<{ valid: boolean; errors?: string[] }> {
|
|
60
|
+
return this.client.post<{ valid: boolean; errors?: string[] }>(
|
|
61
|
+
`${this.basePath}/validate`,
|
|
62
|
+
data,
|
|
63
|
+
options,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import {
|
|
3
|
+
CommissionRuleDto,
|
|
4
|
+
CreateCommissionRuleDto,
|
|
5
|
+
UpdateCommissionRuleDto,
|
|
6
|
+
CommissionRuleFiltersDto,
|
|
7
|
+
} from '../models/commissions';
|
|
8
|
+
import { RequestOptions, PaginatedResponseDto } from '../types';
|
|
9
|
+
|
|
10
|
+
export class CommissionPromotionsResource extends BaseResource {
|
|
11
|
+
private basePath = 'commissions/promotions';
|
|
12
|
+
|
|
13
|
+
async createPromotion(
|
|
14
|
+
data: CreateCommissionRuleDto,
|
|
15
|
+
options?: RequestOptions,
|
|
16
|
+
): Promise<CommissionRuleDto> {
|
|
17
|
+
return this.client.post<CommissionRuleDto>(this.basePath, data, options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getPromotion(id: string, options?: RequestOptions): Promise<CommissionRuleDto> {
|
|
21
|
+
return this.client.get<CommissionRuleDto>(`${this.basePath}/${id}`, undefined, options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async listPromotions(
|
|
25
|
+
params?: CommissionRuleFiltersDto,
|
|
26
|
+
options?: RequestOptions,
|
|
27
|
+
): Promise<PaginatedResponseDto<CommissionRuleDto>> {
|
|
28
|
+
return this.paginate<CommissionRuleDto>(this.basePath, params, options);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async updatePromotion(
|
|
32
|
+
id: string,
|
|
33
|
+
data: UpdateCommissionRuleDto,
|
|
34
|
+
options?: RequestOptions,
|
|
35
|
+
): Promise<CommissionRuleDto> {
|
|
36
|
+
return this.client.put<CommissionRuleDto>(`${this.basePath}/${id}`, data, options);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async deletePromotion(id: string, options?: RequestOptions): Promise<{ success: boolean }> {
|
|
40
|
+
return this.client.delete<{ success: boolean }>(`${this.basePath}/${id}`, options);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async activatePromotion(id: string, options?: RequestOptions): Promise<CommissionRuleDto> {
|
|
44
|
+
return this.client.put<CommissionRuleDto>(`${this.basePath}/${id}/activate`, {}, options);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async deactivatePromotion(id: string, options?: RequestOptions): Promise<CommissionRuleDto> {
|
|
48
|
+
return this.client.put<CommissionRuleDto>(`${this.basePath}/${id}/deactivate`, {}, options);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async validatePromotion(
|
|
52
|
+
data: CreateCommissionRuleDto,
|
|
53
|
+
options?: RequestOptions,
|
|
54
|
+
): Promise<{ valid: boolean; errors?: string[]; conflicts?: CommissionRuleDto[] }> {
|
|
55
|
+
return this.client.post<{ valid: boolean; errors?: string[]; conflicts?: CommissionRuleDto[] }>(
|
|
56
|
+
`${this.basePath}/validate`,
|
|
57
|
+
data,
|
|
58
|
+
options,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async estimateImpact(
|
|
63
|
+
id: string,
|
|
64
|
+
options?: RequestOptions,
|
|
65
|
+
): Promise<{
|
|
66
|
+
estimatedContracts: number;
|
|
67
|
+
estimatedCommissions: number;
|
|
68
|
+
estimatedCost: number;
|
|
69
|
+
}> {
|
|
70
|
+
return this.client.get<{
|
|
71
|
+
estimatedContracts: number;
|
|
72
|
+
estimatedCommissions: number;
|
|
73
|
+
estimatedCost: number;
|
|
74
|
+
}>(`${this.basePath}/${id}/impact`, undefined, options);
|
|
75
|
+
}
|
|
76
|
+
}
|