@forklaunch/implementation-billing-base 0.8.23 → 0.9.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/lib/domain/schemas/index.d.mts +8 -8
- package/lib/domain/schemas/index.d.ts +8 -8
- package/lib/domain/schemas/index.js +8 -8
- package/lib/domain/schemas/index.mjs +8 -8
- package/lib/domain/types/index.d.mts +272 -31
- package/lib/domain/types/index.d.ts +272 -31
- package/lib/eject/domain/schemas/plan.schema.ts +2 -2
- package/lib/eject/domain/schemas/subscription.schema.ts +2 -2
- package/lib/eject/domain/types/baseBillingEntity.types.ts +97 -46
- package/lib/eject/domain/types/billingPortal.mapper.types.ts +7 -4
- package/lib/eject/domain/types/checkoutSession.mapper.types.ts +7 -4
- package/lib/eject/domain/types/paymentLink.mapper.types.ts +7 -4
- package/lib/eject/domain/types/plan.mapper.types.ts +7 -4
- package/lib/eject/domain/types/subscription.mapper.types.ts +7 -4
- package/lib/eject/services/billingPortal.service.ts +8 -7
- package/lib/eject/services/checkoutSession.service.ts +24 -14
- package/lib/eject/services/paymentLink.service.ts +28 -19
- package/lib/eject/services/plan.service.ts +23 -10
- package/lib/eject/services/subscription.service.ts +56 -32
- package/lib/services/index.d.mts +3 -3
- package/lib/services/index.d.ts +3 -3
- package/lib/services/index.js +102 -56
- package/lib/services/index.mjs +102 -56
- package/package.json +8 -8
|
@@ -11,22 +11,23 @@ import {
|
|
|
11
11
|
UpdateSubscriptionDto
|
|
12
12
|
} from '@forklaunch/interfaces-billing/types';
|
|
13
13
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
14
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
14
|
+
import { EntityManager, InferEntity } from '@mikro-orm/core';
|
|
15
15
|
import { BaseSubscriptionDtos } from '../domain/types/baseBillingDto.types';
|
|
16
16
|
import { BaseSubscriptionEntities } from '../domain/types/baseBillingEntity.types';
|
|
17
17
|
import { SubscriptionMappers } from '../domain/types/subscription.mapper.types';
|
|
18
|
+
import { Subscription } from '../persistence/entities';
|
|
18
19
|
|
|
19
20
|
export class BaseSubscriptionService<
|
|
20
21
|
SchemaValidator extends AnySchemaValidator,
|
|
21
22
|
PartyType,
|
|
22
23
|
BillingProviderType,
|
|
23
|
-
|
|
24
|
-
Dto extends BaseSubscriptionDtos<
|
|
24
|
+
MapperEntities extends BaseSubscriptionEntities<
|
|
25
25
|
PartyType,
|
|
26
26
|
BillingProviderType
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
>,
|
|
28
|
+
Dto extends BaseSubscriptionDtos<PartyType, BillingProviderType> =
|
|
29
|
+
BaseSubscriptionDtos<PartyType, BillingProviderType>
|
|
30
|
+
> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
30
31
|
protected evaluatedTelemetryOptions: {
|
|
31
32
|
logging?: boolean;
|
|
32
33
|
metrics?: boolean;
|
|
@@ -38,7 +39,7 @@ export class BaseSubscriptionService<
|
|
|
38
39
|
protected readonly mappers: SubscriptionMappers<
|
|
39
40
|
PartyType,
|
|
40
41
|
BillingProviderType,
|
|
41
|
-
|
|
42
|
+
MapperEntities,
|
|
42
43
|
Dto
|
|
43
44
|
>;
|
|
44
45
|
|
|
@@ -46,7 +47,12 @@ export class BaseSubscriptionService<
|
|
|
46
47
|
em: EntityManager,
|
|
47
48
|
openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,
|
|
48
49
|
schemaValidator: SchemaValidator,
|
|
49
|
-
mappers: SubscriptionMappers<
|
|
50
|
+
mappers: SubscriptionMappers<
|
|
51
|
+
PartyType,
|
|
52
|
+
BillingProviderType,
|
|
53
|
+
MapperEntities,
|
|
54
|
+
Dto
|
|
55
|
+
>,
|
|
50
56
|
readonly options?: {
|
|
51
57
|
telemetry?: TelemetryOptions;
|
|
52
58
|
}
|
|
@@ -96,11 +102,11 @@ export class BaseSubscriptionService<
|
|
|
96
102
|
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
97
103
|
}
|
|
98
104
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
99
|
-
|
|
105
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
100
106
|
idDto
|
|
101
107
|
);
|
|
102
108
|
return this.mappers.SubscriptionMapper.toDto(
|
|
103
|
-
subscription as
|
|
109
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
104
110
|
);
|
|
105
111
|
}
|
|
106
112
|
|
|
@@ -111,14 +117,17 @@ export class BaseSubscriptionService<
|
|
|
111
117
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
112
118
|
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
113
119
|
}
|
|
114
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
121
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
122
|
+
{
|
|
123
|
+
partyId: id,
|
|
124
|
+
partyType: 'USER',
|
|
125
|
+
active: true
|
|
126
|
+
}
|
|
127
|
+
);
|
|
119
128
|
|
|
120
129
|
return this.mappers.SubscriptionMapper.toDto(
|
|
121
|
-
subscription as
|
|
130
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
122
131
|
);
|
|
123
132
|
}
|
|
124
133
|
|
|
@@ -129,13 +138,16 @@ export class BaseSubscriptionService<
|
|
|
129
138
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
130
139
|
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
131
140
|
}
|
|
132
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
142
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
143
|
+
{
|
|
144
|
+
partyId: id,
|
|
145
|
+
partyType: 'ORGANIZATION',
|
|
146
|
+
active: true
|
|
147
|
+
}
|
|
148
|
+
);
|
|
137
149
|
return this.mappers.SubscriptionMapper.toDto(
|
|
138
|
-
subscription as
|
|
150
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
139
151
|
);
|
|
140
152
|
}
|
|
141
153
|
|
|
@@ -172,11 +184,14 @@ export class BaseSubscriptionService<
|
|
|
172
184
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
173
185
|
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
174
186
|
}
|
|
175
|
-
const subscription = await (em ?? this.em).findOne(
|
|
187
|
+
const subscription = await (em ?? this.em).findOne(
|
|
188
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
189
|
+
idDto
|
|
190
|
+
);
|
|
176
191
|
if (!subscription) {
|
|
177
192
|
throw new Error('Subscription not found');
|
|
178
193
|
}
|
|
179
|
-
await (em ?? this.em).
|
|
194
|
+
await (em ?? this.em).remove(subscription).flush();
|
|
180
195
|
}
|
|
181
196
|
|
|
182
197
|
async listSubscriptions(
|
|
@@ -188,12 +203,15 @@ export class BaseSubscriptionService<
|
|
|
188
203
|
}
|
|
189
204
|
return Promise.all(
|
|
190
205
|
(
|
|
191
|
-
await (em ?? this.em).findAll(
|
|
192
|
-
|
|
193
|
-
|
|
206
|
+
await (em ?? this.em).findAll(
|
|
207
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
208
|
+
{
|
|
209
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
|
|
210
|
+
}
|
|
211
|
+
)
|
|
194
212
|
).map((subscription) =>
|
|
195
213
|
this.mappers.SubscriptionMapper.toDto(
|
|
196
|
-
subscription as
|
|
214
|
+
subscription as InferEntity<MapperEntities['SubscriptionMapper']>
|
|
197
215
|
)
|
|
198
216
|
)
|
|
199
217
|
);
|
|
@@ -203,11 +221,14 @@ export class BaseSubscriptionService<
|
|
|
203
221
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
204
222
|
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
205
223
|
}
|
|
206
|
-
const subscription = await (em ?? this.em).findOne(
|
|
224
|
+
const subscription = await (em ?? this.em).findOne(
|
|
225
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
226
|
+
idDto
|
|
227
|
+
);
|
|
207
228
|
if (!subscription) {
|
|
208
229
|
throw new Error('Subscription not found');
|
|
209
230
|
}
|
|
210
|
-
|
|
231
|
+
subscription.active = false;
|
|
211
232
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
212
233
|
await innerEm.persist(subscription);
|
|
213
234
|
});
|
|
@@ -217,11 +238,14 @@ export class BaseSubscriptionService<
|
|
|
217
238
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
218
239
|
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
219
240
|
}
|
|
220
|
-
const subscription = await (em ?? this.em).findOne(
|
|
241
|
+
const subscription = await (em ?? this.em).findOne(
|
|
242
|
+
this.mappers.SubscriptionMapper.entity as typeof Subscription,
|
|
243
|
+
idDto
|
|
244
|
+
);
|
|
221
245
|
if (!subscription) {
|
|
222
246
|
throw new Error('Subscription not found');
|
|
223
247
|
}
|
|
224
|
-
|
|
248
|
+
subscription.active = true;
|
|
225
249
|
await (em ?? this.em).transactional(async (innerEm) => {
|
|
226
250
|
await innerEm.persist(subscription);
|
|
227
251
|
});
|
package/lib/services/index.d.mts
CHANGED
|
@@ -89,7 +89,7 @@ declare class BasePlanService<SchemaValidator extends AnySchemaValidator, PlanCa
|
|
|
89
89
|
}, em?: EntityManager): Promise<void>;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType,
|
|
92
|
+
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType, MapperEntities extends BaseSubscriptionEntities<PartyType, BillingProviderType>, Dto extends BaseSubscriptionDtos<PartyType, BillingProviderType> = BaseSubscriptionDtos<PartyType, BillingProviderType>> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
93
93
|
readonly options?: {
|
|
94
94
|
telemetry?: TelemetryOptions;
|
|
95
95
|
} | undefined;
|
|
@@ -101,8 +101,8 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
|
|
|
101
101
|
protected em: EntityManager;
|
|
102
102
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
103
103
|
protected readonly schemaValidator: SchemaValidator;
|
|
104
|
-
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
-
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
104
|
+
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>;
|
|
105
|
+
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>, options?: {
|
|
106
106
|
telemetry?: TelemetryOptions;
|
|
107
107
|
} | undefined);
|
|
108
108
|
createSubscription(subscriptionDto: CreateSubscriptionDto<PartyType, BillingProviderType>, em?: EntityManager, ...args: unknown[]): Promise<Dto['SubscriptionMapper']>;
|
package/lib/services/index.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ declare class BasePlanService<SchemaValidator extends AnySchemaValidator, PlanCa
|
|
|
89
89
|
}, em?: EntityManager): Promise<void>;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType,
|
|
92
|
+
declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType, MapperEntities extends BaseSubscriptionEntities<PartyType, BillingProviderType>, Dto extends BaseSubscriptionDtos<PartyType, BillingProviderType> = BaseSubscriptionDtos<PartyType, BillingProviderType>> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
93
93
|
readonly options?: {
|
|
94
94
|
telemetry?: TelemetryOptions;
|
|
95
95
|
} | undefined;
|
|
@@ -101,8 +101,8 @@ declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator
|
|
|
101
101
|
protected em: EntityManager;
|
|
102
102
|
protected readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
|
|
103
103
|
protected readonly schemaValidator: SchemaValidator;
|
|
104
|
-
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
105
|
-
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType,
|
|
104
|
+
protected readonly mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>;
|
|
105
|
+
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, schemaValidator: SchemaValidator, mappers: SubscriptionMappers<PartyType, BillingProviderType, MapperEntities, Dto>, options?: {
|
|
106
106
|
telemetry?: TelemetryOptions;
|
|
107
107
|
} | undefined);
|
|
108
108
|
createSubscription(subscriptionDto: CreateSubscriptionDto<PartyType, BillingProviderType>, em?: EntityManager, ...args: unknown[]): Promise<Dto['SubscriptionMapper']>;
|
package/lib/services/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var BaseBillingPortalService = class {
|
|
|
68
68
|
...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
|
|
69
69
|
);
|
|
70
70
|
if (this.enableDatabaseBackup) {
|
|
71
|
-
await this.em.
|
|
71
|
+
await this.em.persist(billingPortal).flush();
|
|
72
72
|
}
|
|
73
73
|
const createdBillingPortalDto = await this.mappers.BillingPortalMapper.toDto(billingPortal);
|
|
74
74
|
await this.cache.putRecord({
|
|
@@ -112,9 +112,9 @@ var BaseBillingPortalService = class {
|
|
|
112
112
|
...args[0] instanceof import_core.EntityManager ? args.slice(1) : args
|
|
113
113
|
);
|
|
114
114
|
if (this.enableDatabaseBackup) {
|
|
115
|
-
await this.em.
|
|
115
|
+
await this.em.persist({
|
|
116
116
|
billingPortal
|
|
117
|
-
});
|
|
117
|
+
}).flush();
|
|
118
118
|
}
|
|
119
119
|
const updatedBillingPortalDto = {
|
|
120
120
|
...existingBillingPortal,
|
|
@@ -189,7 +189,7 @@ var BaseCheckoutSessionService = class {
|
|
|
189
189
|
);
|
|
190
190
|
const createdCheckoutSessionDto = await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
|
|
191
191
|
if (this.enableDatabaseBackup) {
|
|
192
|
-
await this.em.
|
|
192
|
+
await this.em.persist(checkoutSession).flush();
|
|
193
193
|
}
|
|
194
194
|
await this.cache.putRecord({
|
|
195
195
|
key: this.createCacheKey(createdCheckoutSessionDto.id),
|
|
@@ -226,11 +226,14 @@ var BaseCheckoutSessionService = class {
|
|
|
226
226
|
this.openTelemetryCollector.info("Checkout success", { id });
|
|
227
227
|
}
|
|
228
228
|
if (this.enableDatabaseBackup) {
|
|
229
|
-
const checkoutSession = await this.em.upsert(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
const checkoutSession = await this.em.upsert(
|
|
230
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
231
|
+
{
|
|
232
|
+
id,
|
|
233
|
+
status: "SUCCESS"
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
await this.em.persist(checkoutSession).flush();
|
|
234
237
|
}
|
|
235
238
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
236
239
|
}
|
|
@@ -239,11 +242,14 @@ var BaseCheckoutSessionService = class {
|
|
|
239
242
|
this.openTelemetryCollector.info("Checkout failure", { id });
|
|
240
243
|
}
|
|
241
244
|
if (this.enableDatabaseBackup) {
|
|
242
|
-
const checkoutSession = await this.em.upsert(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
245
|
+
const checkoutSession = await this.em.upsert(
|
|
246
|
+
this.mappers.CheckoutSessionMapper.entity,
|
|
247
|
+
{
|
|
248
|
+
id,
|
|
249
|
+
status: "FAILED"
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
await this.em.persist(checkoutSession).flush();
|
|
247
253
|
}
|
|
248
254
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
249
255
|
}
|
|
@@ -286,7 +292,7 @@ var BasePaymentLinkService = class {
|
|
|
286
292
|
...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
|
|
287
293
|
);
|
|
288
294
|
if (this.enableDatabaseBackup) {
|
|
289
|
-
await this.em.
|
|
295
|
+
await this.em.persist(paymentLink).flush();
|
|
290
296
|
}
|
|
291
297
|
const createdPaymentLinkDto = await this.mappers.PaymentLinkMapper.toDto(paymentLink);
|
|
292
298
|
await this.cache.putRecord({
|
|
@@ -311,7 +317,7 @@ var BasePaymentLinkService = class {
|
|
|
311
317
|
...args[0] instanceof import_core3.EntityManager ? args.slice(1) : args
|
|
312
318
|
);
|
|
313
319
|
if (this.enableDatabaseBackup) {
|
|
314
|
-
await this.em.
|
|
320
|
+
await this.em.persist(paymentLink).flush();
|
|
315
321
|
}
|
|
316
322
|
const updatedLinkDto = {
|
|
317
323
|
...existingLink,
|
|
@@ -340,33 +346,42 @@ var BasePaymentLinkService = class {
|
|
|
340
346
|
async expirePaymentLink({ id }) {
|
|
341
347
|
this.openTelemetryCollector.info("Payment link expired", { id });
|
|
342
348
|
if (this.enableDatabaseBackup) {
|
|
343
|
-
const paymentLink = await this.em.upsert(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
349
|
+
const paymentLink = await this.em.upsert(
|
|
350
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
351
|
+
{
|
|
352
|
+
id,
|
|
353
|
+
status: "EXPIRED"
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
await this.em.remove(paymentLink).flush();
|
|
348
357
|
}
|
|
349
358
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
350
359
|
}
|
|
351
360
|
async handlePaymentSuccess({ id }) {
|
|
352
361
|
this.openTelemetryCollector.info("Payment link success", { id });
|
|
353
362
|
if (this.enableDatabaseBackup) {
|
|
354
|
-
const paymentLink = await this.em.upsert(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
363
|
+
const paymentLink = await this.em.upsert(
|
|
364
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
365
|
+
{
|
|
366
|
+
id,
|
|
367
|
+
status: "COMPLETED"
|
|
368
|
+
}
|
|
369
|
+
);
|
|
370
|
+
await this.em.remove(paymentLink).flush();
|
|
359
371
|
}
|
|
360
372
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
361
373
|
}
|
|
362
374
|
async handlePaymentFailure({ id }) {
|
|
363
375
|
this.openTelemetryCollector.info("Payment link failure", { id });
|
|
364
376
|
if (this.enableDatabaseBackup) {
|
|
365
|
-
const paymentLink = await this.em.upsert(
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
377
|
+
const paymentLink = await this.em.upsert(
|
|
378
|
+
this.mappers.PaymentLinkMapper.entity,
|
|
379
|
+
{
|
|
380
|
+
id,
|
|
381
|
+
status: "FAILED"
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
await this.em.remove(paymentLink).flush();
|
|
370
385
|
}
|
|
371
386
|
await this.cache.deleteRecord(this.createCacheKey(id));
|
|
372
387
|
}
|
|
@@ -406,10 +421,15 @@ var BasePlanService = class {
|
|
|
406
421
|
this.openTelemetryCollector.info("Listing plans", idsDto);
|
|
407
422
|
}
|
|
408
423
|
return Promise.all(
|
|
409
|
-
(await (em ?? this.em).findAll(
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
424
|
+
(await (em ?? this.em).findAll(
|
|
425
|
+
this.mappers.PlanMapper.entity,
|
|
426
|
+
{
|
|
427
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
428
|
+
}
|
|
429
|
+
)).map(
|
|
430
|
+
(plan) => this.mappers.PlanMapper.toDto(
|
|
431
|
+
plan
|
|
432
|
+
)
|
|
413
433
|
)
|
|
414
434
|
);
|
|
415
435
|
}
|
|
@@ -431,8 +451,13 @@ var BasePlanService = class {
|
|
|
431
451
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
432
452
|
this.openTelemetryCollector.info("Getting plan", idDto);
|
|
433
453
|
}
|
|
434
|
-
const plan = await (em ?? this.em).findOneOrFail(
|
|
435
|
-
|
|
454
|
+
const plan = await (em ?? this.em).findOneOrFail(
|
|
455
|
+
this.mappers.PlanMapper.entity,
|
|
456
|
+
idDto
|
|
457
|
+
);
|
|
458
|
+
return this.mappers.PlanMapper.toDto(
|
|
459
|
+
plan
|
|
460
|
+
);
|
|
436
461
|
}
|
|
437
462
|
async updatePlan(planDto, em, ...args) {
|
|
438
463
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
@@ -454,7 +479,10 @@ var BasePlanService = class {
|
|
|
454
479
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
455
480
|
this.openTelemetryCollector.info("Deleting plan", idDto);
|
|
456
481
|
}
|
|
457
|
-
await (em ?? this.em).nativeDelete(
|
|
482
|
+
await (em ?? this.em).nativeDelete(
|
|
483
|
+
this.mappers.PlanMapper.entity,
|
|
484
|
+
idDto
|
|
485
|
+
);
|
|
458
486
|
}
|
|
459
487
|
};
|
|
460
488
|
|
|
@@ -502,7 +530,7 @@ var BaseSubscriptionService = class {
|
|
|
502
530
|
this.openTelemetryCollector.info("Getting subscription", idDto);
|
|
503
531
|
}
|
|
504
532
|
const subscription = await (em ?? this.em).findOneOrFail(
|
|
505
|
-
|
|
533
|
+
this.mappers.SubscriptionMapper.entity,
|
|
506
534
|
idDto
|
|
507
535
|
);
|
|
508
536
|
return this.mappers.SubscriptionMapper.toDto(
|
|
@@ -513,11 +541,14 @@ var BaseSubscriptionService = class {
|
|
|
513
541
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
514
542
|
this.openTelemetryCollector.info("Getting user subscription", id);
|
|
515
543
|
}
|
|
516
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
544
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
545
|
+
this.mappers.SubscriptionMapper.entity,
|
|
546
|
+
{
|
|
547
|
+
partyId: id,
|
|
548
|
+
partyType: "USER",
|
|
549
|
+
active: true
|
|
550
|
+
}
|
|
551
|
+
);
|
|
521
552
|
return this.mappers.SubscriptionMapper.toDto(
|
|
522
553
|
subscription
|
|
523
554
|
);
|
|
@@ -526,11 +557,14 @@ var BaseSubscriptionService = class {
|
|
|
526
557
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
527
558
|
this.openTelemetryCollector.info("Getting organization subscription", id);
|
|
528
559
|
}
|
|
529
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
560
|
+
const subscription = await (em ?? this.em).findOneOrFail(
|
|
561
|
+
this.mappers.SubscriptionMapper.entity,
|
|
562
|
+
{
|
|
563
|
+
partyId: id,
|
|
564
|
+
partyType: "ORGANIZATION",
|
|
565
|
+
active: true
|
|
566
|
+
}
|
|
567
|
+
);
|
|
534
568
|
return this.mappers.SubscriptionMapper.toDto(
|
|
535
569
|
subscription
|
|
536
570
|
);
|
|
@@ -558,20 +592,26 @@ var BaseSubscriptionService = class {
|
|
|
558
592
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
559
593
|
this.openTelemetryCollector.info("Deleting subscription", idDto);
|
|
560
594
|
}
|
|
561
|
-
const subscription = await (em ?? this.em).findOne(
|
|
595
|
+
const subscription = await (em ?? this.em).findOne(
|
|
596
|
+
this.mappers.SubscriptionMapper.entity,
|
|
597
|
+
idDto
|
|
598
|
+
);
|
|
562
599
|
if (!subscription) {
|
|
563
600
|
throw new Error("Subscription not found");
|
|
564
601
|
}
|
|
565
|
-
await (em ?? this.em).
|
|
602
|
+
await (em ?? this.em).remove(subscription).flush();
|
|
566
603
|
}
|
|
567
604
|
async listSubscriptions(idsDto, em) {
|
|
568
605
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
569
606
|
this.openTelemetryCollector.info("Listing subscriptions", idsDto);
|
|
570
607
|
}
|
|
571
608
|
return Promise.all(
|
|
572
|
-
(await (em ?? this.em).findAll(
|
|
573
|
-
|
|
574
|
-
|
|
609
|
+
(await (em ?? this.em).findAll(
|
|
610
|
+
this.mappers.SubscriptionMapper.entity,
|
|
611
|
+
{
|
|
612
|
+
where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : void 0
|
|
613
|
+
}
|
|
614
|
+
)).map(
|
|
575
615
|
(subscription) => this.mappers.SubscriptionMapper.toDto(
|
|
576
616
|
subscription
|
|
577
617
|
)
|
|
@@ -582,7 +622,10 @@ var BaseSubscriptionService = class {
|
|
|
582
622
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
583
623
|
this.openTelemetryCollector.info("Canceling subscription", idDto);
|
|
584
624
|
}
|
|
585
|
-
const subscription = await (em ?? this.em).findOne(
|
|
625
|
+
const subscription = await (em ?? this.em).findOne(
|
|
626
|
+
this.mappers.SubscriptionMapper.entity,
|
|
627
|
+
idDto
|
|
628
|
+
);
|
|
586
629
|
if (!subscription) {
|
|
587
630
|
throw new Error("Subscription not found");
|
|
588
631
|
}
|
|
@@ -595,7 +638,10 @@ var BaseSubscriptionService = class {
|
|
|
595
638
|
if (this.evaluatedTelemetryOptions.logging) {
|
|
596
639
|
this.openTelemetryCollector.info("Resuming subscription", idDto);
|
|
597
640
|
}
|
|
598
|
-
const subscription = await (em ?? this.em).findOne(
|
|
641
|
+
const subscription = await (em ?? this.em).findOne(
|
|
642
|
+
this.mappers.SubscriptionMapper.entity,
|
|
643
|
+
idDto
|
|
644
|
+
);
|
|
599
645
|
if (!subscription) {
|
|
600
646
|
throw new Error("Subscription not found");
|
|
601
647
|
}
|