@forklaunch/implementation-billing-base 0.1.11 → 0.1.13
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/__test__/schemaEquality.test.d.ts +1 -1
- package/lib/__test__/schemaEquality.test.js +146 -305
- package/lib/eject/domain/schemas/billingPortal.schema.ts +7 -1
- package/lib/jest.config.d.ts +1 -1
- package/lib/jest.config.js +16 -16
- package/lib/schemas/billingPortal.schema.d.ts +34 -107
- package/lib/schemas/billingPortal.schema.js +1 -4
- package/lib/schemas/checkoutSession.schema.d.ts +54 -169
- package/lib/schemas/checkoutSession.schema.js +1 -4
- package/lib/schemas/index.d.ts +1 -1
- package/lib/schemas/paymentLink.schema.d.ts +64 -210
- package/lib/schemas/paymentLink.schema.js +1 -4
- package/lib/schemas/plan.schema.d.ts +76 -326
- package/lib/schemas/plan.schema.js +1 -4
- package/lib/schemas/subscription.schema.d.ts +88 -364
- package/lib/schemas/subscription.schema.js +1 -4
- package/lib/schemas/typebox/billingPortal.schema.d.ts +38 -172
- package/lib/schemas/typebox/billingPortal.schema.js +17 -23
- package/lib/schemas/typebox/checkoutSession.schema.d.ts +55 -197
- package/lib/schemas/typebox/checkoutSession.schema.js +13 -25
- package/lib/schemas/typebox/paymentLink.schema.d.ts +65 -275
- package/lib/schemas/typebox/paymentLink.schema.js +15 -27
- package/lib/schemas/typebox/plan.schema.d.ts +77 -409
- package/lib/schemas/typebox/plan.schema.js +17 -31
- package/lib/schemas/typebox/subscription.schema.d.ts +89 -481
- package/lib/schemas/typebox/subscription.schema.js +19 -31
- package/lib/schemas/zod/billingPortal.schema.d.ts +38 -42
- package/lib/schemas/zod/billingPortal.schema.js +17 -23
- package/lib/schemas/zod/checkoutSession.schema.d.ts +55 -107
- package/lib/schemas/zod/checkoutSession.schema.js +13 -25
- package/lib/schemas/zod/paymentLink.schema.d.ts +65 -99
- package/lib/schemas/zod/paymentLink.schema.js +15 -27
- package/lib/schemas/zod/plan.schema.d.ts +77 -177
- package/lib/schemas/zod/plan.schema.js +17 -31
- package/lib/schemas/zod/subscription.schema.d.ts +89 -181
- package/lib/schemas/zod/subscription.schema.js +19 -31
- package/lib/services/billingPortal.service.d.ts +28 -77
- package/lib/services/billingPortal.service.js +45 -64
- package/lib/services/checkoutSession.service.d.ts +29 -77
- package/lib/services/checkoutSession.service.js +43 -54
- package/lib/services/index.d.ts +1 -1
- package/lib/services/paymentLink.service.d.ts +32 -82
- package/lib/services/paymentLink.service.js +66 -84
- package/lib/services/plan.service.d.ts +26 -73
- package/lib/services/plan.service.js +40 -45
- package/lib/services/subscription.service.d.ts +44 -136
- package/lib/services/subscription.service.js +88 -111
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/vitest.config.d.ts +2 -2
- package/lib/vitest.config.js +4 -4
- package/package.json +5 -5
|
@@ -1,145 +1,53 @@
|
|
|
1
1
|
import { IdDto } from '@forklaunch/common';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
ResponseDtoMapperConstructor
|
|
5
|
-
} from '@forklaunch/core/mappers';
|
|
6
|
-
import {
|
|
7
|
-
MetricsDefinition,
|
|
8
|
-
OpenTelemetryCollector
|
|
9
|
-
} from '@forklaunch/core/http';
|
|
2
|
+
import { RequestDtoMapperConstructor, ResponseDtoMapperConstructor } from '@forklaunch/core/mappers';
|
|
3
|
+
import { MetricsDefinition, OpenTelemetryCollector } from '@forklaunch/core/http';
|
|
10
4
|
import { SubscriptionService } from '@forklaunch/interfaces-billing/interfaces';
|
|
11
|
-
import {
|
|
12
|
-
CreateSubscriptionDto,
|
|
13
|
-
SubscriptionDto,
|
|
14
|
-
UpdateSubscriptionDto
|
|
15
|
-
} from '@forklaunch/interfaces-billing/types';
|
|
5
|
+
import { CreateSubscriptionDto, SubscriptionDto, UpdateSubscriptionDto } from '@forklaunch/interfaces-billing/types';
|
|
16
6
|
import { AnySchemaValidator } from '@forklaunch/validator';
|
|
17
7
|
import { EntityManager } from '@mikro-orm/core';
|
|
18
|
-
export declare class BaseSubscriptionService<
|
|
19
|
-
SchemaValidator extends AnySchemaValidator,
|
|
20
|
-
PartyType,
|
|
21
|
-
BillingProviderType,
|
|
22
|
-
Metrics extends MetricsDefinition = MetricsDefinition,
|
|
23
|
-
Dto extends {
|
|
8
|
+
export declare class BaseSubscriptionService<SchemaValidator extends AnySchemaValidator, PartyType, BillingProviderType, Metrics extends MetricsDefinition = MetricsDefinition, Dto extends {
|
|
24
9
|
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
25
|
-
CreateSubscriptionDtoMapper: CreateSubscriptionDto<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
>;
|
|
29
|
-
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
|
|
30
|
-
PartyType,
|
|
31
|
-
BillingProviderType
|
|
32
|
-
>;
|
|
33
|
-
} = {
|
|
10
|
+
CreateSubscriptionDtoMapper: CreateSubscriptionDto<PartyType, BillingProviderType>;
|
|
11
|
+
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<PartyType, BillingProviderType>;
|
|
12
|
+
} = {
|
|
34
13
|
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
35
|
-
CreateSubscriptionDtoMapper: CreateSubscriptionDto<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>;
|
|
39
|
-
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<
|
|
40
|
-
PartyType,
|
|
41
|
-
BillingProviderType
|
|
42
|
-
>;
|
|
43
|
-
},
|
|
44
|
-
Entities extends {
|
|
14
|
+
CreateSubscriptionDtoMapper: CreateSubscriptionDto<PartyType, BillingProviderType>;
|
|
15
|
+
UpdateSubscriptionDtoMapper: UpdateSubscriptionDto<PartyType, BillingProviderType>;
|
|
16
|
+
}, Entities extends {
|
|
45
17
|
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
46
|
-
CreateSubscriptionDtoMapper: SubscriptionDto<
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
>;
|
|
50
|
-
UpdateSubscriptionDtoMapper: SubscriptionDto<
|
|
51
|
-
PartyType,
|
|
52
|
-
BillingProviderType
|
|
53
|
-
>;
|
|
54
|
-
} = {
|
|
18
|
+
CreateSubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
19
|
+
UpdateSubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
20
|
+
} = {
|
|
55
21
|
SubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
56
|
-
CreateSubscriptionDtoMapper: SubscriptionDto<
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
>;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
>;
|
|
87
|
-
};
|
|
88
|
-
constructor(
|
|
89
|
-
em: EntityManager,
|
|
90
|
-
openTelemetryCollector: OpenTelemetryCollector<Metrics>,
|
|
91
|
-
schemaValidator: SchemaValidator,
|
|
92
|
-
mapperss: {
|
|
93
|
-
SubscriptionDtoMapper: ResponseDtoMapperConstructor<
|
|
94
|
-
SchemaValidator,
|
|
95
|
-
Dto['SubscriptionDtoMapper'],
|
|
96
|
-
Entities['SubscriptionDtoMapper']
|
|
97
|
-
>;
|
|
98
|
-
CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
99
|
-
SchemaValidator,
|
|
100
|
-
Dto['CreateSubscriptionDtoMapper'],
|
|
101
|
-
Entities['CreateSubscriptionDtoMapper']
|
|
102
|
-
>;
|
|
103
|
-
UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<
|
|
104
|
-
SchemaValidator,
|
|
105
|
-
Dto['UpdateSubscriptionDtoMapper'],
|
|
106
|
-
Entities['UpdateSubscriptionDtoMapper']
|
|
107
|
-
>;
|
|
108
|
-
}
|
|
109
|
-
);
|
|
110
|
-
createSubscription(
|
|
111
|
-
subscriptionDto: Dto['CreateSubscriptionDtoMapper'],
|
|
112
|
-
em?: EntityManager
|
|
113
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
114
|
-
getSubscription(
|
|
115
|
-
idDto: IdDto,
|
|
116
|
-
em?: EntityManager
|
|
117
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
118
|
-
getUserSubscription(
|
|
119
|
-
{ id }: IdDto,
|
|
120
|
-
em?: EntityManager
|
|
121
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
122
|
-
getOrganizationSubscription(
|
|
123
|
-
{ id }: IdDto,
|
|
124
|
-
em?: EntityManager
|
|
125
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
126
|
-
updateSubscription(
|
|
127
|
-
subscriptionDto: Dto['UpdateSubscriptionDtoMapper'],
|
|
128
|
-
em?: EntityManager
|
|
129
|
-
): Promise<Dto['SubscriptionDtoMapper']>;
|
|
130
|
-
deleteSubscription(
|
|
131
|
-
idDto: {
|
|
132
|
-
id: string;
|
|
133
|
-
},
|
|
134
|
-
em?: EntityManager
|
|
135
|
-
): Promise<void>;
|
|
136
|
-
listSubscriptions(
|
|
137
|
-
idsDto: {
|
|
138
|
-
ids?: string[];
|
|
139
|
-
},
|
|
140
|
-
em?: EntityManager
|
|
141
|
-
): Promise<Dto['SubscriptionDtoMapper'][]>;
|
|
142
|
-
cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
143
|
-
resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
22
|
+
CreateSubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
23
|
+
UpdateSubscriptionDtoMapper: SubscriptionDto<PartyType, BillingProviderType>;
|
|
24
|
+
}> implements SubscriptionService<PartyType, BillingProviderType> {
|
|
25
|
+
#private;
|
|
26
|
+
protected em: EntityManager;
|
|
27
|
+
protected readonly openTelemetryCollector: OpenTelemetryCollector<Metrics>;
|
|
28
|
+
protected readonly schemaValidator: SchemaValidator;
|
|
29
|
+
protected readonly mapperss: {
|
|
30
|
+
SubscriptionDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['SubscriptionDtoMapper'], Entities['SubscriptionDtoMapper']>;
|
|
31
|
+
CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateSubscriptionDtoMapper'], Entities['CreateSubscriptionDtoMapper']>;
|
|
32
|
+
UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateSubscriptionDtoMapper'], Entities['UpdateSubscriptionDtoMapper']>;
|
|
33
|
+
};
|
|
34
|
+
constructor(em: EntityManager, openTelemetryCollector: OpenTelemetryCollector<Metrics>, schemaValidator: SchemaValidator, mapperss: {
|
|
35
|
+
SubscriptionDtoMapper: ResponseDtoMapperConstructor<SchemaValidator, Dto['SubscriptionDtoMapper'], Entities['SubscriptionDtoMapper']>;
|
|
36
|
+
CreateSubscriptionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['CreateSubscriptionDtoMapper'], Entities['CreateSubscriptionDtoMapper']>;
|
|
37
|
+
UpdateSubscriptionDtoMapper: RequestDtoMapperConstructor<SchemaValidator, Dto['UpdateSubscriptionDtoMapper'], Entities['UpdateSubscriptionDtoMapper']>;
|
|
38
|
+
});
|
|
39
|
+
createSubscription(subscriptionDto: Dto['CreateSubscriptionDtoMapper'], em?: EntityManager): Promise<Dto['SubscriptionDtoMapper']>;
|
|
40
|
+
getSubscription(idDto: IdDto, em?: EntityManager): Promise<Dto['SubscriptionDtoMapper']>;
|
|
41
|
+
getUserSubscription({ id }: IdDto, em?: EntityManager): Promise<Dto['SubscriptionDtoMapper']>;
|
|
42
|
+
getOrganizationSubscription({ id }: IdDto, em?: EntityManager): Promise<Dto['SubscriptionDtoMapper']>;
|
|
43
|
+
updateSubscription(subscriptionDto: Dto['UpdateSubscriptionDtoMapper'], em?: EntityManager): Promise<Dto['SubscriptionDtoMapper']>;
|
|
44
|
+
deleteSubscription(idDto: {
|
|
45
|
+
id: string;
|
|
46
|
+
}, em?: EntityManager): Promise<void>;
|
|
47
|
+
listSubscriptions(idsDto: {
|
|
48
|
+
ids?: string[];
|
|
49
|
+
}, em?: EntityManager): Promise<Dto['SubscriptionDtoMapper'][]>;
|
|
50
|
+
cancelSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
51
|
+
resumeSubscription(idDto: IdDto, em?: EntityManager): Promise<void>;
|
|
144
52
|
}
|
|
145
|
-
//# sourceMappingURL=subscription.service.d.ts.map
|
|
53
|
+
//# sourceMappingURL=subscription.service.d.ts.map
|
|
@@ -1,117 +1,94 @@
|
|
|
1
1
|
import { transformIntoInternalDtoMapper } from '@forklaunch/core/mappers';
|
|
2
2
|
export class BaseSubscriptionService {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mapperss,
|
|
15
|
-
this.schemaValidator
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
async createSubscription(subscriptionDto, em) {
|
|
19
|
-
const subscription =
|
|
20
|
-
this.#mapperss.CreateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
21
|
-
subscriptionDto
|
|
22
|
-
);
|
|
23
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
24
|
-
await innerEm.persist(subscription);
|
|
25
|
-
});
|
|
26
|
-
const createdSubscriptionDto =
|
|
27
|
-
this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
28
|
-
return createdSubscriptionDto;
|
|
29
|
-
}
|
|
30
|
-
async getSubscription(idDto, em) {
|
|
31
|
-
const subscription = await (em ?? this.em).findOneOrFail(
|
|
32
|
-
'Subscription',
|
|
33
|
-
idDto
|
|
34
|
-
);
|
|
35
|
-
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(
|
|
36
|
-
subscription
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
async getUserSubscription({ id }, em) {
|
|
40
|
-
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
41
|
-
partyId: id,
|
|
42
|
-
partyType: 'USER',
|
|
43
|
-
active: true
|
|
44
|
-
});
|
|
45
|
-
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(
|
|
46
|
-
subscription
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
async getOrganizationSubscription({ id }, em) {
|
|
50
|
-
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
51
|
-
partyId: id,
|
|
52
|
-
partyType: 'ORGANIZATION',
|
|
53
|
-
active: true
|
|
54
|
-
});
|
|
55
|
-
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(
|
|
56
|
-
subscription
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
async updateSubscription(subscriptionDto, em) {
|
|
60
|
-
const subscription =
|
|
61
|
-
this.#mapperss.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(
|
|
62
|
-
subscriptionDto
|
|
63
|
-
);
|
|
64
|
-
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
65
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
66
|
-
await innerEm.persist(updatedSubscription);
|
|
67
|
-
});
|
|
68
|
-
const updatedSubscriptionDto =
|
|
69
|
-
this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(
|
|
70
|
-
updatedSubscription
|
|
71
|
-
);
|
|
72
|
-
return updatedSubscriptionDto;
|
|
73
|
-
}
|
|
74
|
-
async deleteSubscription(idDto, em) {
|
|
75
|
-
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
76
|
-
if (!subscription) {
|
|
77
|
-
throw new Error('Subscription not found');
|
|
3
|
+
em;
|
|
4
|
+
openTelemetryCollector;
|
|
5
|
+
schemaValidator;
|
|
6
|
+
mapperss;
|
|
7
|
+
#mapperss;
|
|
8
|
+
constructor(em, openTelemetryCollector, schemaValidator, mapperss) {
|
|
9
|
+
this.em = em;
|
|
10
|
+
this.openTelemetryCollector = openTelemetryCollector;
|
|
11
|
+
this.schemaValidator = schemaValidator;
|
|
12
|
+
this.mapperss = mapperss;
|
|
13
|
+
this.#mapperss = transformIntoInternalDtoMapper(mapperss, this.schemaValidator);
|
|
78
14
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
$in: idsDto.ids
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
: undefined
|
|
90
|
-
});
|
|
91
|
-
return subscriptions.map((subscription) => {
|
|
92
|
-
const subscriptionDto =
|
|
93
|
-
this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
94
|
-
return subscriptionDto;
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
async cancelSubscription(idDto, em) {
|
|
98
|
-
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
99
|
-
if (!subscription) {
|
|
100
|
-
throw new Error('Subscription not found');
|
|
15
|
+
async createSubscription(subscriptionDto, em) {
|
|
16
|
+
const subscription = this.#mapperss.CreateSubscriptionDtoMapper.deserializeDtoToEntity(subscriptionDto);
|
|
17
|
+
await (em ?? this.em).transactional(async (innerEm) => {
|
|
18
|
+
await innerEm.persist(subscription);
|
|
19
|
+
});
|
|
20
|
+
const createdSubscriptionDto = this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
21
|
+
return createdSubscriptionDto;
|
|
101
22
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
23
|
+
async getSubscription(idDto, em) {
|
|
24
|
+
const subscription = await (em ?? this.em).findOneOrFail('Subscription', idDto);
|
|
25
|
+
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
26
|
+
}
|
|
27
|
+
async getUserSubscription({ id }, em) {
|
|
28
|
+
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
29
|
+
partyId: id,
|
|
30
|
+
partyType: 'USER',
|
|
31
|
+
active: true
|
|
32
|
+
});
|
|
33
|
+
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
34
|
+
}
|
|
35
|
+
async getOrganizationSubscription({ id }, em) {
|
|
36
|
+
const subscription = await (em ?? this.em).findOneOrFail('Subscription', {
|
|
37
|
+
partyId: id,
|
|
38
|
+
partyType: 'ORGANIZATION',
|
|
39
|
+
active: true
|
|
40
|
+
});
|
|
41
|
+
return this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
42
|
+
}
|
|
43
|
+
async updateSubscription(subscriptionDto, em) {
|
|
44
|
+
const subscription = this.#mapperss.UpdateSubscriptionDtoMapper.deserializeDtoToEntity(subscriptionDto);
|
|
45
|
+
const updatedSubscription = await (em ?? this.em).upsert(subscription);
|
|
46
|
+
await (em ?? this.em).transactional(async (innerEm) => {
|
|
47
|
+
await innerEm.persist(updatedSubscription);
|
|
48
|
+
});
|
|
49
|
+
const updatedSubscriptionDto = this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(updatedSubscription);
|
|
50
|
+
return updatedSubscriptionDto;
|
|
51
|
+
}
|
|
52
|
+
async deleteSubscription(idDto, em) {
|
|
53
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
54
|
+
if (!subscription) {
|
|
55
|
+
throw new Error('Subscription not found');
|
|
56
|
+
}
|
|
57
|
+
await (em ?? this.em).removeAndFlush(subscription);
|
|
58
|
+
}
|
|
59
|
+
async listSubscriptions(idsDto, em) {
|
|
60
|
+
const subscriptions = await (em ?? this.em).findAll('Subscription', {
|
|
61
|
+
where: idsDto.ids
|
|
62
|
+
? {
|
|
63
|
+
id: {
|
|
64
|
+
$in: idsDto.ids
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
: undefined
|
|
68
|
+
});
|
|
69
|
+
return subscriptions.map((subscription) => {
|
|
70
|
+
const subscriptionDto = this.#mapperss.SubscriptionDtoMapper.serializeEntityToDto(subscription);
|
|
71
|
+
return subscriptionDto;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async cancelSubscription(idDto, em) {
|
|
75
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
76
|
+
if (!subscription) {
|
|
77
|
+
throw new Error('Subscription not found');
|
|
78
|
+
}
|
|
79
|
+
subscription.active = false;
|
|
80
|
+
await (em ?? this.em).transactional(async (innerEm) => {
|
|
81
|
+
await innerEm.persist(subscription);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async resumeSubscription(idDto, em) {
|
|
85
|
+
const subscription = await (em ?? this.em).findOne('Subscription', idDto);
|
|
86
|
+
if (!subscription) {
|
|
87
|
+
throw new Error('Subscription not found');
|
|
88
|
+
}
|
|
89
|
+
subscription.active = true;
|
|
90
|
+
await (em ?? this.em).transactional(async (innerEm) => {
|
|
91
|
+
await innerEm.persist(subscription);
|
|
92
|
+
});
|
|
111
93
|
}
|
|
112
|
-
subscription.active = true;
|
|
113
|
-
await (em ?? this.em).transactional(async (innerEm) => {
|
|
114
|
-
await innerEm.persist(subscription);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
94
|
}
|