@forklaunch/implementation-billing-base 0.8.23 → 1.0.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.
@@ -1,16 +1,22 @@
1
1
  import {
2
- BillingPortalDto,
3
- CheckoutSessionDto,
4
- PaymentLinkDto,
5
- PlanDto,
6
- SubscriptionDto
7
- } from '@forklaunch/interfaces-billing/types';
2
+ BillingPortal,
3
+ CheckoutSession,
4
+ PaymentLink,
5
+ Plan,
6
+ Subscription
7
+ } from '../../persistence/entities';
8
8
 
9
- // billing entity types
9
+ // billing portal entity types
10
10
  export type BaseBillingEntities = {
11
- BillingPortalMapper: BillingPortalDto;
12
- CreateBillingPortalMapper: BillingPortalDto;
13
- UpdateBillingPortalMapper: BillingPortalDto;
11
+ BillingPortalMapper: {
12
+ '~entity': (typeof BillingPortal)['~entity'];
13
+ };
14
+ CreateBillingPortalMapper: {
15
+ '~entity': (typeof BillingPortal)['~entity'];
16
+ };
17
+ UpdateBillingPortalMapper: {
18
+ '~entity': (typeof BillingPortal)['~entity'];
19
+ };
14
20
  };
15
21
 
16
22
  // checkout session entity types
@@ -19,21 +25,27 @@ export type BaseCheckoutSessionEntities<
19
25
  CurrencyEnum,
20
26
  StatusEnum
21
27
  > = {
22
- CheckoutSessionMapper: CheckoutSessionDto<
23
- PaymentMethodEnum,
24
- CurrencyEnum,
25
- StatusEnum
26
- >;
27
- CreateCheckoutSessionMapper: CheckoutSessionDto<
28
- PaymentMethodEnum,
29
- CurrencyEnum,
30
- StatusEnum
31
- >;
32
- UpdateCheckoutSessionMapper: CheckoutSessionDto<
33
- PaymentMethodEnum,
34
- CurrencyEnum,
35
- StatusEnum
36
- >;
28
+ CheckoutSessionMapper: {
29
+ '~entity': (typeof CheckoutSession)['~entity'] & {
30
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
31
+ currency: CurrencyEnum[keyof CurrencyEnum];
32
+ status: StatusEnum[keyof StatusEnum];
33
+ };
34
+ };
35
+ CreateCheckoutSessionMapper: {
36
+ '~entity': (typeof CheckoutSession)['~entity'] & {
37
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
38
+ currency: CurrencyEnum[keyof CurrencyEnum];
39
+ status: StatusEnum[keyof StatusEnum];
40
+ };
41
+ };
42
+ UpdateCheckoutSessionMapper: {
43
+ '~entity': (typeof CheckoutSession)['~entity'] & {
44
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
45
+ currency: CurrencyEnum[keyof CurrencyEnum];
46
+ status: StatusEnum[keyof StatusEnum];
47
+ };
48
+ };
37
49
  };
38
50
 
39
51
  // payment link entity types
@@ -42,21 +54,27 @@ export type BasePaymentLinkEntities<
42
54
  CurrencyEnum,
43
55
  StatusEnum
44
56
  > = {
45
- PaymentLinkMapper: PaymentLinkDto<
46
- PaymentMethodEnum,
47
- CurrencyEnum,
48
- StatusEnum
49
- >;
50
- CreatePaymentLinkMapper: PaymentLinkDto<
51
- PaymentMethodEnum,
52
- CurrencyEnum,
53
- StatusEnum
54
- >;
55
- UpdatePaymentLinkMapper: PaymentLinkDto<
56
- PaymentMethodEnum,
57
- CurrencyEnum,
58
- StatusEnum
59
- >;
57
+ PaymentLinkMapper: {
58
+ '~entity': (typeof PaymentLink)['~entity'] & {
59
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
60
+ currency: CurrencyEnum[keyof CurrencyEnum];
61
+ status: StatusEnum[keyof StatusEnum];
62
+ };
63
+ };
64
+ CreatePaymentLinkMapper: {
65
+ '~entity': (typeof PaymentLink)['~entity'] & {
66
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
67
+ currency: CurrencyEnum[keyof CurrencyEnum];
68
+ status: StatusEnum[keyof StatusEnum];
69
+ };
70
+ };
71
+ UpdatePaymentLinkMapper: {
72
+ '~entity': (typeof PaymentLink)['~entity'] & {
73
+ paymentMethods: PaymentMethodEnum[keyof PaymentMethodEnum][];
74
+ currency: CurrencyEnum[keyof CurrencyEnum];
75
+ status: StatusEnum[keyof StatusEnum];
76
+ };
77
+ };
60
78
  };
61
79
 
62
80
  // plan entity types
@@ -65,14 +83,47 @@ export type BasePlanEntities<
65
83
  CurrencyEnum,
66
84
  BillingProviderEnum
67
85
  > = {
68
- PlanMapper: PlanDto<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum>;
69
- CreatePlanMapper: PlanDto<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum>;
70
- UpdatePlanMapper: PlanDto<PlanCadenceEnum, CurrencyEnum, BillingProviderEnum>;
86
+ PlanMapper: {
87
+ '~entity': (typeof Plan)['~entity'] & {
88
+ cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
89
+ currency: CurrencyEnum[keyof CurrencyEnum];
90
+ billingProvider: BillingProviderEnum[keyof BillingProviderEnum];
91
+ };
92
+ };
93
+ CreatePlanMapper: {
94
+ '~entity': (typeof Plan)['~entity'] & {
95
+ cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
96
+ currency: CurrencyEnum[keyof CurrencyEnum];
97
+ billingProvider: BillingProviderEnum[keyof BillingProviderEnum];
98
+ };
99
+ };
100
+ UpdatePlanMapper: {
101
+ '~entity': (typeof Plan)['~entity'] & {
102
+ cadence: PlanCadenceEnum[keyof PlanCadenceEnum];
103
+ currency: CurrencyEnum[keyof CurrencyEnum];
104
+ billingProvider: BillingProviderEnum[keyof BillingProviderEnum];
105
+ };
106
+ };
71
107
  };
72
108
 
73
109
  // subscription entity types
74
110
  export type BaseSubscriptionEntities<PartyType, BillingProviderType> = {
75
- SubscriptionMapper: SubscriptionDto<PartyType, BillingProviderType>;
76
- CreateSubscriptionMapper: SubscriptionDto<PartyType, BillingProviderType>;
77
- UpdateSubscriptionMapper: SubscriptionDto<PartyType, BillingProviderType>;
111
+ SubscriptionMapper: {
112
+ '~entity': (typeof Subscription)['~entity'] & {
113
+ partyType: PartyType[keyof PartyType];
114
+ billingProvider: BillingProviderType[keyof BillingProviderType];
115
+ };
116
+ };
117
+ CreateSubscriptionMapper: {
118
+ '~entity': (typeof Subscription)['~entity'] & {
119
+ partyType: PartyType[keyof PartyType];
120
+ billingProvider: BillingProviderType[keyof BillingProviderType];
121
+ };
122
+ };
123
+ UpdateSubscriptionMapper: {
124
+ '~entity': (typeof Subscription)['~entity'] & {
125
+ partyType: PartyType[keyof PartyType];
126
+ billingProvider: BillingProviderType[keyof BillingProviderType];
127
+ };
128
+ };
78
129
  };
@@ -1,4 +1,4 @@
1
- import { EntityManager } from '@mikro-orm/core';
1
+ import { EntityManager, InferEntity } from '@mikro-orm/core';
2
2
  import { BaseBillingDtos } from './baseBillingDto.types';
3
3
  import { BaseBillingEntities } from './baseBillingEntity.types';
4
4
 
@@ -7,22 +7,25 @@ export type BillingPortalMappers<
7
7
  MapperDomains extends BaseBillingDtos
8
8
  > = {
9
9
  BillingPortalMapper: {
10
+ entity: MapperEntities['BillingPortalMapper'];
10
11
  toDto: (
11
- entity: MapperEntities['BillingPortalMapper']
12
+ entity: InferEntity<MapperEntities['BillingPortalMapper']>
12
13
  ) => Promise<MapperDomains['BillingPortalMapper']>;
13
14
  };
14
15
  CreateBillingPortalMapper: {
16
+ entity: MapperEntities['CreateBillingPortalMapper'];
15
17
  toEntity: (
16
18
  dto: MapperDomains['CreateBillingPortalMapper'],
17
19
  em: EntityManager,
18
20
  ...args: unknown[]
19
- ) => Promise<MapperEntities['CreateBillingPortalMapper']>;
21
+ ) => Promise<InferEntity<MapperEntities['CreateBillingPortalMapper']>>;
20
22
  };
21
23
  UpdateBillingPortalMapper: {
24
+ entity: MapperEntities['UpdateBillingPortalMapper'];
22
25
  toEntity: (
23
26
  dto: MapperDomains['UpdateBillingPortalMapper'],
24
27
  em: EntityManager,
25
28
  ...args: unknown[]
26
- ) => Promise<MapperEntities['UpdateBillingPortalMapper']>;
29
+ ) => Promise<InferEntity<MapperEntities['UpdateBillingPortalMapper']>>;
27
30
  };
28
31
  };
@@ -1,4 +1,4 @@
1
- import { EntityManager } from '@mikro-orm/core';
1
+ import { EntityManager, InferEntity } from '@mikro-orm/core';
2
2
  import { BaseCheckoutSessionDtos } from './baseBillingDto.types';
3
3
  import { BaseCheckoutSessionEntities } from './baseBillingEntity.types';
4
4
 
@@ -18,22 +18,25 @@ export type CheckoutSessionMappers<
18
18
  >
19
19
  > = {
20
20
  CheckoutSessionMapper: {
21
+ entity: MapperEntities['CheckoutSessionMapper'];
21
22
  toDto: (
22
- entity: MapperEntities['CheckoutSessionMapper']
23
+ entity: InferEntity<MapperEntities['CheckoutSessionMapper']>
23
24
  ) => Promise<MapperDomains['CheckoutSessionMapper']>;
24
25
  };
25
26
  CreateCheckoutSessionMapper: {
27
+ entity: MapperEntities['CreateCheckoutSessionMapper'];
26
28
  toEntity: (
27
29
  dto: MapperDomains['CreateCheckoutSessionMapper'],
28
30
  em: EntityManager,
29
31
  ...args: unknown[]
30
- ) => Promise<MapperEntities['CreateCheckoutSessionMapper']>;
32
+ ) => Promise<InferEntity<MapperEntities['CreateCheckoutSessionMapper']>>;
31
33
  };
32
34
  UpdateCheckoutSessionMapper: {
35
+ entity: MapperEntities['UpdateCheckoutSessionMapper'];
33
36
  toEntity: (
34
37
  dto: MapperDomains['UpdateCheckoutSessionMapper'],
35
38
  em: EntityManager,
36
39
  ...args: unknown[]
37
- ) => Promise<MapperEntities['UpdateCheckoutSessionMapper']>;
40
+ ) => Promise<InferEntity<MapperEntities['UpdateCheckoutSessionMapper']>>;
38
41
  };
39
42
  };
@@ -1,4 +1,4 @@
1
- import { EntityManager } from '@mikro-orm/core';
1
+ import { EntityManager, InferEntity } from '@mikro-orm/core';
2
2
  import { BasePaymentLinkDtos } from './baseBillingDto.types';
3
3
  import { BasePaymentLinkEntities } from './baseBillingEntity.types';
4
4
 
@@ -18,22 +18,25 @@ export type PaymentLinkMappers<
18
18
  >
19
19
  > = {
20
20
  PaymentLinkMapper: {
21
+ entity: MapperEntities['PaymentLinkMapper'];
21
22
  toDto: (
22
- entity: MapperEntities['PaymentLinkMapper']
23
+ entity: InferEntity<MapperEntities['PaymentLinkMapper']>
23
24
  ) => Promise<MapperDomains['PaymentLinkMapper']>;
24
25
  };
25
26
  CreatePaymentLinkMapper: {
27
+ entity: MapperEntities['CreatePaymentLinkMapper'];
26
28
  toEntity: (
27
29
  dto: MapperDomains['CreatePaymentLinkMapper'],
28
30
  em: EntityManager,
29
31
  ...args: unknown[]
30
- ) => Promise<MapperEntities['CreatePaymentLinkMapper']>;
32
+ ) => Promise<InferEntity<MapperEntities['CreatePaymentLinkMapper']>>;
31
33
  };
32
34
  UpdatePaymentLinkMapper: {
35
+ entity: MapperEntities['UpdatePaymentLinkMapper'];
33
36
  toEntity: (
34
37
  dto: MapperDomains['UpdatePaymentLinkMapper'],
35
38
  em: EntityManager,
36
39
  ...args: unknown[]
37
- ) => Promise<MapperEntities['UpdatePaymentLinkMapper']>;
40
+ ) => Promise<InferEntity<MapperEntities['UpdatePaymentLinkMapper']>>;
38
41
  };
39
42
  };
@@ -1,4 +1,4 @@
1
- import { EntityManager } from '@mikro-orm/core';
1
+ import { EntityManager, InferEntity } from '@mikro-orm/core';
2
2
  import { BasePlanDtos } from './baseBillingDto.types';
3
3
  import { BasePlanEntities } from './baseBillingEntity.types';
4
4
 
@@ -18,22 +18,25 @@ export type PlanMappers<
18
18
  >
19
19
  > = {
20
20
  PlanMapper: {
21
+ entity: MapperEntities['PlanMapper'];
21
22
  toDto: (
22
- entity: MapperEntities['PlanMapper']
23
+ entity: InferEntity<MapperEntities['PlanMapper']>
23
24
  ) => Promise<MapperDomains['PlanMapper']>;
24
25
  };
25
26
  CreatePlanMapper: {
27
+ entity: MapperEntities['CreatePlanMapper'];
26
28
  toEntity: (
27
29
  dto: MapperDomains['CreatePlanMapper'],
28
30
  em: EntityManager,
29
31
  ...args: unknown[]
30
- ) => Promise<MapperEntities['CreatePlanMapper']>;
32
+ ) => Promise<InferEntity<MapperEntities['CreatePlanMapper']>>;
31
33
  };
32
34
  UpdatePlanMapper: {
35
+ entity: MapperEntities['UpdatePlanMapper'];
33
36
  toEntity: (
34
37
  dto: MapperDomains['UpdatePlanMapper'],
35
38
  em: EntityManager,
36
39
  ...args: unknown[]
37
- ) => Promise<MapperEntities['UpdatePlanMapper']>;
40
+ ) => Promise<InferEntity<MapperEntities['UpdatePlanMapper']>>;
38
41
  };
39
42
  };
@@ -1,4 +1,4 @@
1
- import { EntityManager } from '@mikro-orm/core';
1
+ import { EntityManager, InferEntity } from '@mikro-orm/core';
2
2
  import { BaseSubscriptionDtos } from './baseBillingDto.types';
3
3
  import { BaseSubscriptionEntities } from './baseBillingEntity.types';
4
4
 
@@ -12,22 +12,25 @@ export type SubscriptionMappers<
12
12
  MapperDomains extends BaseSubscriptionDtos<PartyType, BillingProviderType>
13
13
  > = {
14
14
  SubscriptionMapper: {
15
+ entity: MapperEntities['SubscriptionMapper'];
15
16
  toDto: (
16
- entity: MapperEntities['SubscriptionMapper']
17
+ entity: InferEntity<MapperEntities['SubscriptionMapper']>
17
18
  ) => Promise<MapperDomains['SubscriptionMapper']>;
18
19
  };
19
20
  CreateSubscriptionMapper: {
21
+ entity: MapperEntities['CreateSubscriptionMapper'];
20
22
  toEntity: (
21
23
  dto: MapperDomains['CreateSubscriptionMapper'],
22
24
  em: EntityManager,
23
25
  ...args: unknown[]
24
- ) => Promise<MapperEntities['CreateSubscriptionMapper']>;
26
+ ) => Promise<InferEntity<MapperEntities['CreateSubscriptionMapper']>>;
25
27
  };
26
28
  UpdateSubscriptionMapper: {
29
+ entity: MapperEntities['UpdateSubscriptionMapper'];
27
30
  toEntity: (
28
31
  dto: MapperDomains['UpdateSubscriptionMapper'],
29
32
  em: EntityManager,
30
33
  ...args: unknown[]
31
- ) => Promise<MapperEntities['UpdateSubscriptionMapper']>;
34
+ ) => Promise<InferEntity<MapperEntities['UpdateSubscriptionMapper']>>;
32
35
  };
33
36
  };
@@ -81,7 +81,7 @@ export class BaseBillingPortalService<
81
81
  );
82
82
 
83
83
  if (this.enableDatabaseBackup) {
84
- await this.em.persistAndFlush(billingPortal);
84
+ await this.em.persist(billingPortal).flush();
85
85
  }
86
86
 
87
87
  const createdBillingPortalDto =
@@ -104,7 +104,7 @@ export class BaseBillingPortalService<
104
104
  }
105
105
 
106
106
  const billingPortalDetails = await this.cache.readRecord<
107
- MapperEntities['BillingPortalMapper']
107
+ MapperDomains['BillingPortalMapper']
108
108
  >(this.createCacheKey(idDto.id));
109
109
 
110
110
  if (!billingPortalDetails) {
@@ -147,9 +147,7 @@ export class BaseBillingPortalService<
147
147
  );
148
148
 
149
149
  if (this.enableDatabaseBackup) {
150
- await this.em.persistAndFlush({
151
- billingPortal
152
- });
150
+ await this.em.persist(billingPortal).flush();
153
151
  }
154
152
 
155
153
  const updatedBillingPortalDto = {
@@ -10,6 +10,7 @@ import { CheckoutSessionService } from '@forklaunch/interfaces-billing/interface
10
10
  import { CreateCheckoutSessionDto } from '@forklaunch/interfaces-billing/types';
11
11
  import { AnySchemaValidator } from '@forklaunch/validator';
12
12
  import { EntityManager } from '@mikro-orm/core';
13
+ import { CheckoutSession } from '../persistence/entities';
13
14
  import { BaseCheckoutSessionDtos } from '../domain/types/baseBillingDto.types';
14
15
  import { BaseCheckoutSessionEntities } from '../domain/types/baseBillingEntity.types';
15
16
  import { CheckoutSessionMappers } from '../domain/types/checkoutSession.mapper.types';
@@ -109,7 +110,7 @@ export class BaseCheckoutSessionService<
109
110
  await this.mappers.CheckoutSessionMapper.toDto(checkoutSession);
110
111
 
111
112
  if (this.enableDatabaseBackup) {
112
- await this.em.persistAndFlush(checkoutSession);
113
+ await this.em.persist(checkoutSession).flush();
113
114
  }
114
115
 
115
116
  await this.cache.putRecord({
@@ -125,7 +126,7 @@ export class BaseCheckoutSessionService<
125
126
  id
126
127
  }: IdDto): Promise<MapperDomains['CheckoutSessionMapper']> {
127
128
  const checkoutSessionDetails = await this.cache.readRecord<
128
- MapperEntities['CheckoutSessionMapper']
129
+ MapperDomains['CheckoutSessionMapper']
129
130
  >(this.createCacheKey(id));
130
131
  if (!checkoutSessionDetails) {
131
132
  throw new Error('Session not found');
@@ -155,11 +156,14 @@ export class BaseCheckoutSessionService<
155
156
  }
156
157
 
157
158
  if (this.enableDatabaseBackup) {
158
- const checkoutSession = await this.em.upsert('CheckoutSession', {
159
- id,
160
- status: 'SUCCESS'
161
- });
162
- await this.em.persistAndFlush(checkoutSession);
159
+ const checkoutSession = await this.em.upsert(
160
+ this.mappers.CheckoutSessionMapper.entity as typeof CheckoutSession,
161
+ {
162
+ id,
163
+ status: 'SUCCESS'
164
+ }
165
+ );
166
+ await this.em.persist(checkoutSession).flush();
163
167
  }
164
168
 
165
169
  await this.cache.deleteRecord(this.createCacheKey(id));
@@ -171,11 +175,14 @@ export class BaseCheckoutSessionService<
171
175
  }
172
176
 
173
177
  if (this.enableDatabaseBackup) {
174
- const checkoutSession = await this.em.upsert('CheckoutSession', {
175
- id,
176
- status: 'FAILED'
177
- });
178
- await this.em.persistAndFlush(checkoutSession);
178
+ const checkoutSession = await this.em.upsert(
179
+ this.mappers.CheckoutSessionMapper.entity as typeof CheckoutSession,
180
+ {
181
+ id,
182
+ status: 'FAILED'
183
+ }
184
+ );
185
+ await this.em.persist(checkoutSession).flush();
179
186
  }
180
187
 
181
188
  await this.cache.deleteRecord(this.createCacheKey(id));
@@ -13,6 +13,7 @@ import {
13
13
  } from '@forklaunch/interfaces-billing/types';
14
14
  import { AnySchemaValidator } from '@forklaunch/validator';
15
15
  import { EntityManager } from '@mikro-orm/core';
16
+ import { PaymentLink } from '../persistence/entities';
16
17
  import { BasePaymentLinkDtos } from '../domain/types/baseBillingDto.types';
17
18
  import { BasePaymentLinkEntities } from '../domain/types/baseBillingEntity.types';
18
19
  import { PaymentLinkMappers } from '../domain/types/paymentLink.mapper.types';
@@ -106,7 +107,7 @@ export class BasePaymentLinkService<
106
107
  );
107
108
 
108
109
  if (this.enableDatabaseBackup) {
109
- await this.em.persistAndFlush(paymentLink);
110
+ await this.em.persist(paymentLink).flush();
110
111
  }
111
112
 
112
113
  const createdPaymentLinkDto =
@@ -147,7 +148,7 @@ export class BasePaymentLinkService<
147
148
  );
148
149
 
149
150
  if (this.enableDatabaseBackup) {
150
- await this.em.persistAndFlush(paymentLink);
151
+ await this.em.persist(paymentLink).flush();
151
152
  }
152
153
 
153
154
  const updatedLinkDto = {
@@ -185,11 +186,14 @@ export class BasePaymentLinkService<
185
186
  this.openTelemetryCollector.info('Payment link expired', { id });
186
187
 
187
188
  if (this.enableDatabaseBackup) {
188
- const paymentLink = await this.em.upsert('PaymentLink', {
189
- id,
190
- status: 'EXPIRED'
191
- });
192
- await this.em.removeAndFlush(paymentLink);
189
+ const paymentLink = await this.em.upsert(
190
+ this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
191
+ {
192
+ id,
193
+ status: 'EXPIRED'
194
+ }
195
+ );
196
+ await this.em.remove(paymentLink).flush();
193
197
  }
194
198
  await this.cache.deleteRecord(this.createCacheKey(id));
195
199
  }
@@ -197,11 +201,14 @@ export class BasePaymentLinkService<
197
201
  async handlePaymentSuccess({ id }: IdDto): Promise<void> {
198
202
  this.openTelemetryCollector.info('Payment link success', { id });
199
203
  if (this.enableDatabaseBackup) {
200
- const paymentLink = await this.em.upsert('PaymentLink', {
201
- id,
202
- status: 'COMPLETED'
203
- });
204
- await this.em.removeAndFlush(paymentLink);
204
+ const paymentLink = await this.em.upsert(
205
+ this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
206
+ {
207
+ id,
208
+ status: 'COMPLETED'
209
+ }
210
+ );
211
+ await this.em.remove(paymentLink).flush();
205
212
  }
206
213
  await this.cache.deleteRecord(this.createCacheKey(id));
207
214
  }
@@ -209,11 +216,14 @@ export class BasePaymentLinkService<
209
216
  async handlePaymentFailure({ id }: IdDto): Promise<void> {
210
217
  this.openTelemetryCollector.info('Payment link failure', { id });
211
218
  if (this.enableDatabaseBackup) {
212
- const paymentLink = await this.em.upsert('PaymentLink', {
213
- id,
214
- status: 'FAILED'
215
- });
216
- await this.em.removeAndFlush(paymentLink);
219
+ const paymentLink = await this.em.upsert(
220
+ this.mappers.PaymentLinkMapper.entity as typeof PaymentLink,
221
+ {
222
+ id,
223
+ status: 'FAILED'
224
+ }
225
+ );
226
+ await this.em.remove(paymentLink).flush();
217
227
  }
218
228
  await this.cache.deleteRecord(this.createCacheKey(id));
219
229
  }
@@ -11,10 +11,11 @@ import {
11
11
  UpdatePlanDto
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 { BasePlanDtos } from '../domain/types/baseBillingDto.types';
16
16
  import { BasePlanEntities } from '../domain/types/baseBillingEntity.types';
17
17
  import { PlanMappers } from '../domain/types/plan.mapper.types';
18
+ import { Plan } from '../persistence/entities';
18
19
 
19
20
  export class BasePlanService<
20
21
  SchemaValidator extends AnySchemaValidator,
@@ -87,11 +88,16 @@ export class BasePlanService<
87
88
 
88
89
  return Promise.all(
89
90
  (
90
- await (em ?? this.em).findAll('Plan', {
91
- where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
92
- })
91
+ await (em ?? this.em).findAll(
92
+ this.mappers.PlanMapper.entity as typeof Plan,
93
+ {
94
+ where: idsDto?.ids?.length ? { id: { $in: idsDto.ids } } : undefined
95
+ }
96
+ )
93
97
  ).map((plan) =>
94
- this.mappers.PlanMapper.toDto(plan as MapperEntities['PlanMapper'])
98
+ this.mappers.PlanMapper.toDto(
99
+ plan as InferEntity<MapperEntities['PlanMapper']>
100
+ )
95
101
  )
96
102
  );
97
103
  }
@@ -122,8 +128,13 @@ export class BasePlanService<
122
128
  if (this.evaluatedTelemetryOptions.logging) {
123
129
  this.openTelemetryCollector.info('Getting plan', idDto);
124
130
  }
125
- const plan = await (em ?? this.em).findOneOrFail('Plan', idDto);
126
- return this.mappers.PlanMapper.toDto(plan as MapperEntities['PlanMapper']);
131
+ const plan = await (em ?? this.em).findOneOrFail(
132
+ this.mappers.PlanMapper.entity as typeof Plan,
133
+ idDto
134
+ );
135
+ return this.mappers.PlanMapper.toDto(
136
+ plan as InferEntity<MapperEntities['PlanMapper']>
137
+ );
127
138
  }
128
139
 
129
140
  async updatePlan(
@@ -151,6 +162,9 @@ export class BasePlanService<
151
162
  if (this.evaluatedTelemetryOptions.logging) {
152
163
  this.openTelemetryCollector.info('Deleting plan', idDto);
153
164
  }
154
- await (em ?? this.em).nativeDelete('Plan', idDto);
165
+ await (em ?? this.em).nativeDelete(
166
+ this.mappers.PlanMapper.entity as typeof Plan,
167
+ idDto
168
+ );
155
169
  }
156
170
  }