@misterhomer1992/miit-bot-payment 1.0.7 → 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 +0 -25
- package/dist/modules/invoice/repository.d.ts.map +1 -1
- package/dist/modules/invoice/repository.js +0 -25
- package/dist/modules/invoice/repository.js.map +1 -1
- package/dist/modules/invoice/service.d.ts +0 -21
- package/dist/modules/invoice/service.d.ts.map +1 -1
- package/dist/modules/invoice/service.js +0 -21
- package/dist/modules/invoice/service.js.map +1 -1
- package/dist/modules/invoice/types.d.ts +0 -8
- 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 +1 -59
- package/dist/modules/payments/repository.d.ts.map +1 -1
- package/dist/modules/payments/repository.js +2 -59
- package/dist/modules/payments/repository.js.map +1 -1
- package/dist/modules/payments/service.d.ts +2 -66
- package/dist/modules/payments/service.d.ts.map +1 -1
- package/dist/modules/payments/service.js +5 -68
- package/dist/modules/payments/service.js.map +1 -1
- package/dist/modules/payments/types.d.ts +4 -11
- 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 +4 -83
- package/dist/modules/subscription/repository.d.ts.map +1 -1
- package/dist/modules/subscription/repository.js +15 -109
- package/dist/modules/subscription/repository.js.map +1 -1
- package/dist/modules/subscription/service.d.ts +5 -89
- package/dist/modules/subscription/service.d.ts.map +1 -1
- package/dist/modules/subscription/service.js +7 -83
- package/dist/modules/subscription/service.js.map +1 -1
- package/dist/modules/subscription/types.d.ts +12 -27
- package/dist/modules/subscription/types.d.ts.map +1 -1
- package/dist/modules/user/types.d.ts +7 -8
- package/dist/modules/user/types.d.ts.map +1 -1
- package/dist/modules/user/userRepository.d.ts +3 -46
- package/dist/modules/user/userRepository.d.ts.map +1 -1
- package/dist/modules/user/userRepository.js +6 -48
- package/dist/modules/user/userRepository.js.map +1 -1
- package/dist/modules/user/userService.d.ts +3 -37
- package/dist/modules/user/userService.d.ts.map +1 -1
- package/dist/modules/user/userService.js +3 -36
- package/dist/modules/user/userService.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,31 +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 params - Service dependencies
|
|
19
|
-
* @param params.logger - Application logger instance for logging operations
|
|
20
|
-
* @param params.repository - Optional subscription repository instance for dependency injection (defaults to new SubscriptionRepository())
|
|
21
|
-
* @param params.paymentService - Optional payment service instance for dependency injection (defaults to new PaymentService())
|
|
22
|
-
*/
|
|
23
12
|
constructor({ logger, repository, paymentService, }) {
|
|
24
13
|
this.logger = logger;
|
|
25
14
|
this.repository = repository || new repository_1.SubscriptionRepository();
|
|
26
15
|
this.paymentService = paymentService || new service_1.PaymentService({ logger });
|
|
27
16
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves a subscription for a specific user.
|
|
30
|
-
* @param params - Query parameters
|
|
31
|
-
* @param params.userId - The user's unique identifier
|
|
32
|
-
* @param params.appNamespace - The application namespace/platform
|
|
33
|
-
* @param params.status - Optional status filter. Can be a single status or array of statuses. Defaults to 'active'
|
|
34
|
-
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
35
|
-
*/
|
|
36
17
|
async findSubscription(params) {
|
|
37
18
|
try {
|
|
38
19
|
return await this.repository.findSubscription(params);
|
|
@@ -42,24 +23,13 @@ class SubscriptionService {
|
|
|
42
23
|
message: 'Error in subscription service findSubscription',
|
|
43
24
|
payload: {
|
|
44
25
|
userId: params.userId,
|
|
45
|
-
|
|
26
|
+
platform: params.platform,
|
|
46
27
|
error: JSON.stringify(error),
|
|
47
28
|
},
|
|
48
29
|
});
|
|
49
30
|
return null;
|
|
50
31
|
}
|
|
51
32
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new subscription record in the database.
|
|
54
|
-
* @param params - Subscription creation parameters
|
|
55
|
-
* @param params.userId - The user's unique identifier
|
|
56
|
-
* @param params.appNamespace - The application namespace/platform
|
|
57
|
-
* @param params.planId - The subscription plan identifier
|
|
58
|
-
* @param params.expiresAt - ISO timestamp when subscription expires
|
|
59
|
-
* @param params.startedAt - ISO timestamp when subscription started
|
|
60
|
-
* @returns Promise resolving to created SubscriptionEntity with ID
|
|
61
|
-
* @throws Error if subscription creation fails
|
|
62
|
-
*/
|
|
63
33
|
async create(params) {
|
|
64
34
|
try {
|
|
65
35
|
return await this.repository.create(params);
|
|
@@ -69,7 +39,7 @@ class SubscriptionService {
|
|
|
69
39
|
message: 'Error in subscription service create',
|
|
70
40
|
payload: {
|
|
71
41
|
userId: params.userId,
|
|
72
|
-
|
|
42
|
+
platform: params.platform,
|
|
73
43
|
planId: params.planId,
|
|
74
44
|
error: JSON.stringify(error),
|
|
75
45
|
},
|
|
@@ -77,14 +47,6 @@ class SubscriptionService {
|
|
|
77
47
|
throw error;
|
|
78
48
|
}
|
|
79
49
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Updates specific fields of a subscription identified by userId and appNamespace.
|
|
82
|
-
* @param params - Update parameters
|
|
83
|
-
* @param params.userId - The user's unique identifier
|
|
84
|
-
* @param params.appNamespace - The application namespace/platform
|
|
85
|
-
* @param params.fields - Array of field paths and values to update
|
|
86
|
-
* @throws Error if subscription not found or update fails
|
|
87
|
-
*/
|
|
88
50
|
async updateFieldsByUserId(params) {
|
|
89
51
|
try {
|
|
90
52
|
await this.repository.updateFieldsByUserId(params);
|
|
@@ -94,7 +56,7 @@ class SubscriptionService {
|
|
|
94
56
|
message: 'Error in subscription service updateFieldsByUserId',
|
|
95
57
|
payload: {
|
|
96
58
|
userId: params.userId,
|
|
97
|
-
|
|
59
|
+
platform: params.platform,
|
|
98
60
|
fields: JSON.stringify(params.fields),
|
|
99
61
|
error: JSON.stringify(error),
|
|
100
62
|
},
|
|
@@ -102,11 +64,6 @@ class SubscriptionService {
|
|
|
102
64
|
throw error;
|
|
103
65
|
}
|
|
104
66
|
}
|
|
105
|
-
/**
|
|
106
|
-
* Retrieves all active subscriptions that have expired.
|
|
107
|
-
* Used for batch processing to update subscription statuses.
|
|
108
|
-
* @returns Promise resolving to array of expired SubscriptionEntity
|
|
109
|
-
*/
|
|
110
67
|
async getExpiredActiveSubscriptions() {
|
|
111
68
|
try {
|
|
112
69
|
return await this.repository.getExpiredActiveSubscriptions();
|
|
@@ -121,13 +78,6 @@ class SubscriptionService {
|
|
|
121
78
|
return [];
|
|
122
79
|
}
|
|
123
80
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Updates specific fields of a subscription identified by subscription ID.
|
|
126
|
-
* @param params - Update parameters
|
|
127
|
-
* @param params.subscriptionId - The subscription document ID
|
|
128
|
-
* @param params.fields - Array of field paths and values to update
|
|
129
|
-
* @throws Error if update fails
|
|
130
|
-
*/
|
|
131
81
|
async updateFieldsById(params) {
|
|
132
82
|
try {
|
|
133
83
|
await this.repository.updateFieldsById(params);
|
|
@@ -144,25 +94,12 @@ class SubscriptionService {
|
|
|
144
94
|
throw error;
|
|
145
95
|
}
|
|
146
96
|
}
|
|
147
|
-
/**
|
|
148
|
-
* Gets or creates a subscription payment URL.
|
|
149
|
-
* Checks for recent pending payments (within 3 minutes) and reuses the payment link if found.
|
|
150
|
-
* Otherwise creates a new payment intent for the subscription.
|
|
151
|
-
* @param params - Payment URL creation parameters
|
|
152
|
-
* @param params.userId - The user's unique identifier
|
|
153
|
-
* @param params.appNamespace - The application namespace/platform
|
|
154
|
-
* @param params.planId - The subscription plan identifier
|
|
155
|
-
* @param params.languageCode - Language code for translations
|
|
156
|
-
* @param params.translate - Translation function
|
|
157
|
-
* @returns Promise resolving to the payment URL string
|
|
158
|
-
* @throws Error if subscription plan not found or payment creation fails
|
|
159
|
-
*/
|
|
160
97
|
async getOrCreateSubscriptionPaymentUrl(params) {
|
|
161
98
|
try {
|
|
162
99
|
// Check for existing pending payments for this plan
|
|
163
100
|
const existingPayments = await this.paymentService.getByUserId({
|
|
164
101
|
userId: params.userId,
|
|
165
|
-
|
|
102
|
+
platform: params.platform,
|
|
166
103
|
status: 'pending',
|
|
167
104
|
});
|
|
168
105
|
const recentPayment = existingPayments
|
|
@@ -181,7 +118,7 @@ class SubscriptionService {
|
|
|
181
118
|
}));
|
|
182
119
|
const paymentEntity = await this.paymentService.createPaymentIntent({
|
|
183
120
|
userId: params.userId,
|
|
184
|
-
|
|
121
|
+
platform: params.platform,
|
|
185
122
|
planId: subscriptionPlan.id,
|
|
186
123
|
productName,
|
|
187
124
|
productPrice: subscriptionPlan.amount,
|
|
@@ -196,7 +133,7 @@ class SubscriptionService {
|
|
|
196
133
|
message: 'Error in subscription service getOrCreateSubscriptionPaymentUrl',
|
|
197
134
|
payload: {
|
|
198
135
|
userId: params.userId,
|
|
199
|
-
|
|
136
|
+
platform: params.platform,
|
|
200
137
|
planId: params.planId,
|
|
201
138
|
error: JSON.stringify(error),
|
|
202
139
|
},
|
|
@@ -204,19 +141,6 @@ class SubscriptionService {
|
|
|
204
141
|
throw error;
|
|
205
142
|
}
|
|
206
143
|
}
|
|
207
|
-
/**
|
|
208
|
-
* Activates a subscription for a user.
|
|
209
|
-
* This operation is transactional - it creates/updates the subscription document
|
|
210
|
-
* and updates the user's subscription status atomically.
|
|
211
|
-
* @param params - Activation parameters
|
|
212
|
-
* @param params.userId - The user's unique identifier
|
|
213
|
-
* @param params.appNamespace - The application namespace/platform
|
|
214
|
-
* @param params.startedAt - ISO timestamp when subscription period starts
|
|
215
|
-
* @param params.expiresAt - ISO timestamp when subscription period ends
|
|
216
|
-
* @param params.planId - The subscription plan identifier
|
|
217
|
-
* @param params.provider - Payment provider (e.g., 'wayforpay')
|
|
218
|
-
* @throws Error if user not found or activation fails
|
|
219
|
-
*/
|
|
220
144
|
async activateSubscription(params) {
|
|
221
145
|
try {
|
|
222
146
|
await this.repository.activateSubscription(params);
|
|
@@ -226,7 +150,7 @@ class SubscriptionService {
|
|
|
226
150
|
message: 'Error in subscription service activateSubscription',
|
|
227
151
|
payload: {
|
|
228
152
|
userId: params.userId,
|
|
229
|
-
|
|
153
|
+
platform: params.platform,
|
|
230
154
|
planId: params.planId,
|
|
231
155
|
error: JSON.stringify(error),
|
|
232
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,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AAC,QAAQ;gBACnC,QAAQ,EAAE,MAAM,CAAC,YAAY;gBAC7B,WAAW,EAAE,gBAAgB,CAAC,WAAW;aAC5C,CAAC,CAAC;YAEH,OAAO,aAAa,CAAC,WAAW,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;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
|
};
|
|
@@ -45,7 +44,7 @@ interface ISubscriptionRepository {
|
|
|
45
44
|
*/
|
|
46
45
|
findSubscription(params: {
|
|
47
46
|
userId: string;
|
|
48
|
-
|
|
47
|
+
platform: string;
|
|
49
48
|
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
50
49
|
}): Promise<SubscriptionEntity | null>;
|
|
51
50
|
/**
|
|
@@ -55,18 +54,18 @@ interface ISubscriptionRepository {
|
|
|
55
54
|
*/
|
|
56
55
|
create(params: {
|
|
57
56
|
userId: string;
|
|
58
|
-
|
|
57
|
+
platform: string;
|
|
59
58
|
planId: string;
|
|
60
59
|
expiresAt: string;
|
|
61
60
|
startedAt: string;
|
|
62
61
|
}): Promise<SubscriptionEntity>;
|
|
63
62
|
/**
|
|
64
|
-
* Updates specific fields of a subscription identified by userId and
|
|
63
|
+
* Updates specific fields of a subscription identified by userId and platform.
|
|
65
64
|
* @param params - Update parameters
|
|
66
65
|
*/
|
|
67
66
|
updateFieldsByUserId(params: {
|
|
68
67
|
userId: string;
|
|
69
|
-
|
|
68
|
+
platform: string;
|
|
70
69
|
fields: any;
|
|
71
70
|
}): Promise<void>;
|
|
72
71
|
/**
|
|
@@ -86,14 +85,7 @@ interface ISubscriptionRepository {
|
|
|
86
85
|
* Activates a subscription for a user using a transaction.
|
|
87
86
|
* @param params - Activation parameters
|
|
88
87
|
*/
|
|
89
|
-
activateSubscription(params:
|
|
90
|
-
userId: string;
|
|
91
|
-
appNamespace: AppNamespace;
|
|
92
|
-
startedAt: string;
|
|
93
|
-
expiresAt: string;
|
|
94
|
-
planId: string;
|
|
95
|
-
provider: 'wayforpay';
|
|
96
|
-
}): Promise<void>;
|
|
88
|
+
activateSubscription(params: Omit<SubscriptionEntity, 'id' | 'status'>): Promise<void>;
|
|
97
89
|
}
|
|
98
90
|
/**
|
|
99
91
|
* Interface for subscription service operations.
|
|
@@ -107,7 +99,7 @@ interface ISubscriptionService {
|
|
|
107
99
|
*/
|
|
108
100
|
findSubscription(params: {
|
|
109
101
|
userId: string;
|
|
110
|
-
|
|
102
|
+
platform: string;
|
|
111
103
|
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
112
104
|
}): Promise<SubscriptionEntity | null>;
|
|
113
105
|
/**
|
|
@@ -117,18 +109,18 @@ interface ISubscriptionService {
|
|
|
117
109
|
*/
|
|
118
110
|
create(params: {
|
|
119
111
|
userId: string;
|
|
120
|
-
|
|
112
|
+
platform: string;
|
|
121
113
|
planId: string;
|
|
122
114
|
expiresAt: string;
|
|
123
115
|
startedAt: string;
|
|
124
116
|
}): Promise<SubscriptionEntity>;
|
|
125
117
|
/**
|
|
126
|
-
* Updates specific fields of a subscription identified by userId and
|
|
118
|
+
* Updates specific fields of a subscription identified by userId and platform.
|
|
127
119
|
* @param params - Update parameters
|
|
128
120
|
*/
|
|
129
121
|
updateFieldsByUserId(params: {
|
|
130
122
|
userId: string;
|
|
131
|
-
|
|
123
|
+
platform: string;
|
|
132
124
|
fields: any;
|
|
133
125
|
}): Promise<void>;
|
|
134
126
|
/**
|
|
@@ -151,7 +143,7 @@ interface ISubscriptionService {
|
|
|
151
143
|
*/
|
|
152
144
|
getOrCreateSubscriptionPaymentUrl(params: {
|
|
153
145
|
userId: string;
|
|
154
|
-
|
|
146
|
+
platform: string;
|
|
155
147
|
planId: string;
|
|
156
148
|
languageCode: string;
|
|
157
149
|
translate: (params: {
|
|
@@ -163,14 +155,7 @@ interface ISubscriptionService {
|
|
|
163
155
|
* Activates a subscription for a user.
|
|
164
156
|
* @param params - Activation parameters
|
|
165
157
|
*/
|
|
166
|
-
activateSubscription(params:
|
|
167
|
-
userId: string;
|
|
168
|
-
appNamespace: AppNamespace;
|
|
169
|
-
startedAt: string;
|
|
170
|
-
expiresAt: string;
|
|
171
|
-
planId: string;
|
|
172
|
-
provider: 'wayforpay';
|
|
173
|
-
}): Promise<void>;
|
|
158
|
+
activateSubscription(params: Omit<SubscriptionEntity, 'id' | 'status'>): Promise<void>;
|
|
174
159
|
}
|
|
175
160
|
export type { SubscriptionEntity, SubscriptionPlan, SubscriptionFieldPath, ISubscriptionRepository, ISubscriptionService, };
|
|
176
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.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,KAAK,kBAAkB,GAAG;IACtB,6CAA6C;IAC7C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;IAC3C,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;IAClB,uCAAuC;IACvC,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,QAAQ,EAAE,WAAW,CAAC;CACzB,CAAC;AAEF,KAAK,gBAAgB,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,GAA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E,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, {
|
|
@@ -87,7 +86,7 @@ export interface IUserRepository {
|
|
|
87
86
|
*/
|
|
88
87
|
getByUserId(params: {
|
|
89
88
|
userId: string;
|
|
90
|
-
|
|
89
|
+
platform: string;
|
|
91
90
|
}): Promise<User | null>;
|
|
92
91
|
/**
|
|
93
92
|
* Creates a new user record in the database.
|
|
@@ -96,14 +95,14 @@ export interface IUserRepository {
|
|
|
96
95
|
*/
|
|
97
96
|
create(params: {
|
|
98
97
|
user: User;
|
|
99
|
-
|
|
98
|
+
platform: string;
|
|
100
99
|
}): Promise<void>;
|
|
101
100
|
/**
|
|
102
101
|
* Updates specific fields of a user identified by userId.
|
|
103
102
|
* @param params - Update parameters
|
|
104
103
|
*/
|
|
105
104
|
updateFieldsByUserId(params: {
|
|
106
|
-
|
|
105
|
+
platform: string;
|
|
107
106
|
userId: string;
|
|
108
107
|
fields: any;
|
|
109
108
|
}): Promise<void>;
|
|
@@ -120,7 +119,7 @@ export interface IUserService {
|
|
|
120
119
|
*/
|
|
121
120
|
getByUserId(params: {
|
|
122
121
|
userId: string;
|
|
123
|
-
|
|
122
|
+
platform: string;
|
|
124
123
|
}): Promise<User | null>;
|
|
125
124
|
/**
|
|
126
125
|
* Creates a new user record in the database.
|
|
@@ -129,14 +128,14 @@ export interface IUserService {
|
|
|
129
128
|
*/
|
|
130
129
|
create(params: {
|
|
131
130
|
user: User;
|
|
132
|
-
|
|
131
|
+
platform: string;
|
|
133
132
|
}): Promise<void>;
|
|
134
133
|
/**
|
|
135
134
|
* Updates specific fields of a user identified by userId.
|
|
136
135
|
* @param params - Update parameters
|
|
137
136
|
*/
|
|
138
137
|
updateFieldsByUserId(params: {
|
|
139
|
-
|
|
138
|
+
platform: string;
|
|
140
139
|
userId: string;
|
|
141
140
|
fields: any;
|
|
142
141
|
}): Promise<void>;
|
|
@@ -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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,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAEhF;;;;OAIG;IACH,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhE;;;OAGG;IACH,oBAAoB,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,GAAG,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClG"}
|
|
@@ -1,68 +1,25 @@
|
|
|
1
1
|
import { FieldValue, Firestore } from 'firebase-admin/firestore';
|
|
2
2
|
import { User, UserFieldPath, IUserRepository } from './types';
|
|
3
|
-
import { AppNamespace } from '../app/types';
|
|
4
3
|
export type UpdateDBUserFields = [UserFieldPath, FieldValue | string | number | boolean | Date | [] | {}][];
|
|
5
|
-
/**
|
|
6
|
-
* UserRepository class handles all database operations related to users.
|
|
7
|
-
* Implements repository pattern for user data access.
|
|
8
|
-
*/
|
|
9
4
|
export declare class UserRepository implements IUserRepository {
|
|
10
5
|
private readonly db;
|
|
11
|
-
/**
|
|
12
|
-
* Creates an instance of UserRepository.
|
|
13
|
-
* @param params - Repository dependencies
|
|
14
|
-
* @param params.db - Optional Firestore instance for dependency injection (defaults to getFirestore())
|
|
15
|
-
*/
|
|
16
6
|
constructor({ db }?: {
|
|
17
7
|
db?: Firestore;
|
|
18
8
|
});
|
|
19
|
-
/**
|
|
20
|
-
* Retrieves a user by their ID.
|
|
21
|
-
* @param params - Query parameters
|
|
22
|
-
* @param params.userId - The user's unique identifier
|
|
23
|
-
* @param params.appNamespace - The application namespace/platform
|
|
24
|
-
* @returns Promise resolving to User or null if not found
|
|
25
|
-
*/
|
|
26
9
|
getByUserId(params: {
|
|
27
10
|
userId: string;
|
|
28
|
-
|
|
11
|
+
platform: string;
|
|
29
12
|
}): Promise<User | null>;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a new user record in the database.
|
|
32
|
-
* @param params - User creation parameters
|
|
33
|
-
* @param params.user - The user data to create
|
|
34
|
-
* @param params.appNamespace - The application namespace/platform
|
|
35
|
-
* @returns Promise resolving when user is created
|
|
36
|
-
* @throws Error if user creation fails
|
|
37
|
-
*/
|
|
38
13
|
create(params: {
|
|
39
14
|
user: User;
|
|
40
|
-
|
|
15
|
+
platform: string;
|
|
41
16
|
}): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Updates specific fields of a user identified by userId.
|
|
44
|
-
* @param params - Update parameters
|
|
45
|
-
* @param params.userId - The user's unique identifier
|
|
46
|
-
* @param params.appNamespace - The application namespace/platform
|
|
47
|
-
* @param params.fields - Array of field paths and values to update
|
|
48
|
-
* @throws Error if user not found or update fails
|
|
49
|
-
*/
|
|
50
17
|
updateFieldsByUserId(params: {
|
|
51
|
-
|
|
18
|
+
platform: string;
|
|
52
19
|
userId: string;
|
|
53
20
|
fields: UpdateDBUserFields;
|
|
54
21
|
}): Promise<void>;
|
|
55
|
-
/**
|
|
56
|
-
* Maps a Firestore document to a User entity.
|
|
57
|
-
* @param doc - Firestore document snapshot
|
|
58
|
-
* @returns User entity
|
|
59
|
-
*/
|
|
60
22
|
private mapDocumentToEntity;
|
|
61
|
-
/**
|
|
62
|
-
* Builds an update object from field tuples.
|
|
63
|
-
* @param fields - Array of field paths and values
|
|
64
|
-
* @returns Object with field paths as keys and values to update
|
|
65
|
-
*/
|
|
66
23
|
private buildUpdateObject;
|
|
67
24
|
}
|
|
68
25
|
//# sourceMappingURL=userRepository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userRepository.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkC,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"userRepository.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAkC,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,MAAM,kBAAkB,GAAG,CAAC,aAAa,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAE5G,qBAAa,cAAe,YAAW,eAAe;IAClD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;gBAEnB,EAAE,EAAE,EAAE,GAAE;QAAE,EAAE,CAAC,EAAE,SAAS,CAAA;KAAO;IAI9B,WAAW,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAY/E,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/D,oBAAoB,CAAC,MAAM,EAAE;QACtC,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,kBAAkB,CAAC;KAC9B,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -2,76 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserRepository = void 0;
|
|
4
4
|
const firestore_1 = require("firebase-admin/firestore");
|
|
5
|
-
/**
|
|
6
|
-
* UserRepository class handles all database operations related to users.
|
|
7
|
-
* Implements repository pattern for user data access.
|
|
8
|
-
*/
|
|
9
5
|
class UserRepository {
|
|
10
|
-
/**
|
|
11
|
-
* Creates an instance of UserRepository.
|
|
12
|
-
* @param params - Repository dependencies
|
|
13
|
-
* @param params.db - Optional Firestore instance for dependency injection (defaults to getFirestore())
|
|
14
|
-
*/
|
|
15
6
|
constructor({ db } = {}) {
|
|
16
7
|
this.db = db || (0, firestore_1.getFirestore)();
|
|
17
8
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves a user by their ID.
|
|
20
|
-
* @param params - Query parameters
|
|
21
|
-
* @param params.userId - The user's unique identifier
|
|
22
|
-
* @param params.appNamespace - The application namespace/platform
|
|
23
|
-
* @returns Promise resolving to User or null if not found
|
|
24
|
-
*/
|
|
25
9
|
async getByUserId(params) {
|
|
26
|
-
const { userId,
|
|
27
|
-
const docSnapshot = await this.db.collection(`platform/${
|
|
10
|
+
const { userId, platform } = params;
|
|
11
|
+
const docSnapshot = await this.db.collection(`platform/${platform}/users`).doc(userId).get();
|
|
28
12
|
if (!docSnapshot.exists) {
|
|
29
13
|
return null;
|
|
30
14
|
}
|
|
31
15
|
return this.mapDocumentToEntity(docSnapshot);
|
|
32
16
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates a new user record in the database.
|
|
35
|
-
* @param params - User creation parameters
|
|
36
|
-
* @param params.user - The user data to create
|
|
37
|
-
* @param params.appNamespace - The application namespace/platform
|
|
38
|
-
* @returns Promise resolving when user is created
|
|
39
|
-
* @throws Error if user creation fails
|
|
40
|
-
*/
|
|
41
17
|
async create(params) {
|
|
42
|
-
const { user,
|
|
43
|
-
await this.db.collection(`platform/${
|
|
18
|
+
const { user, platform } = params;
|
|
19
|
+
await this.db.collection(`platform/${platform}/users`).doc(user.user.id).set(user);
|
|
44
20
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Updates specific fields of a user identified by userId.
|
|
47
|
-
* @param params - Update parameters
|
|
48
|
-
* @param params.userId - The user's unique identifier
|
|
49
|
-
* @param params.appNamespace - The application namespace/platform
|
|
50
|
-
* @param params.fields - Array of field paths and values to update
|
|
51
|
-
* @throws Error if user not found or update fails
|
|
52
|
-
*/
|
|
53
21
|
async updateFieldsByUserId(params) {
|
|
54
|
-
const { userId,
|
|
22
|
+
const { userId, platform, fields } = params;
|
|
55
23
|
const updateObject = this.buildUpdateObject(fields);
|
|
56
|
-
const snapshot = await this.db.collection(`platform/${
|
|
24
|
+
const snapshot = await this.db.collection(`platform/${platform}/users`).doc(userId).get();
|
|
57
25
|
if (!snapshot.exists) {
|
|
58
26
|
throw new Error(`User not found: ${userId}`);
|
|
59
27
|
}
|
|
60
28
|
await snapshot.ref.update(updateObject);
|
|
61
29
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Maps a Firestore document to a User entity.
|
|
64
|
-
* @param doc - Firestore document snapshot
|
|
65
|
-
* @returns User entity
|
|
66
|
-
*/
|
|
67
30
|
mapDocumentToEntity(doc) {
|
|
68
31
|
return doc.data();
|
|
69
32
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Builds an update object from field tuples.
|
|
72
|
-
* @param fields - Array of field paths and values
|
|
73
|
-
* @returns Object with field paths as keys and values to update
|
|
74
|
-
*/
|
|
75
33
|
buildUpdateObject(fields) {
|
|
76
34
|
const updateObject = {};
|
|
77
35
|
fields
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userRepository.js","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":";;;AAAA,wDAAiG;
|
|
1
|
+
{"version":3,"file":"userRepository.js","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":";;;AAAA,wDAAiG;AAKjG,MAAa,cAAc;IAGvB,YAAY,EAAE,EAAE,KAAyB,EAAE;QACvC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,IAAA,wBAAY,GAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CA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