@misterhomer1992/miit-bot-payment 1.0.6 → 1.0.8
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/README.md +1 -359
- package/dist/modules/cancellableAPI/utils.d.ts +1 -2
- package/dist/modules/cancellableAPI/utils.d.ts.map +1 -1
- package/dist/modules/cancellableAPI/utils.js.map +1 -1
- package/dist/modules/invoice/repository.d.ts +6 -26
- package/dist/modules/invoice/repository.d.ts.map +1 -1
- package/dist/modules/invoice/repository.js +2 -25
- package/dist/modules/invoice/repository.js.map +1 -1
- package/dist/modules/invoice/service.d.ts +6 -22
- package/dist/modules/invoice/service.d.ts.map +1 -1
- package/dist/modules/invoice/service.js +2 -21
- package/dist/modules/invoice/service.js.map +1 -1
- package/dist/modules/invoice/types.d.ts +30 -1
- package/dist/modules/invoice/types.d.ts.map +1 -1
- package/dist/modules/payments/api.d.ts +3 -4
- package/dist/modules/payments/api.d.ts.map +1 -1
- package/dist/modules/payments/api.js +3 -3
- package/dist/modules/payments/api.js.map +1 -1
- package/dist/modules/payments/repository.d.ts +7 -61
- package/dist/modules/payments/repository.d.ts.map +1 -1
- package/dist/modules/payments/repository.js +4 -59
- package/dist/modules/payments/repository.js.map +1 -1
- package/dist/modules/payments/service.d.ts +8 -67
- package/dist/modules/payments/service.d.ts.map +1 -1
- package/dist/modules/payments/service.js +7 -68
- package/dist/modules/payments/service.js.map +1 -1
- package/dist/modules/payments/types.d.ts +100 -3
- package/dist/modules/payments/types.d.ts.map +1 -1
- package/dist/modules/payments/utils.d.ts +3 -4
- package/dist/modules/payments/utils.d.ts.map +1 -1
- package/dist/modules/payments/utils.js +6 -6
- package/dist/modules/payments/utils.js.map +1 -1
- package/dist/modules/subscription/repository.d.ts +10 -85
- package/dist/modules/subscription/repository.d.ts.map +1 -1
- package/dist/modules/subscription/repository.js +17 -109
- package/dist/modules/subscription/repository.js.map +1 -1
- package/dist/modules/subscription/service.d.ts +13 -89
- package/dist/modules/subscription/service.d.ts.map +1 -1
- package/dist/modules/subscription/service.js +10 -83
- package/dist/modules/subscription/service.js.map +1 -1
- package/dist/modules/subscription/types.d.ts +127 -3
- package/dist/modules/subscription/types.d.ts.map +1 -1
- package/dist/modules/user/types.d.ts +67 -2
- package/dist/modules/user/types.d.ts.map +1 -1
- package/dist/modules/user/userRepository.d.ts +9 -48
- package/dist/modules/user/userRepository.d.ts.map +1 -1
- package/dist/modules/user/userRepository.js +8 -48
- package/dist/modules/user/userRepository.js.map +1 -1
- package/dist/modules/user/userService.d.ts +9 -38
- package/dist/modules/user/userService.d.ts.map +1 -1
- package/dist/modules/user/userService.js +5 -36
- package/dist/modules/user/userService.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,97 +1,41 @@
|
|
|
1
1
|
import { Logger } from '../logger/types';
|
|
2
2
|
import { UpdateDBSubscriptionFields } from './repository';
|
|
3
|
-
import { SubscriptionEntity } from './types';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
* SubscriptionService class handles business logic related to subscriptions.
|
|
7
|
-
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
-
*/
|
|
9
|
-
export declare class SubscriptionService {
|
|
3
|
+
import { SubscriptionEntity, ISubscriptionRepository, ISubscriptionService } from './types';
|
|
4
|
+
import { IPaymentService } from '../payments/types';
|
|
5
|
+
export declare class SubscriptionService implements ISubscriptionService {
|
|
10
6
|
private readonly logger;
|
|
11
7
|
private readonly repository;
|
|
12
8
|
private readonly paymentService;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a subscription for a specific user.
|
|
20
|
-
* @param params - Query parameters
|
|
21
|
-
* @param params.userId - The user's unique identifier
|
|
22
|
-
* @param params.appNamespace - The application namespace/platform
|
|
23
|
-
* @param params.status - Optional status filter. Can be a single status or array of statuses. Defaults to 'active'
|
|
24
|
-
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
25
|
-
*/
|
|
9
|
+
constructor({ logger, repository, paymentService, }: {
|
|
10
|
+
logger: Logger;
|
|
11
|
+
repository?: ISubscriptionRepository;
|
|
12
|
+
paymentService?: IPaymentService;
|
|
13
|
+
});
|
|
26
14
|
findSubscription(params: {
|
|
27
15
|
userId: string;
|
|
28
|
-
|
|
16
|
+
platform: string;
|
|
29
17
|
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
30
18
|
}): Promise<SubscriptionEntity | null>;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a new subscription record in the database.
|
|
33
|
-
* @param params - Subscription creation parameters
|
|
34
|
-
* @param params.userId - The user's unique identifier
|
|
35
|
-
* @param params.appNamespace - The application namespace/platform
|
|
36
|
-
* @param params.planId - The subscription plan identifier
|
|
37
|
-
* @param params.expiresAt - ISO timestamp when subscription expires
|
|
38
|
-
* @param params.startedAt - ISO timestamp when subscription started
|
|
39
|
-
* @returns Promise resolving to created SubscriptionEntity with ID
|
|
40
|
-
* @throws Error if subscription creation fails
|
|
41
|
-
*/
|
|
42
19
|
create(params: {
|
|
43
20
|
userId: string;
|
|
44
|
-
|
|
21
|
+
platform: string;
|
|
45
22
|
planId: string;
|
|
46
23
|
expiresAt: string;
|
|
47
24
|
startedAt: string;
|
|
48
25
|
}): Promise<SubscriptionEntity>;
|
|
49
|
-
/**
|
|
50
|
-
* Updates specific fields of a subscription identified by userId and appNamespace.
|
|
51
|
-
* @param params - Update parameters
|
|
52
|
-
* @param params.userId - The user's unique identifier
|
|
53
|
-
* @param params.appNamespace - The application namespace/platform
|
|
54
|
-
* @param params.fields - Array of field paths and values to update
|
|
55
|
-
* @throws Error if subscription not found or update fails
|
|
56
|
-
*/
|
|
57
26
|
updateFieldsByUserId(params: {
|
|
58
27
|
userId: string;
|
|
59
|
-
|
|
28
|
+
platform: string;
|
|
60
29
|
fields: UpdateDBSubscriptionFields;
|
|
61
30
|
}): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Retrieves all active subscriptions that have expired.
|
|
64
|
-
* Used for batch processing to update subscription statuses.
|
|
65
|
-
* @returns Promise resolving to array of expired SubscriptionEntity
|
|
66
|
-
*/
|
|
67
31
|
getExpiredActiveSubscriptions(): Promise<SubscriptionEntity[]>;
|
|
68
|
-
/**
|
|
69
|
-
* Updates specific fields of a subscription identified by subscription ID.
|
|
70
|
-
* @param params - Update parameters
|
|
71
|
-
* @param params.subscriptionId - The subscription document ID
|
|
72
|
-
* @param params.fields - Array of field paths and values to update
|
|
73
|
-
* @throws Error if update fails
|
|
74
|
-
*/
|
|
75
32
|
updateFieldsById(params: {
|
|
76
33
|
subscriptionId: string;
|
|
77
34
|
fields: UpdateDBSubscriptionFields;
|
|
78
35
|
}): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Gets or creates a subscription payment URL.
|
|
81
|
-
* Checks for recent pending payments (within 3 minutes) and reuses the payment link if found.
|
|
82
|
-
* Otherwise creates a new payment intent for the subscription.
|
|
83
|
-
* @param params - Payment URL creation parameters
|
|
84
|
-
* @param params.userId - The user's unique identifier
|
|
85
|
-
* @param params.appNamespace - The application namespace/platform
|
|
86
|
-
* @param params.planId - The subscription plan identifier
|
|
87
|
-
* @param params.languageCode - Language code for translations
|
|
88
|
-
* @param params.translate - Translation function
|
|
89
|
-
* @returns Promise resolving to the payment URL string
|
|
90
|
-
* @throws Error if subscription plan not found or payment creation fails
|
|
91
|
-
*/
|
|
92
36
|
getOrCreateSubscriptionPaymentUrl(params: {
|
|
93
37
|
userId: string;
|
|
94
|
-
|
|
38
|
+
platform: string;
|
|
95
39
|
planId: string;
|
|
96
40
|
languageCode: string;
|
|
97
41
|
translate: (params: {
|
|
@@ -99,26 +43,6 @@ export declare class SubscriptionService {
|
|
|
99
43
|
path: string;
|
|
100
44
|
}) => string;
|
|
101
45
|
}): Promise<string>;
|
|
102
|
-
|
|
103
|
-
* Activates a subscription for a user.
|
|
104
|
-
* This operation is transactional - it creates/updates the subscription document
|
|
105
|
-
* and updates the user's subscription status atomically.
|
|
106
|
-
* @param params - Activation parameters
|
|
107
|
-
* @param params.userId - The user's unique identifier
|
|
108
|
-
* @param params.appNamespace - The application namespace/platform
|
|
109
|
-
* @param params.startedAt - ISO timestamp when subscription period starts
|
|
110
|
-
* @param params.expiresAt - ISO timestamp when subscription period ends
|
|
111
|
-
* @param params.planId - The subscription plan identifier
|
|
112
|
-
* @param params.provider - Payment provider (e.g., 'wayforpay')
|
|
113
|
-
* @throws Error if user not found or activation fails
|
|
114
|
-
*/
|
|
115
|
-
activateSubscription(params: {
|
|
116
|
-
userId: string;
|
|
117
|
-
appNamespace: AppNamespace;
|
|
118
|
-
startedAt: string;
|
|
119
|
-
expiresAt: string;
|
|
120
|
-
planId: string;
|
|
121
|
-
provider: 'wayforpay';
|
|
122
|
-
}): Promise<void>;
|
|
46
|
+
activateSubscription(params: Omit<SubscriptionEntity, 'id' | 'status'>): Promise<void>;
|
|
123
47
|
}
|
|
124
48
|
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAA0B,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAA0B,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAG5F,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,qBAAa,mBAAoB,YAAW,oBAAoB;IA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f,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,KAAK,MAAM,CAAC;KACjE,GAAG,OAAO,CAAC,MAAM,CAAC;IAyDN,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBtG"}
|
|
@@ -8,28 +8,12 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
8
8
|
const repository_1 = require("./repository");
|
|
9
9
|
const utils_1 = require("./utils");
|
|
10
10
|
const service_1 = require("../payments/service");
|
|
11
|
-
/**
|
|
12
|
-
* SubscriptionService class handles business logic related to subscriptions.
|
|
13
|
-
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
14
|
-
*/
|
|
15
11
|
class SubscriptionService {
|
|
16
|
-
|
|
17
|
-
* Creates an instance of SubscriptionService.
|
|
18
|
-
* @param logger - Application logger instance for logging operations
|
|
19
|
-
*/
|
|
20
|
-
constructor(logger) {
|
|
12
|
+
constructor({ logger, repository, paymentService, }) {
|
|
21
13
|
this.logger = logger;
|
|
22
|
-
this.repository = new repository_1.SubscriptionRepository();
|
|
23
|
-
this.paymentService = new service_1.PaymentService(logger);
|
|
14
|
+
this.repository = repository || new repository_1.SubscriptionRepository();
|
|
15
|
+
this.paymentService = paymentService || new service_1.PaymentService({ logger });
|
|
24
16
|
}
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves a subscription for a specific user.
|
|
27
|
-
* @param params - Query parameters
|
|
28
|
-
* @param params.userId - The user's unique identifier
|
|
29
|
-
* @param params.appNamespace - The application namespace/platform
|
|
30
|
-
* @param params.status - Optional status filter. Can be a single status or array of statuses. Defaults to 'active'
|
|
31
|
-
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
32
|
-
*/
|
|
33
17
|
async findSubscription(params) {
|
|
34
18
|
try {
|
|
35
19
|
return await this.repository.findSubscription(params);
|
|
@@ -39,24 +23,13 @@ class SubscriptionService {
|
|
|
39
23
|
message: 'Error in subscription service findSubscription',
|
|
40
24
|
payload: {
|
|
41
25
|
userId: params.userId,
|
|
42
|
-
|
|
26
|
+
platform: params.platform,
|
|
43
27
|
error: JSON.stringify(error),
|
|
44
28
|
},
|
|
45
29
|
});
|
|
46
30
|
return null;
|
|
47
31
|
}
|
|
48
32
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Creates a new subscription record in the database.
|
|
51
|
-
* @param params - Subscription creation parameters
|
|
52
|
-
* @param params.userId - The user's unique identifier
|
|
53
|
-
* @param params.appNamespace - The application namespace/platform
|
|
54
|
-
* @param params.planId - The subscription plan identifier
|
|
55
|
-
* @param params.expiresAt - ISO timestamp when subscription expires
|
|
56
|
-
* @param params.startedAt - ISO timestamp when subscription started
|
|
57
|
-
* @returns Promise resolving to created SubscriptionEntity with ID
|
|
58
|
-
* @throws Error if subscription creation fails
|
|
59
|
-
*/
|
|
60
33
|
async create(params) {
|
|
61
34
|
try {
|
|
62
35
|
return await this.repository.create(params);
|
|
@@ -66,7 +39,7 @@ class SubscriptionService {
|
|
|
66
39
|
message: 'Error in subscription service create',
|
|
67
40
|
payload: {
|
|
68
41
|
userId: params.userId,
|
|
69
|
-
|
|
42
|
+
platform: params.platform,
|
|
70
43
|
planId: params.planId,
|
|
71
44
|
error: JSON.stringify(error),
|
|
72
45
|
},
|
|
@@ -74,14 +47,6 @@ class SubscriptionService {
|
|
|
74
47
|
throw error;
|
|
75
48
|
}
|
|
76
49
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Updates specific fields of a subscription identified by userId and appNamespace.
|
|
79
|
-
* @param params - Update parameters
|
|
80
|
-
* @param params.userId - The user's unique identifier
|
|
81
|
-
* @param params.appNamespace - The application namespace/platform
|
|
82
|
-
* @param params.fields - Array of field paths and values to update
|
|
83
|
-
* @throws Error if subscription not found or update fails
|
|
84
|
-
*/
|
|
85
50
|
async updateFieldsByUserId(params) {
|
|
86
51
|
try {
|
|
87
52
|
await this.repository.updateFieldsByUserId(params);
|
|
@@ -91,7 +56,7 @@ class SubscriptionService {
|
|
|
91
56
|
message: 'Error in subscription service updateFieldsByUserId',
|
|
92
57
|
payload: {
|
|
93
58
|
userId: params.userId,
|
|
94
|
-
|
|
59
|
+
platform: params.platform,
|
|
95
60
|
fields: JSON.stringify(params.fields),
|
|
96
61
|
error: JSON.stringify(error),
|
|
97
62
|
},
|
|
@@ -99,11 +64,6 @@ class SubscriptionService {
|
|
|
99
64
|
throw error;
|
|
100
65
|
}
|
|
101
66
|
}
|
|
102
|
-
/**
|
|
103
|
-
* Retrieves all active subscriptions that have expired.
|
|
104
|
-
* Used for batch processing to update subscription statuses.
|
|
105
|
-
* @returns Promise resolving to array of expired SubscriptionEntity
|
|
106
|
-
*/
|
|
107
67
|
async getExpiredActiveSubscriptions() {
|
|
108
68
|
try {
|
|
109
69
|
return await this.repository.getExpiredActiveSubscriptions();
|
|
@@ -118,13 +78,6 @@ class SubscriptionService {
|
|
|
118
78
|
return [];
|
|
119
79
|
}
|
|
120
80
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Updates specific fields of a subscription identified by subscription ID.
|
|
123
|
-
* @param params - Update parameters
|
|
124
|
-
* @param params.subscriptionId - The subscription document ID
|
|
125
|
-
* @param params.fields - Array of field paths and values to update
|
|
126
|
-
* @throws Error if update fails
|
|
127
|
-
*/
|
|
128
81
|
async updateFieldsById(params) {
|
|
129
82
|
try {
|
|
130
83
|
await this.repository.updateFieldsById(params);
|
|
@@ -141,25 +94,12 @@ class SubscriptionService {
|
|
|
141
94
|
throw error;
|
|
142
95
|
}
|
|
143
96
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Gets or creates a subscription payment URL.
|
|
146
|
-
* Checks for recent pending payments (within 3 minutes) and reuses the payment link if found.
|
|
147
|
-
* Otherwise creates a new payment intent for the subscription.
|
|
148
|
-
* @param params - Payment URL creation parameters
|
|
149
|
-
* @param params.userId - The user's unique identifier
|
|
150
|
-
* @param params.appNamespace - The application namespace/platform
|
|
151
|
-
* @param params.planId - The subscription plan identifier
|
|
152
|
-
* @param params.languageCode - Language code for translations
|
|
153
|
-
* @param params.translate - Translation function
|
|
154
|
-
* @returns Promise resolving to the payment URL string
|
|
155
|
-
* @throws Error if subscription plan not found or payment creation fails
|
|
156
|
-
*/
|
|
157
97
|
async getOrCreateSubscriptionPaymentUrl(params) {
|
|
158
98
|
try {
|
|
159
99
|
// Check for existing pending payments for this plan
|
|
160
100
|
const existingPayments = await this.paymentService.getByUserId({
|
|
161
101
|
userId: params.userId,
|
|
162
|
-
|
|
102
|
+
platform: params.platform,
|
|
163
103
|
status: 'pending',
|
|
164
104
|
});
|
|
165
105
|
const recentPayment = existingPayments
|
|
@@ -178,7 +118,7 @@ class SubscriptionService {
|
|
|
178
118
|
}));
|
|
179
119
|
const paymentEntity = await this.paymentService.createPaymentIntent({
|
|
180
120
|
userId: params.userId,
|
|
181
|
-
|
|
121
|
+
platform: params.platform,
|
|
182
122
|
planId: subscriptionPlan.id,
|
|
183
123
|
productName,
|
|
184
124
|
productPrice: subscriptionPlan.amount,
|
|
@@ -193,7 +133,7 @@ class SubscriptionService {
|
|
|
193
133
|
message: 'Error in subscription service getOrCreateSubscriptionPaymentUrl',
|
|
194
134
|
payload: {
|
|
195
135
|
userId: params.userId,
|
|
196
|
-
|
|
136
|
+
platform: params.platform,
|
|
197
137
|
planId: params.planId,
|
|
198
138
|
error: JSON.stringify(error),
|
|
199
139
|
},
|
|
@@ -201,19 +141,6 @@ class SubscriptionService {
|
|
|
201
141
|
throw error;
|
|
202
142
|
}
|
|
203
143
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Activates a subscription for a user.
|
|
206
|
-
* This operation is transactional - it creates/updates the subscription document
|
|
207
|
-
* and updates the user's subscription status atomically.
|
|
208
|
-
* @param params - Activation parameters
|
|
209
|
-
* @param params.userId - The user's unique identifier
|
|
210
|
-
* @param params.appNamespace - The application namespace/platform
|
|
211
|
-
* @param params.startedAt - ISO timestamp when subscription period starts
|
|
212
|
-
* @param params.expiresAt - ISO timestamp when subscription period ends
|
|
213
|
-
* @param params.planId - The subscription plan identifier
|
|
214
|
-
* @param params.provider - Payment provider (e.g., 'wayforpay')
|
|
215
|
-
* @throws Error if user not found or activation fails
|
|
216
|
-
*/
|
|
217
144
|
async activateSubscription(params) {
|
|
218
145
|
try {
|
|
219
146
|
await this.repository.activateSubscription(params);
|
|
@@ -223,7 +150,7 @@ class SubscriptionService {
|
|
|
223
150
|
message: 'Error in subscription service activateSubscription',
|
|
224
151
|
payload: {
|
|
225
152
|
userId: params.userId,
|
|
226
|
-
|
|
153
|
+
platform: params.platform,
|
|
227
154
|
planId: params.planId,
|
|
228
155
|
error: JSON.stringify(error),
|
|
229
156
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAkF;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAkF;AAElF,mCAAoE;AACpE,iDAAqD;AAGrD,MAAa,mBAAmB;IAI5B,YAAY,EACR,MAAM,EACN,UAAU,EACV,cAAc,GAKjB;QACG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,IAAI,mCAAsB,EAAE,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,cAAc,IAAI,IAAI,wBAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,MAI7B;QACG,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC1D,CA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YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,iEAAiE;gBAC1E,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,MAAiD;QAC/E,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,oDAAoD;gBAC7D,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AArMD,kDAqMC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
-
import { AppNamespace } from '../app/types';
|
|
3
2
|
type SubscriptionEntity = {
|
|
4
3
|
/** Auto-generated unique ID (document ID) */
|
|
5
4
|
id?: string;
|
|
@@ -14,7 +13,7 @@ type SubscriptionEntity = {
|
|
|
14
13
|
/** Timestamp when this period began */
|
|
15
14
|
startedAt: string;
|
|
16
15
|
/** Platform/app namespace */
|
|
17
|
-
platform:
|
|
16
|
+
platform: string;
|
|
18
17
|
/** Payment provider */
|
|
19
18
|
provider: 'wayforpay';
|
|
20
19
|
};
|
|
@@ -33,5 +32,130 @@ type SubscriptionPlan = {
|
|
|
33
32
|
regularMode: 'daily' | 'monthly' | 'yearly';
|
|
34
33
|
};
|
|
35
34
|
type SubscriptionFieldPath = NestedPathsAccess<SubscriptionEntity>;
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Interface for subscription repository operations.
|
|
37
|
+
* Defines the contract for data access layer.
|
|
38
|
+
*/
|
|
39
|
+
interface ISubscriptionRepository {
|
|
40
|
+
/**
|
|
41
|
+
* Retrieves a subscription for a specific user.
|
|
42
|
+
* @param params - Query parameters
|
|
43
|
+
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
44
|
+
*/
|
|
45
|
+
findSubscription(params: {
|
|
46
|
+
userId: string;
|
|
47
|
+
platform: string;
|
|
48
|
+
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
49
|
+
}): Promise<SubscriptionEntity | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a new subscription record in the database.
|
|
52
|
+
* @param params - Subscription creation parameters
|
|
53
|
+
* @returns Promise resolving to created SubscriptionEntity with ID
|
|
54
|
+
*/
|
|
55
|
+
create(params: {
|
|
56
|
+
userId: string;
|
|
57
|
+
platform: string;
|
|
58
|
+
planId: string;
|
|
59
|
+
expiresAt: string;
|
|
60
|
+
startedAt: string;
|
|
61
|
+
}): Promise<SubscriptionEntity>;
|
|
62
|
+
/**
|
|
63
|
+
* Updates specific fields of a subscription identified by userId and platform.
|
|
64
|
+
* @param params - Update parameters
|
|
65
|
+
*/
|
|
66
|
+
updateFieldsByUserId(params: {
|
|
67
|
+
userId: string;
|
|
68
|
+
platform: string;
|
|
69
|
+
fields: any;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves all active subscriptions that have expired.
|
|
73
|
+
* @returns Promise resolving to array of expired SubscriptionEntity
|
|
74
|
+
*/
|
|
75
|
+
getExpiredActiveSubscriptions(): Promise<SubscriptionEntity[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Updates specific fields of a subscription identified by subscription ID.
|
|
78
|
+
* @param params - Update parameters
|
|
79
|
+
*/
|
|
80
|
+
updateFieldsById(params: {
|
|
81
|
+
subscriptionId: string;
|
|
82
|
+
fields: any;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Activates a subscription for a user using a transaction.
|
|
86
|
+
* @param params - Activation parameters
|
|
87
|
+
*/
|
|
88
|
+
activateSubscription(params: Omit<SubscriptionEntity, 'id' | 'status'>): Promise<void>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Interface for subscription service operations.
|
|
92
|
+
* Defines the contract for business logic layer.
|
|
93
|
+
*/
|
|
94
|
+
interface ISubscriptionService {
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves a subscription for a specific user.
|
|
97
|
+
* @param params - Query parameters
|
|
98
|
+
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
99
|
+
*/
|
|
100
|
+
findSubscription(params: {
|
|
101
|
+
userId: string;
|
|
102
|
+
platform: string;
|
|
103
|
+
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
104
|
+
}): Promise<SubscriptionEntity | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new subscription record in the database.
|
|
107
|
+
* @param params - Subscription creation parameters
|
|
108
|
+
* @returns Promise resolving to created SubscriptionEntity with ID
|
|
109
|
+
*/
|
|
110
|
+
create(params: {
|
|
111
|
+
userId: string;
|
|
112
|
+
platform: string;
|
|
113
|
+
planId: string;
|
|
114
|
+
expiresAt: string;
|
|
115
|
+
startedAt: string;
|
|
116
|
+
}): Promise<SubscriptionEntity>;
|
|
117
|
+
/**
|
|
118
|
+
* Updates specific fields of a subscription identified by userId and platform.
|
|
119
|
+
* @param params - Update parameters
|
|
120
|
+
*/
|
|
121
|
+
updateFieldsByUserId(params: {
|
|
122
|
+
userId: string;
|
|
123
|
+
platform: string;
|
|
124
|
+
fields: any;
|
|
125
|
+
}): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieves all active subscriptions that have expired.
|
|
128
|
+
* @returns Promise resolving to array of expired SubscriptionEntity
|
|
129
|
+
*/
|
|
130
|
+
getExpiredActiveSubscriptions(): Promise<SubscriptionEntity[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Updates specific fields of a subscription identified by subscription ID.
|
|
133
|
+
* @param params - Update parameters
|
|
134
|
+
*/
|
|
135
|
+
updateFieldsById(params: {
|
|
136
|
+
subscriptionId: string;
|
|
137
|
+
fields: any;
|
|
138
|
+
}): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Gets or creates a subscription payment URL.
|
|
141
|
+
* @param params - Payment URL creation parameters
|
|
142
|
+
* @returns Promise resolving to the payment URL string
|
|
143
|
+
*/
|
|
144
|
+
getOrCreateSubscriptionPaymentUrl(params: {
|
|
145
|
+
userId: string;
|
|
146
|
+
platform: string;
|
|
147
|
+
planId: string;
|
|
148
|
+
languageCode: string;
|
|
149
|
+
translate: (params: {
|
|
150
|
+
code: string;
|
|
151
|
+
path: string;
|
|
152
|
+
}) => string;
|
|
153
|
+
}): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Activates a subscription for a user.
|
|
156
|
+
* @param params - Activation parameters
|
|
157
|
+
*/
|
|
158
|
+
activateSubscription(params: Omit<SubscriptionEntity, 'id' | 'status'>): Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
export type { SubscriptionEntity, SubscriptionPlan, SubscriptionFieldPath, ISubscriptionRepository, ISubscriptionService, };
|
|
37
161
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/types.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AAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEhC;;;OAGG;IACH,oBAAoB,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE/F;;;OAGG;IACH,6BAA6B,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAE/D;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjF;;;;OAIG;IACH,iCAAiC,CAAC,MAAM,EAAE;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,CAAC,MAAM,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,KAAK,MAAM,CAAC;KACjE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpB;;;OAGG;IACH,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,IAAI,GAAG,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1F;AAED,YAAY,EACR,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,GACvB,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
-
import { AppNamespace } from '../app/types';
|
|
3
2
|
export interface User {
|
|
4
3
|
user: {
|
|
5
4
|
id: string;
|
|
@@ -34,7 +33,7 @@ export interface User {
|
|
|
34
33
|
}
|
|
35
34
|
export interface UserAnalytics {
|
|
36
35
|
id: string;
|
|
37
|
-
platform:
|
|
36
|
+
platform: string;
|
|
38
37
|
createdDate: string;
|
|
39
38
|
chatGPT: {
|
|
40
39
|
completions: Partial<Record<number, {
|
|
@@ -75,4 +74,70 @@ export interface UserAnalytics {
|
|
|
75
74
|
}
|
|
76
75
|
export type UserFieldPath = NestedPathsAccess<User>;
|
|
77
76
|
export type UserFieldAnalyticsPath = NestedPathsAccess<UserAnalytics>;
|
|
77
|
+
/**
|
|
78
|
+
* Interface for user repository operations.
|
|
79
|
+
* Defines the contract for data access layer.
|
|
80
|
+
*/
|
|
81
|
+
export interface IUserRepository {
|
|
82
|
+
/**
|
|
83
|
+
* Retrieves a user by their ID.
|
|
84
|
+
* @param params - Query parameters
|
|
85
|
+
* @returns Promise resolving to User or null if not found
|
|
86
|
+
*/
|
|
87
|
+
getByUserId(params: {
|
|
88
|
+
userId: string;
|
|
89
|
+
platform: string;
|
|
90
|
+
}): Promise<User | null>;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new user record in the database.
|
|
93
|
+
* @param params - User creation parameters
|
|
94
|
+
* @returns Promise resolving when user is created
|
|
95
|
+
*/
|
|
96
|
+
create(params: {
|
|
97
|
+
user: User;
|
|
98
|
+
platform: string;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Updates specific fields of a user identified by userId.
|
|
102
|
+
* @param params - Update parameters
|
|
103
|
+
*/
|
|
104
|
+
updateFieldsByUserId(params: {
|
|
105
|
+
platform: string;
|
|
106
|
+
userId: string;
|
|
107
|
+
fields: any;
|
|
108
|
+
}): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Interface for user service operations.
|
|
112
|
+
* Defines the contract for business logic layer.
|
|
113
|
+
*/
|
|
114
|
+
export interface IUserService {
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves a user by their ID.
|
|
117
|
+
* @param params - Query parameters
|
|
118
|
+
* @returns Promise resolving to User or null if not found
|
|
119
|
+
*/
|
|
120
|
+
getByUserId(params: {
|
|
121
|
+
userId: string;
|
|
122
|
+
platform: string;
|
|
123
|
+
}): Promise<User | null>;
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new user record in the database.
|
|
126
|
+
* @param params - User creation parameters
|
|
127
|
+
* @returns Promise resolving when user is created
|
|
128
|
+
*/
|
|
129
|
+
create(params: {
|
|
130
|
+
user: User;
|
|
131
|
+
platform: string;
|
|
132
|
+
}): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Updates specific fields of a user identified by userId.
|
|
135
|
+
* @param params - Update parameters
|
|
136
|
+
*/
|
|
137
|
+
updateFieldsByUserId(params: {
|
|
138
|
+
platform: string;
|
|
139
|
+
userId: string;
|
|
140
|
+
fields: any;
|
|
141
|
+
}): Promise<void>;
|
|
142
|
+
}
|
|
78
143
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/user/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/user/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,MAAM,WAAW,IAAI;IACjB,IAAI,EAAE;QACF,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;QAC1B,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;KACvB,CAAC;IACF,YAAY,EAAE;QACV,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE;YACP,MAAM,EAAE,MAAM,CAAC;YACf,cAAc,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