@forklaunch/implementation-billing-base 0.2.3 → 0.3.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/schemas/index.d.mts +402 -0
- package/lib/schemas/index.d.ts +402 -6
- package/lib/schemas/index.js +498 -5
- package/lib/schemas/index.mjs +547 -0
- package/lib/services/index.d.mts +255 -0
- package/lib/services/index.d.ts +255 -6
- package/lib/services/index.js +610 -5
- package/lib/services/index.mjs +599 -0
- package/package.json +6 -5
- package/lib/__test__/schemaEquality.test.d.ts +0 -2
- package/lib/__test__/schemaEquality.test.d.ts.map +0 -1
- package/lib/__test__/schemaEquality.test.js +0 -430
- package/lib/jest.config.d.ts +0 -4
- package/lib/jest.config.d.ts.map +0 -1
- package/lib/jest.config.js +0 -19
- package/lib/schemas/billingPortal.schema.d.ts +0 -119
- package/lib/schemas/billingPortal.schema.d.ts.map +0 -1
- package/lib/schemas/billingPortal.schema.js +0 -7
- package/lib/schemas/checkoutSession.schema.d.ts +0 -265
- package/lib/schemas/checkoutSession.schema.d.ts.map +0 -1
- package/lib/schemas/checkoutSession.schema.js +0 -7
- package/lib/schemas/index.d.ts.map +0 -1
- package/lib/schemas/paymentLink.schema.d.ts +0 -319
- package/lib/schemas/paymentLink.schema.d.ts.map +0 -1
- package/lib/schemas/paymentLink.schema.js +0 -7
- package/lib/schemas/plan.schema.d.ts +0 -338
- package/lib/schemas/plan.schema.d.ts.map +0 -1
- package/lib/schemas/plan.schema.js +0 -7
- package/lib/schemas/subscription.schema.d.ts +0 -366
- package/lib/schemas/subscription.schema.d.ts.map +0 -1
- package/lib/schemas/subscription.schema.js +0 -7
- package/lib/schemas/typebox/billingPortal.schema.d.ts +0 -161
- package/lib/schemas/typebox/billingPortal.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/billingPortal.schema.js +0 -31
- package/lib/schemas/typebox/checkoutSession.schema.d.ts +0 -316
- package/lib/schemas/typebox/checkoutSession.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/checkoutSession.schema.js +0 -50
- package/lib/schemas/typebox/paymentLink.schema.d.ts +0 -406
- package/lib/schemas/typebox/paymentLink.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/paymentLink.schema.js +0 -55
- package/lib/schemas/typebox/plan.schema.d.ts +0 -408
- package/lib/schemas/typebox/plan.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/plan.schema.js +0 -57
- package/lib/schemas/typebox/subscription.schema.d.ts +0 -456
- package/lib/schemas/typebox/subscription.schema.d.ts.map +0 -1
- package/lib/schemas/typebox/subscription.schema.js +0 -61
- package/lib/schemas/zod/billingPortal.schema.d.ts +0 -63
- package/lib/schemas/zod/billingPortal.schema.d.ts.map +0 -1
- package/lib/schemas/zod/billingPortal.schema.js +0 -31
- package/lib/schemas/zod/checkoutSession.schema.d.ts +0 -176
- package/lib/schemas/zod/checkoutSession.schema.d.ts.map +0 -1
- package/lib/schemas/zod/checkoutSession.schema.js +0 -50
- package/lib/schemas/zod/paymentLink.schema.d.ts +0 -172
- package/lib/schemas/zod/paymentLink.schema.d.ts.map +0 -1
- package/lib/schemas/zod/paymentLink.schema.js +0 -55
- package/lib/schemas/zod/plan.schema.d.ts +0 -196
- package/lib/schemas/zod/plan.schema.d.ts.map +0 -1
- package/lib/schemas/zod/plan.schema.js +0 -57
- package/lib/schemas/zod/subscription.schema.d.ts +0 -204
- package/lib/schemas/zod/subscription.schema.d.ts.map +0 -1
- package/lib/schemas/zod/subscription.schema.js +0 -61
- package/lib/services/billingPortal.service.d.ts +0 -112
- package/lib/services/billingPortal.service.d.ts.map +0 -1
- package/lib/services/billingPortal.service.js +0 -128
- package/lib/services/checkoutSession.service.d.ts +0 -137
- package/lib/services/checkoutSession.service.d.ts.map +0 -1
- package/lib/services/checkoutSession.service.js +0 -111
- package/lib/services/index.d.ts.map +0 -1
- package/lib/services/paymentLink.service.d.ts +0 -118
- package/lib/services/paymentLink.service.d.ts.map +0 -1
- package/lib/services/paymentLink.service.js +0 -154
- package/lib/services/plan.service.d.ts +0 -102
- package/lib/services/plan.service.d.ts.map +0 -1
- package/lib/services/plan.service.js +0 -80
- package/lib/services/subscription.service.d.ts +0 -159
- package/lib/services/subscription.service.d.ts.map +0 -1
- package/lib/services/subscription.service.js +0 -169
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/vitest.config.d.ts +0 -3
- package/lib/vitest.config.d.ts.map +0 -1
- package/lib/vitest.config.js +0 -7
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
2
|
-
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
3
|
-
export class BasePlanService {
|
|
4
|
-
em;
|
|
5
|
-
openTelemetryCollector;
|
|
6
|
-
schemaValidator;
|
|
7
|
-
mappers;
|
|
8
|
-
options;
|
|
9
|
-
#mappers;
|
|
10
|
-
evaluatedTelemetryOptions;
|
|
11
|
-
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
12
|
-
this.em = em;
|
|
13
|
-
this.openTelemetryCollector = openTelemetryCollector;
|
|
14
|
-
this.schemaValidator = schemaValidator;
|
|
15
|
-
this.mappers = mappers;
|
|
16
|
-
this.options = options;
|
|
17
|
-
this.#mappers = transformIntoInternalDtoMapper(mappers, schemaValidator);
|
|
18
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
19
|
-
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
20
|
-
: {
|
|
21
|
-
logging: false,
|
|
22
|
-
metrics: false,
|
|
23
|
-
tracing: false
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async listPlans(idsDto, em) {
|
|
27
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
28
|
-
this.openTelemetryCollector.info('Listing plans', idsDto);
|
|
29
|
-
}
|
|
30
|
-
return Promise.all(
|
|
31
|
-
(
|
|
32
|
-
await (em ?? this.em).findAll('Plan', {
|
|
33
|
-
filters: idsDto?.ids ? { id: { $in: idsDto.ids } } : undefined
|
|
34
|
-
})
|
|
35
|
-
).map((plan) => this.#mappers.PlanDtoMapper.serializeEntityToDto(plan))
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
async createPlan(planDto, em) {
|
|
39
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
40
|
-
this.openTelemetryCollector.info('Creating plan', planDto);
|
|
41
|
-
}
|
|
42
|
-
const plan = await this.#mappers.CreatePlanDtoMapper.deserializeDtoToEntity(
|
|
43
|
-
planDto,
|
|
44
|
-
em ?? this.em
|
|
45
|
-
);
|
|
46
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
47
|
-
await innerEm.persist(plan);
|
|
48
|
-
});
|
|
49
|
-
return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
|
|
50
|
-
}
|
|
51
|
-
async getPlan(idDto, em) {
|
|
52
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
53
|
-
this.openTelemetryCollector.info('Getting plan', idDto);
|
|
54
|
-
}
|
|
55
|
-
const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
|
|
56
|
-
return this.#mappers.PlanDtoMapper.serializeEntityToDto(plan);
|
|
57
|
-
}
|
|
58
|
-
async updatePlan(planDto, em) {
|
|
59
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
60
|
-
this.openTelemetryCollector.info('Updating plan', planDto);
|
|
61
|
-
}
|
|
62
|
-
const plan = await this.#mappers.UpdatePlanDtoMapper.deserializeDtoToEntity(
|
|
63
|
-
planDto,
|
|
64
|
-
em ?? this.em
|
|
65
|
-
);
|
|
66
|
-
const updatedPlan = await (em ?? this.em).upsert(plan);
|
|
67
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
68
|
-
await innerEm.persist(plan);
|
|
69
|
-
});
|
|
70
|
-
const updatedPlanDto =
|
|
71
|
-
await this.#mappers.PlanDtoMapper.serializeEntityToDto(updatedPlan);
|
|
72
|
-
return updatedPlanDto;
|
|
73
|
-
}
|
|
74
|
-
async deletePlan(idDto, em) {
|
|
75
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
76
|
-
this.openTelemetryCollector.info('Deleting plan', idDto);
|
|
77
|
-
}
|
|
78
|
-
await (em ?? this.em).nativeDelete('Plan', idDto);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { IdDto } from '@forklaunch/common';
|
|
2
|
-
import {
|
|
3
|
-
MetricsDefinition,
|
|
4
|
-
OpenTelemetryCollector,
|
|
5
|
-
TelemetryOptions
|
|
6
|
-
} from '@forklaunch/core/http';
|
|
7
|
-
import {
|
|
8
|
-
RequestDtoMapperConstructor,
|
|
9
|
-
ResponseDtoMapperConstructor
|
|
10
|
-
} from '@forklaunch/core/mappers';
|
|
11
|
-
import { SubscriptionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
12
|
-
import {
|
|
13
|
-
CreateSubscriptionDto,
|
|
14
|
-
SubscriptionDto,
|
|
15
|
-
UpdateSubscriptionDto
|
|
16
|
-
} from '@forklaunch/interfaces-billing/types';
|
|
17
|
-
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
18
|
-
import { EntityManager } from '@mikro-orm/core';
|
|
19
|
-
export declare class BaseSubscriptionService<
|
|
20
|
-
SchemaValidator extends AnySchemaValidator,
|
|
21
|
-
PartyType,
|
|
22
|
-
BillingProviderType,
|
|
23
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
24
|
-
Dto extends {
|
|
25
|
-
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
26
|
-
CreateSubscriptionDtoMapper: CreateSubscriptionDto<
|
|
27
|
-
PartyType,
|
|
28
|
-
BillingProviderType
|
|
29
|
-
>;
|
|
30
|
-
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
|
|
31
|
-
PartyType,
|
|
32
|
-
BillingProviderType
|
|
33
|
-
>;
|
|
34
|
-
} = {
|
|
35
|
-
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
36
|
-
CreateSubscriptionDtoMapper: CreateSubscriptionDto<
|
|
37
|
-
PartyType,
|
|
38
|
-
BillingProviderType
|
|
39
|
-
>;
|
|
40
|
-
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
|
|
41
|
-
PartyType,
|
|
42
|
-
BillingProviderType
|
|
43
|
-
>;
|
|
44
|
-
},
|
|
45
|
-
Entities extends {
|
|
46
|
-
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
47
|
-
CreateSubscriptionDtoMapper: SubscriptionDto<
|
|
48
|
-
PartyType,
|
|
49
|
-
BillingProviderType
|
|
50
|
-
>;
|
|
51
|
-
UpdateSubscriptionDtoMapper: SubscriptionDto<
|
|
52
|
-
PartyType,
|
|
53
|
-
BillingProviderType
|
|
54
|
-
>;
|
|
55
|
-
} = {
|
|
56
|
-
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
57
|
-
CreateSubscriptionDtoMapper: SubscriptionDto<
|
|
58
|
-
PartyType,
|
|
59
|
-
BillingProviderType
|
|
60
|
-
>;
|
|
61
|
-
UpdateSubscriptionDtoMapper: SubscriptionDto<
|
|
62
|
-
PartyType,
|
|
63
|
-
BillingProviderType
|
|
64
|
-
>;
|
|
65
|
-
}
|
|
66
|
-
> implements SubscriptionService<PartyType, BillingProviderType>
|
|
67
|
-
{
|
|
68
|
-
#private;
|
|
69
|
-
protected em: EntityManager;
|
|
70
|
-
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
71
|
-
protected readonly schemaValidator: SchemaValidator;
|
|
72
|
-
protected readonly mappers: {
|
|
73
|
-
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
74
|
-
SchemaValidator,
|
|
75
|
-
Dto['SubscriptionDtoMapper'],
|
|
76
|
-
Entities['SubscriptionDtoMapper']
|
|
77
|
-
>;
|
|
78
|
-
CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
79
|
-
SchemaValidator,
|
|
80
|
-
Dto['CreateSubscriptionDtoMapper'],
|
|
81
|
-
Entities['CreateSubscriptionDtoMapper']
|
|
82
|
-
>;
|
|
83
|
-
UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
84
|
-
SchemaValidator,
|
|
85
|
-
Dto['UpdateSubscriptionDtoMapper'],
|
|
86
|
-
Entities['UpdateSubscriptionDtoMapper']
|
|
87
|
-
>;
|
|
88
|
-
};
|
|
89
|
-
readonly options?:
|
|
90
|
-
| {
|
|
91
|
-
enableDatabaseBackup?: boolean;
|
|
92
|
-
telemetry?: TelemetryOptions;
|
|
93
|
-
}
|
|
94
|
-
| undefined;
|
|
95
|
-
private evaluatedTelemetryOptions;
|
|
96
|
-
constructor(
|
|
97
|
-
em: EntityManager,
|
|
98
|
-
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
99
|
-
schemaValidator: SchemaValidator,
|
|
100
|
-
mappers: {
|
|
101
|
-
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
102
|
-
SchemaValidator,
|
|
103
|
-
Dto['SubscriptionDtoMapper'],
|
|
104
|
-
Entities['SubscriptionDtoMapper']
|
|
105
|
-
>;
|
|
106
|
-
CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
107
|
-
SchemaValidator,
|
|
108
|
-
Dto['CreateSubscriptionDtoMapper'],
|
|
109
|
-
Entities['CreateSubscriptionDtoMapper']
|
|
110
|
-
>;
|
|
111
|
-
UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
112
|
-
SchemaValidator,
|
|
113
|
-
Dto['UpdateSubscriptionDtoMapper'],
|
|
114
|
-
Entities['UpdateSubscriptionDtoMapper']
|
|
115
|
-
>;
|
|
116
|
-
},
|
|
117
|
-
options?:
|
|
118
|
-
| {
|
|
119
|
-
enableDatabaseBackup?: boolean;
|
|
120
|
-
telemetry?: TelemetryOptions;
|
|
121
|
-
}
|
|
122
|
-
| undefined
|
|
123
|
-
);
|
|
124
|
-
createSubscription(
|
|
125
|
-
subscriptionDto: Dto['CreateSubscriptionDtoMapper'],
|
|
126
|
-
em?: EntityManager
|
|
127
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
128
|
-
getSubscription(
|
|
129
|
-
idDto: IdDto,
|
|
130
|
-
em?: EntityManager
|
|
131
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
132
|
-
getUserSubscription(
|
|
133
|
-
{ id }: IdDto,
|
|
134
|
-
em?: EntityManager
|
|
135
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
136
|
-
getOrganizationSubscription(
|
|
137
|
-
{ id }: IdDto,
|
|
138
|
-
em?: EntityManager
|
|
139
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
140
|
-
updateSubscription(
|
|
141
|
-
subscriptionDto: Dto['UpdateSubscriptionDtoMapper'],
|
|
142
|
-
em?: EntityManager
|
|
143
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
144
|
-
deleteSubscription(
|
|
145
|
-
idDto: {
|
|
146
|
-
id: string;
|
|
147
|
-
},
|
|
148
|
-
em?: EntityManager
|
|
149
|
-
): Promise<void>;
|
|
150
|
-
listSubscriptions(
|
|
151
|
-
idsDto: {
|
|
152
|
-
ids?: string[];
|
|
153
|
-
},
|
|
154
|
-
em?: EntityManager
|
|
155
|
-
): Promise<Dto['SubscriptionDtoMapper'][]>;
|
|
156
|
-
cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
157
|
-
resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
158
|
-
}
|
|
159
|
-
//# sourceMappingURL=subscription.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.service.d.ts","sourceRoot":"","sources":["../../services/subscription.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAC/D,OA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AK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnE,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAa1E"}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { evaluateTelemetryOptions } from '@forklaunch/core/http';
|
|
2
|
-
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
3
|
-
export class BaseSubscriptionService {
|
|
4
|
-
em;
|
|
5
|
-
openTelemetryCollector;
|
|
6
|
-
schemaValidator;
|
|
7
|
-
mappers;
|
|
8
|
-
options;
|
|
9
|
-
#mappers;
|
|
10
|
-
evaluatedTelemetryOptions;
|
|
11
|
-
constructor(em, openTelemetryCollector, schemaValidator, mappers, options) {
|
|
12
|
-
this.em = em;
|
|
13
|
-
this.openTelemetryCollector = openTelemetryCollector;
|
|
14
|
-
this.schemaValidator = schemaValidator;
|
|
15
|
-
this.mappers = mappers;
|
|
16
|
-
this.options = options;
|
|
17
|
-
this.#mappers = transformIntoInternalDtoMapper(
|
|
18
|
-
mappers,
|
|
19
|
-
this.schemaValidator
|
|
20
|
-
);
|
|
21
|
-
this.evaluatedTelemetryOptions = options?.telemetry
|
|
22
|
-
? evaluateTelemetryOptions(options.telemetry).enabled
|
|
23
|
-
: {
|
|
24
|
-
logging: false,
|
|
25
|
-
metrics: false,
|
|
26
|
-
tracing: false
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
async createSubscription(subscriptionDto, em) {
|
|
30
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
31
|
-
this.openTelemetryCollector.info(
|
|
32
|
-
'Creating subscription',
|
|
33
|
-
subscriptionDto
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
const subscription =
|
|
37
|
-
await this.#mappers.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
38
|
-
subscriptionDto,
|
|
39
|
-
em ?? this.em
|
|
40
|
-
);
|
|
41
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
42
|
-
await innerEm.persist(subscription);
|
|
43
|
-
});
|
|
44
|
-
const createdSubscriptionDto =
|
|
45
|
-
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
46
|
-
subscription
|
|
47
|
-
);
|
|
48
|
-
return createdSubscriptionDto;
|
|
49
|
-
}
|
|
50
|
-
async getSubscription(idDto, em) {
|
|
51
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
52
|
-
this.openTelemetryCollector.info('Getting subscription', idDto);
|
|
53
|
-
}
|
|
54
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
55
|
-
'Subscription',
|
|
56
|
-
idDto
|
|
57
|
-
);
|
|
58
|
-
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
59
|
-
subscription
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
async getUserSubscription({ id }, em) {
|
|
63
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
64
|
-
this.openTelemetryCollector.info('Getting user subscription', id);
|
|
65
|
-
}
|
|
66
|
-
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
67
|
-
partyId: id,
|
|
68
|
-
partyType: 'USER',
|
|
69
|
-
active: true
|
|
70
|
-
});
|
|
71
|
-
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
72
|
-
subscription
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
async getOrganizationSubscription({ id }, em) {
|
|
76
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
77
|
-
this.openTelemetryCollector.info('Getting organization subscription', id);
|
|
78
|
-
}
|
|
79
|
-
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
80
|
-
partyId: id,
|
|
81
|
-
partyType: 'ORGANIZATION',
|
|
82
|
-
active: true
|
|
83
|
-
});
|
|
84
|
-
return this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
85
|
-
subscription
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
async updateSubscription(subscriptionDto, em) {
|
|
89
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
90
|
-
this.openTelemetryCollector.info(
|
|
91
|
-
'Updating subscription',
|
|
92
|
-
subscriptionDto
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
const subscription =
|
|
96
|
-
this.#mappers.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
97
|
-
subscriptionDto,
|
|
98
|
-
em ?? this.em
|
|
99
|
-
);
|
|
100
|
-
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
101
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
102
|
-
await innerEm.persist(updatedSubscription);
|
|
103
|
-
});
|
|
104
|
-
const updatedSubscriptionDto =
|
|
105
|
-
await this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
106
|
-
updatedSubscription
|
|
107
|
-
);
|
|
108
|
-
return updatedSubscriptionDto;
|
|
109
|
-
}
|
|
110
|
-
async deleteSubscription(idDto, em) {
|
|
111
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
112
|
-
this.openTelemetryCollector.info('Deleting subscription', idDto);
|
|
113
|
-
}
|
|
114
|
-
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
115
|
-
if (!subscription) {
|
|
116
|
-
throw new Error('Subscription not found');
|
|
117
|
-
}
|
|
118
|
-
await (em ?? this.em).removeAndFlush(subscription);
|
|
119
|
-
}
|
|
120
|
-
async listSubscriptions(idsDto, em) {
|
|
121
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
122
|
-
this.openTelemetryCollector.info('Listing subscriptions', idsDto);
|
|
123
|
-
}
|
|
124
|
-
const subscriptions = await (em ?? this.em).findAll('Subscription', {
|
|
125
|
-
where: idsDto.ids
|
|
126
|
-
? {
|
|
127
|
-
id: {
|
|
128
|
-
$in: idsDto.ids
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
: undefined
|
|
132
|
-
});
|
|
133
|
-
return Promise.all(
|
|
134
|
-
subscriptions.map((subscription) => {
|
|
135
|
-
const subscriptionDto =
|
|
136
|
-
this.#mappers.SubscriptionDtoMapper.serializeEntityToDto(
|
|
137
|
-
subscription
|
|
138
|
-
);
|
|
139
|
-
return subscriptionDto;
|
|
140
|
-
})
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
async cancelSubscription(idDto, em) {
|
|
144
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
145
|
-
this.openTelemetryCollector.info('Canceling subscription', idDto);
|
|
146
|
-
}
|
|
147
|
-
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
148
|
-
if (!subscription) {
|
|
149
|
-
throw new Error('Subscription not found');
|
|
150
|
-
}
|
|
151
|
-
subscription.active = false;
|
|
152
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
153
|
-
await innerEm.persist(subscription);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async resumeSubscription(idDto, em) {
|
|
157
|
-
if (this.evaluatedTelemetryOptions.logging) {
|
|
158
|
-
this.openTelemetryCollector.info('Resuming subscription', idDto);
|
|
159
|
-
}
|
|
160
|
-
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
161
|
-
if (!subscription) {
|
|
162
|
-
throw new Error('Subscription not found');
|
|
163
|
-
}
|
|
164
|
-
subscription.active = true;
|
|
165
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
166
|
-
await innerEm.persist(subscription);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|