@misterhomer1992/miit-bot-payment 1.0.3 → 1.0.5
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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/payments/api.d.ts +26 -1
- package/dist/modules/payments/api.d.ts.map +1 -1
- package/dist/modules/payments/api.js +35 -5
- package/dist/modules/payments/api.js.map +1 -1
- package/dist/modules/payments/index.d.ts +1 -0
- package/dist/modules/payments/index.d.ts.map +1 -1
- package/dist/modules/payments/index.js +1 -0
- package/dist/modules/payments/index.js.map +1 -1
- package/dist/modules/payments/utils.d.ts +12 -1
- package/dist/modules/payments/utils.d.ts.map +1 -1
- package/dist/modules/payments/utils.js +24 -0
- package/dist/modules/payments/utils.js.map +1 -1
- package/dist/modules/subscription/repository.d.ts +24 -1
- package/dist/modules/subscription/repository.d.ts.map +1 -1
- package/dist/modules/subscription/repository.js +75 -6
- package/dist/modules/subscription/repository.js.map +1 -1
- package/dist/modules/subscription/service.d.ts +24 -1
- package/dist/modules/subscription/service.d.ts.map +1 -1
- package/dist/modules/subscription/service.js +32 -1
- package/dist/modules/subscription/service.js.map +1 -1
- package/dist/modules/user/index.d.ts +4 -0
- package/dist/modules/user/index.d.ts.map +1 -0
- package/dist/modules/user/index.js +20 -0
- package/dist/modules/user/index.js.map +1 -0
- package/dist/modules/user/types.d.ts +78 -0
- package/dist/modules/user/types.d.ts.map +1 -0
- package/dist/modules/user/types.js +3 -0
- package/dist/modules/user/types.js.map +1 -0
- package/dist/modules/user/userRepository.d.ts +61 -19
- package/dist/modules/user/userRepository.d.ts.map +1 -1
- package/dist/modules/user/userRepository.js +72 -35
- package/dist/modules/user/userRepository.js.map +1 -1
- package/dist/modules/user/userService.d.ts +54 -0
- package/dist/modules/user/userService.d.ts.map +1 -0
- package/dist/modules/user/userService.js +92 -0
- package/dist/modules/user/userService.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./modules/payments"), exports);
|
|
18
18
|
__exportStar(require("./modules/invoice"), exports);
|
|
19
19
|
__exportStar(require("./modules/subscription"), exports);
|
|
20
|
+
__exportStar(require("./modules/user"), exports);
|
|
20
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC;AAClC,yDAAuC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC;AAClC,yDAAuC;AACvC,iDAA+B"}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { AppNamespace } from '../app/types';
|
|
2
|
+
interface WayforpayResponse {
|
|
3
|
+
url?: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
2
6
|
/**
|
|
3
7
|
* Creates a payment API URL for regular purchases via Wayforpay.
|
|
4
8
|
* Generates a unique order reference and creates a payment URL with the provided parameters.
|
|
@@ -30,5 +34,26 @@ declare function createPaymentAPI({ userId, appNamespace, productName, productPr
|
|
|
30
34
|
url: string;
|
|
31
35
|
orderReference: string;
|
|
32
36
|
} | null>;
|
|
33
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Edits an existing regular purchase via Wayforpay.
|
|
39
|
+
* Updates the parameters of an existing recurring payment schedule.
|
|
40
|
+
*
|
|
41
|
+
* @param params - Parameters for editing the regular purchase
|
|
42
|
+
* @param params.orderReference - The unique reference of the order to edit
|
|
43
|
+
* @param params.amount - The new payment amount
|
|
44
|
+
* @param params.dateBegin - The start date for the regular purchase in DD.MM.YYYY format
|
|
45
|
+
* @param params.dateEnd - The end date for the regular purchase in DD.MM.YYYY format
|
|
46
|
+
* @param params.regularMode - The frequency mode for regular payments
|
|
47
|
+
* @returns Promise resolving to the Wayforpay API response
|
|
48
|
+
* @throws Error with code 'EDIT_REGULAR_PURCHASE_API' if the API response is invalid
|
|
49
|
+
*/
|
|
50
|
+
declare function editRegularPurchaseAPI({ orderReference, amount, dateBegin, dateEnd, regularMode, currency, }: {
|
|
51
|
+
orderReference: string;
|
|
52
|
+
amount: number;
|
|
53
|
+
dateBegin: string;
|
|
54
|
+
dateEnd: string;
|
|
55
|
+
regularMode: 'daily' | 'weekly' | 'monthly' | 'yearly';
|
|
56
|
+
currency: string;
|
|
57
|
+
}): Promise<WayforpayResponse>;
|
|
58
|
+
export { createPaymentAPI, editRegularPurchaseAPI };
|
|
34
59
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C,UAAU,iBAAiB;IACvB,GAAG,CAAC,EAAE,MAA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
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createPaymentAPI = createPaymentAPI;
|
|
7
|
+
exports.editRegularPurchaseAPI = editRegularPurchaseAPI;
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
-
// @ts-ignore - Package may not have type declarations
|
|
10
9
|
const wayforpay_api_1 = require("@misterhomer1992/wayforpay-api");
|
|
11
10
|
const utils_1 = require("../../utils");
|
|
12
11
|
const utils_2 = require("./utils");
|
|
@@ -35,7 +34,7 @@ async function createPaymentAPI({ userId, appNamespace, productName, productPric
|
|
|
35
34
|
planId,
|
|
36
35
|
utcDate: formattedUtc,
|
|
37
36
|
});
|
|
38
|
-
const response = (await (0, wayforpay_api_1.
|
|
37
|
+
const response = (await (0, wayforpay_api_1.generateRegularPurchase)({
|
|
39
38
|
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT,
|
|
40
39
|
merchantDomainName: process.env.WAYFORPAY_MERCHANT_DOMAIN,
|
|
41
40
|
merchantSecretKey: process.env.WAYFORPAY_MERCHANT_SECRET_KEY,
|
|
@@ -43,8 +42,8 @@ async function createPaymentAPI({ userId, appNamespace, productName, productPric
|
|
|
43
42
|
orderReference,
|
|
44
43
|
productName: [productName],
|
|
45
44
|
productPrice: [productPrice],
|
|
46
|
-
currency,
|
|
47
|
-
language,
|
|
45
|
+
currency: currency,
|
|
46
|
+
language: language,
|
|
48
47
|
serviceUrl: process.env.WAYFORPAY_SERVICE_URL,
|
|
49
48
|
regularMode,
|
|
50
49
|
regularCount,
|
|
@@ -60,4 +59,35 @@ async function createPaymentAPI({ userId, appNamespace, productName, productPric
|
|
|
60
59
|
orderReference,
|
|
61
60
|
};
|
|
62
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Edits an existing regular purchase via Wayforpay.
|
|
64
|
+
* Updates the parameters of an existing recurring payment schedule.
|
|
65
|
+
*
|
|
66
|
+
* @param params - Parameters for editing the regular purchase
|
|
67
|
+
* @param params.orderReference - The unique reference of the order to edit
|
|
68
|
+
* @param params.amount - The new payment amount
|
|
69
|
+
* @param params.dateBegin - The start date for the regular purchase in DD.MM.YYYY format
|
|
70
|
+
* @param params.dateEnd - The end date for the regular purchase in DD.MM.YYYY format
|
|
71
|
+
* @param params.regularMode - The frequency mode for regular payments
|
|
72
|
+
* @returns Promise resolving to the Wayforpay API response
|
|
73
|
+
* @throws Error with code 'EDIT_REGULAR_PURCHASE_API' if the API response is invalid
|
|
74
|
+
*/
|
|
75
|
+
async function editRegularPurchaseAPI({ orderReference, amount, dateBegin, dateEnd, regularMode, currency, }) {
|
|
76
|
+
const response = await (0, wayforpay_api_1.editRegularPurchase)({
|
|
77
|
+
merchantAccount: process.env.WAYFORPAY_MERCHANT_ACCOUNT,
|
|
78
|
+
merchantPassword: process.env.WAYFORPAY_MERCHANT_PASSWORD,
|
|
79
|
+
orderReference,
|
|
80
|
+
amount,
|
|
81
|
+
dateBegin,
|
|
82
|
+
dateEnd,
|
|
83
|
+
regularMode,
|
|
84
|
+
currency: currency,
|
|
85
|
+
});
|
|
86
|
+
if (!(0, utils_1.isObject)(response)) {
|
|
87
|
+
throw {
|
|
88
|
+
code: 'EDIT_REGULAR_PURCHASE_API',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
63
93
|
//# sourceMappingURL=api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/modules/payments/api.ts"],"names":[],"mappings":";;;;;AAuIS,4CAAgB;AAAE,wDAAsB;AAvIjD,oDAA4B;AAC5B,kEAAkH;AAElH,uCAA2D;AAC3D,mCAA+C;AAO/C;;;;;;;;;;;;;;;GAeG;AACH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EAClC,cAAc,EACd,MAAM,EACN,SAAS,EACT,OAAO,EACP,WAAW,EACX,QAAQ,GAQX;IACG,MAAM,QAAQ,GAAG,MAAM,IAAA,mCAAmB,EAAC;QACvC,eAAe,EAAE,OAAO,CAAC,GAAG,CAAC,0BAAoC;QACjE,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAAqC;QACnE,cAAc;QACd,MAAM;QACN,SAAS;QACT,OAAO;QACP,WAAW;QACX,QAAQ,EAAE,QAAoB;KACjC,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,gBAAQ,EAAC,QAAQ,CAAC,EAAE,CAAC;QACtB,MAAM;YACF,IAAI,EAAE,2BAA2B;SACpC,CAAC;IACN,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,wCAAsB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/payments/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,wCAAsB;AACtB,0CAAwB"}
|
|
@@ -5,5 +5,16 @@ declare function createOrderReference({ userId, appNamespace, planId, utcDate, }
|
|
|
5
5
|
planId: string;
|
|
6
6
|
utcDate: string;
|
|
7
7
|
}): string;
|
|
8
|
-
export
|
|
8
|
+
export interface ParsedReferenceString {
|
|
9
|
+
appName: string;
|
|
10
|
+
appNamespace: AppNamespace;
|
|
11
|
+
serviceType: string;
|
|
12
|
+
userId: string;
|
|
13
|
+
planId: string;
|
|
14
|
+
version: string;
|
|
15
|
+
timestamp: string;
|
|
16
|
+
chargeId?: string;
|
|
17
|
+
}
|
|
18
|
+
declare function parseOrderReference(referenceString: string): ParsedReferenceString | null;
|
|
19
|
+
export { createOrderReference, parseOrderReference };
|
|
9
20
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,iBAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,GACV,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAET;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,iBAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,GACV,EAAE;IACC,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,CAET;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,iBAAS,mBAAmB,CAAC,eAAe,EAAE,MAAM,GAAG,qBAAqB,GAAG,IAAI,CA2BlF;AAED,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOrderReference = createOrderReference;
|
|
4
|
+
exports.parseOrderReference = parseOrderReference;
|
|
4
5
|
function createOrderReference({ userId, appNamespace, planId, utcDate, }) {
|
|
5
6
|
return `miia_${appNamespace}_bot_${userId}_${planId}_v1_${utcDate}`;
|
|
6
7
|
}
|
|
8
|
+
function parseOrderReference(referenceString) {
|
|
9
|
+
// `miia_${appNamespace}_bot_${userId}_${planId}_v1_${formattedUtc}`;
|
|
10
|
+
const [appName, appNamespace, serviceType, userId, planId, version, timestamp, chargeId] = referenceString.split('_');
|
|
11
|
+
if (typeof appName !== 'string' ||
|
|
12
|
+
typeof appNamespace !== 'string' ||
|
|
13
|
+
typeof serviceType !== 'string' ||
|
|
14
|
+
typeof userId !== 'string' ||
|
|
15
|
+
typeof planId !== 'string' ||
|
|
16
|
+
typeof version !== 'string' ||
|
|
17
|
+
typeof timestamp !== 'string') {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
appName,
|
|
22
|
+
appNamespace: appNamespace,
|
|
23
|
+
serviceType,
|
|
24
|
+
userId,
|
|
25
|
+
planId,
|
|
26
|
+
version,
|
|
27
|
+
timestamp,
|
|
28
|
+
chargeId,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
7
31
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/modules/payments/utils.ts"],"names":[],"mappings":";;AAwDS,oDAAoB;AAAE,kDAAmB;AAtDlD,SAAS,oBAAoB,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,MAAM,EACN,OAAO,GAMV;IACG,OAAO,QAAQ,YAAY,QAAQ,MAAM,IAAI,MAAM,OAAO,OAAO,EAAE,CAAC;AACxE,CAAC;AAaD,SAAS,mBAAmB,CAAC,eAAuB;IAChD,qEAAqE;IACrE,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC,GACpF,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE/B,IACI,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,YAAY,KAAK,QAAQ;QAChC,OAAO,WAAW,KAAK,QAAQ;QAC/B,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,SAAS,KAAK,QAAQ,EAC/B,CAAC;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO;QACP,YAAY,EAAE,YAA4B;QAC1C,WAAW;QACX,MAAM;QACN,MAAM;QACN,OAAO;QACP,SAAS;QACT,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -17,15 +17,17 @@ export declare class SubscriptionRepository {
|
|
|
17
17
|
*/
|
|
18
18
|
constructor();
|
|
19
19
|
/**
|
|
20
|
-
* Retrieves
|
|
20
|
+
* Retrieves a subscription for a specific user.
|
|
21
21
|
* @param params - Query parameters
|
|
22
22
|
* @param params.userId - The user's unique identifier
|
|
23
23
|
* @param params.appNamespace - The application namespace/platform
|
|
24
|
+
* @param params.status - Optional status filter. Can be a single status or array of statuses. Defaults to 'active'
|
|
24
25
|
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
25
26
|
*/
|
|
26
27
|
getByUserId(params: {
|
|
27
28
|
userId: string;
|
|
28
29
|
appNamespace: string;
|
|
30
|
+
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
29
31
|
}): Promise<SubscriptionEntity | null>;
|
|
30
32
|
/**
|
|
31
33
|
* Creates a new subscription record in the database.
|
|
@@ -81,6 +83,27 @@ export declare class SubscriptionRepository {
|
|
|
81
83
|
* @returns SubscriptionEntity with document ID
|
|
82
84
|
*/
|
|
83
85
|
private mapDocumentToEntity;
|
|
86
|
+
/**
|
|
87
|
+
* Activates a subscription for a user using a transaction.
|
|
88
|
+
* Creates a new subscription if one doesn't exist, or updates the existing one.
|
|
89
|
+
* Also updates the user document to reflect active subscription status.
|
|
90
|
+
* @param params - Activation parameters
|
|
91
|
+
* @param params.userId - The user's unique identifier
|
|
92
|
+
* @param params.appNamespace - The application namespace/platform
|
|
93
|
+
* @param params.startedAt - ISO timestamp when subscription period starts
|
|
94
|
+
* @param params.expiresAt - ISO timestamp when subscription period ends
|
|
95
|
+
* @param params.planId - The subscription plan identifier
|
|
96
|
+
* @param params.provider - Payment provider (e.g., 'wayforpay')
|
|
97
|
+
* @throws Error if user not found or transaction fails
|
|
98
|
+
*/
|
|
99
|
+
activateSubscription(params: {
|
|
100
|
+
userId: string;
|
|
101
|
+
appNamespace: AppNamespace;
|
|
102
|
+
startedAt: string;
|
|
103
|
+
expiresAt: string;
|
|
104
|
+
planId: string;
|
|
105
|
+
provider: 'wayforpay';
|
|
106
|
+
}): Promise<void>;
|
|
84
107
|
/**
|
|
85
108
|
* Builds an update object from field tuples.
|
|
86
109
|
* @param fields - Array of field paths and values
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkD,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkD,MAAM,0BAA0B,CAAC;AACtG,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,MAAM,0BAA0B,GAAG;IACrC,qBAAqB;IACrB,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE;CAC1D,EAAE,CAAC;AAEJ;;;GAGG;AACH,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;IAC/B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAElD;;OAEG;;IAKH;;;;;;;OAOG;IACU,WAAW,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;KAC1E,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IA6BtC;;;;;;;;;;OAUG;IACU,MAAM,CAAC,MAAM,EAAE;QACxB,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAwB/B;;;;;;;OAOG;IACU,oBAAoB,CAAC,MAAM,EAAE;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,0BAA0B,CAAC;KACtC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBjB;;;;OAIG;IACU,6BAA6B,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAgB3E;;;;;;OAMG;IACU,gBAAgB,CAAC,MAAM,EAAE;QAClC,cAAc,EAAE,MAAM,CAAC;QACvB,MAAM,EAAE,0BAA0B,CAAC;KACtC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;;;;;;;;;;;OAYG;IACU,oBAAoB,CAAC,MAAM,EAAE;QACtC,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,YAAY,CAAC;QAC3B,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,WAAW,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDjB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;CAS5B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SubscriptionRepository = void 0;
|
|
4
4
|
const firestore_1 = require("firebase-admin/firestore");
|
|
5
5
|
const const_1 = require("./const");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
6
7
|
/**
|
|
7
8
|
* SubscriptionRepository class handles all database operations related to subscriptions.
|
|
8
9
|
* Implements repository pattern for subscription data access.
|
|
@@ -16,21 +17,31 @@ class SubscriptionRepository {
|
|
|
16
17
|
this.db = (0, firestore_1.getFirestore)();
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
* Retrieves
|
|
20
|
+
* Retrieves a subscription for a specific user.
|
|
20
21
|
* @param params - Query parameters
|
|
21
22
|
* @param params.userId - The user's unique identifier
|
|
22
23
|
* @param params.appNamespace - The application namespace/platform
|
|
24
|
+
* @param params.status - Optional status filter. Can be a single status or array of statuses. Defaults to 'active'
|
|
23
25
|
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
24
26
|
*/
|
|
25
27
|
async getByUserId(params) {
|
|
26
28
|
const { userId, appNamespace } = params;
|
|
27
|
-
|
|
29
|
+
let query = this.db
|
|
28
30
|
.collection(this.collectionName)
|
|
29
31
|
.where('platform', '==', appNamespace)
|
|
30
|
-
.where('userId', '==', userId)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.
|
|
32
|
+
.where('userId', '==', userId);
|
|
33
|
+
if (!(0, utils_1.isUndefined)(params.status)) {
|
|
34
|
+
// Handle status filter
|
|
35
|
+
if (Array.isArray(params.status)) {
|
|
36
|
+
// Multiple statuses - use 'in' operator
|
|
37
|
+
query = query.where('status', 'in', params.status);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Single status - use '==' operator
|
|
41
|
+
query = query.where('status', '==', params.status);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const querySnapshot = await query.limit(1).get();
|
|
34
45
|
if (querySnapshot.empty) {
|
|
35
46
|
return null;
|
|
36
47
|
}
|
|
@@ -129,6 +140,64 @@ class SubscriptionRepository {
|
|
|
129
140
|
...doc.data(),
|
|
130
141
|
};
|
|
131
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Activates a subscription for a user using a transaction.
|
|
145
|
+
* Creates a new subscription if one doesn't exist, or updates the existing one.
|
|
146
|
+
* Also updates the user document to reflect active subscription status.
|
|
147
|
+
* @param params - Activation parameters
|
|
148
|
+
* @param params.userId - The user's unique identifier
|
|
149
|
+
* @param params.appNamespace - The application namespace/platform
|
|
150
|
+
* @param params.startedAt - ISO timestamp when subscription period starts
|
|
151
|
+
* @param params.expiresAt - ISO timestamp when subscription period ends
|
|
152
|
+
* @param params.planId - The subscription plan identifier
|
|
153
|
+
* @param params.provider - Payment provider (e.g., 'wayforpay')
|
|
154
|
+
* @throws Error if user not found or transaction fails
|
|
155
|
+
*/
|
|
156
|
+
async activateSubscription(params) {
|
|
157
|
+
const { userId, appNamespace, startedAt, expiresAt, planId, provider } = params;
|
|
158
|
+
return await this.db.runTransaction(async (tx) => {
|
|
159
|
+
// Get user document
|
|
160
|
+
const userSnapshot = await tx.get(this.db.collection(`platform/${appNamespace}/users`).doc(userId));
|
|
161
|
+
// Get subscription document
|
|
162
|
+
const subscriptionSnapshot = await tx.get(this.db
|
|
163
|
+
.collection(this.collectionName)
|
|
164
|
+
.where('userId', '==', userId)
|
|
165
|
+
.where('platform', '==', appNamespace)
|
|
166
|
+
.limit(1));
|
|
167
|
+
if (!userSnapshot.exists) {
|
|
168
|
+
throw new Error(`User not found: ${userId}`);
|
|
169
|
+
}
|
|
170
|
+
if (subscriptionSnapshot.empty) {
|
|
171
|
+
// Create new subscription
|
|
172
|
+
const subscriptionEntity = {
|
|
173
|
+
planId,
|
|
174
|
+
expiresAt,
|
|
175
|
+
status: 'active',
|
|
176
|
+
platform: appNamespace,
|
|
177
|
+
provider,
|
|
178
|
+
startedAt,
|
|
179
|
+
userId,
|
|
180
|
+
};
|
|
181
|
+
const docRef = this.db.collection(this.collectionName).doc();
|
|
182
|
+
await tx.create(docRef, {
|
|
183
|
+
id: docRef.id,
|
|
184
|
+
...subscriptionEntity,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
// Update existing subscription
|
|
189
|
+
await tx.update(subscriptionSnapshot.docs[0].ref, {
|
|
190
|
+
expiresAt,
|
|
191
|
+
status: 'active',
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
// Update user document
|
|
195
|
+
await tx.update(userSnapshot.ref, {
|
|
196
|
+
'subscription.isActive': true,
|
|
197
|
+
'subscription.isTrial': false,
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
132
201
|
/**
|
|
133
202
|
* Builds an update object from field tuples.
|
|
134
203
|
* @param fields - Array of field paths and values
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAsD;
|
|
1
|
+
{"version":3,"file":"repository.js","sourceRoot":"","sources":["../../../src/modules/subscription/repository.ts"],"names":[],"mappings":";;;AAAA,wDAAsG;AAEtG,mCAAsD;AAEtD,uCAA0C;AAO1C;;;GAGG;AACH,MAAa,sBAAsB;IAI/B;;OAEG;IACH;QALiB,mBAAc,GAAG,eAAe,CAAC;QAM9C,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,WAAW,CAAC,MAIxB;QACG,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAExC,IAAI,KAAK,GAAG,IAAI,CAAC,EAAE;aACd,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;aAC/B,KAAK,CAAC,UAAU,EAAE,IAAI,EAAE,YAAY,CAAC;aACrC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAEnC,IAAI,CAAC,IAAA,mBAAW,EAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,uBAAuB;YACvB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/B,wCAAwC;gBACxC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,EA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|
|
19
|
-
* Retrieves
|
|
19
|
+
* Retrieves a subscription for a specific user.
|
|
20
20
|
* @param params - Query parameters
|
|
21
21
|
* @param params.userId - The user's unique identifier
|
|
22
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'
|
|
23
24
|
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
24
25
|
*/
|
|
25
26
|
getByUserId(params: {
|
|
26
27
|
userId: string;
|
|
27
28
|
appNamespace: string;
|
|
29
|
+
status?: SubscriptionEntity['status'] | SubscriptionEntity['status'][];
|
|
28
30
|
}): Promise<SubscriptionEntity | null>;
|
|
29
31
|
/**
|
|
30
32
|
* Creates a new subscription record in the database.
|
|
@@ -97,5 +99,26 @@ export declare class SubscriptionService {
|
|
|
97
99
|
path: string;
|
|
98
100
|
}) => string;
|
|
99
101
|
}): 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>;
|
|
100
123
|
}
|
|
101
124
|
//# 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;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEhD;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAM1B
|
|
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;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAI5C;;;GAGG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEhD;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAM1B;;;;;;;OAOG;IACU,WAAW,CAAC,MAAM,EAAE;QAC7B,MAAM,EAAE,MAAM,CAAC;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;KAC1E,GAAG,OAAO,CA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E,WAAW,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBpB"}
|
|
@@ -23,10 +23,11 @@ class SubscriptionService {
|
|
|
23
23
|
this.paymentService = new service_1.PaymentService(logger);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Retrieves
|
|
26
|
+
* Retrieves a subscription for a specific user.
|
|
27
27
|
* @param params - Query parameters
|
|
28
28
|
* @param params.userId - The user's unique identifier
|
|
29
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'
|
|
30
31
|
* @returns Promise resolving to SubscriptionEntity or null if not found
|
|
31
32
|
*/
|
|
32
33
|
async getByUserId(params) {
|
|
@@ -200,6 +201,36 @@ class SubscriptionService {
|
|
|
200
201
|
throw error;
|
|
201
202
|
}
|
|
202
203
|
}
|
|
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
|
+
async activateSubscription(params) {
|
|
218
|
+
try {
|
|
219
|
+
await this.repository.activateSubscription(params);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
this.logger.error({
|
|
223
|
+
message: 'Error in subscription service activateSubscription',
|
|
224
|
+
payload: {
|
|
225
|
+
userId: params.userId,
|
|
226
|
+
appNamespace: params.appNamespace,
|
|
227
|
+
planId: params.planId,
|
|
228
|
+
error: JSON.stringify(error),
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
203
234
|
}
|
|
204
235
|
exports.SubscriptionService = SubscriptionService;
|
|
205
236
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAkF;AAGlF,mCAAoE;AACpE,iDAAqD;AAErD;;;GAGG;AACH,MAAa,mBAAmB;IAK5B;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAsB,EAAE,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAED
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/modules/subscription/service.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,6CAAkF;AAGlF,mCAAoE;AACpE,iDAAqD;AAErD;;;GAGG;AACH,MAAa,mBAAmB;IAK5B;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAsB,EAAE,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,IAAI,wBAAc,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,WAAW,CAAC,MAIxB;QACG,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,2CAA2C;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CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,iEAAiE;gBAC1E,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,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;IAED;;;;;;;;;;;;OAYG;IACI,KAAK,CAAC,oBAAoB,CAAC,MAOjC;QACG,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,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,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;AA3QD,kDA2QC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/user/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./userRepository"), exports);
|
|
18
|
+
__exportStar(require("./userService"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/user/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,gDAA8B;AAC9B,0CAAwB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { NestedPathsAccess } from '../../types/utilities';
|
|
2
|
+
import { AppNamespace } from '../app/types';
|
|
3
|
+
export interface User {
|
|
4
|
+
user: {
|
|
5
|
+
id: string;
|
|
6
|
+
lastUpdate: null | string;
|
|
7
|
+
name: null | string;
|
|
8
|
+
};
|
|
9
|
+
subscription: {
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
isTrial: boolean;
|
|
12
|
+
payments?: {
|
|
13
|
+
planId: string;
|
|
14
|
+
orderReference: string;
|
|
15
|
+
url: string;
|
|
16
|
+
createdDate: string;
|
|
17
|
+
}[];
|
|
18
|
+
paymentUrlMessageId?: number;
|
|
19
|
+
};
|
|
20
|
+
personality?: string;
|
|
21
|
+
messages: Record<string, Record<string, unknown>>;
|
|
22
|
+
commands?: Record<string, unknown>;
|
|
23
|
+
keyboardContext?: Record<string, unknown>;
|
|
24
|
+
settings: {
|
|
25
|
+
voiceResponse: boolean;
|
|
26
|
+
languageCode: string;
|
|
27
|
+
activeMessageThread: string;
|
|
28
|
+
requestCount: number;
|
|
29
|
+
imageAutoDetection: boolean;
|
|
30
|
+
imageResolution: string;
|
|
31
|
+
activeKeyboardMessageId?: number;
|
|
32
|
+
hasFakeImage?: boolean;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface UserAnalytics {
|
|
36
|
+
id: string;
|
|
37
|
+
platform: AppNamespace;
|
|
38
|
+
createdDate: string;
|
|
39
|
+
chatGPT: {
|
|
40
|
+
completions: Partial<Record<number, {
|
|
41
|
+
requestTokensCount: number;
|
|
42
|
+
responseTokensCount: number;
|
|
43
|
+
}>>;
|
|
44
|
+
image: {
|
|
45
|
+
create?: {
|
|
46
|
+
'11': {
|
|
47
|
+
count: number;
|
|
48
|
+
inputImageTokens: number;
|
|
49
|
+
outputImageTokens: number;
|
|
50
|
+
inputTextTokens: number;
|
|
51
|
+
};
|
|
52
|
+
'12': {
|
|
53
|
+
count: number;
|
|
54
|
+
};
|
|
55
|
+
'18': {
|
|
56
|
+
count: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
vision: Partial<Record<number, {
|
|
60
|
+
requestTokensCount: number;
|
|
61
|
+
responseTokensCount: number;
|
|
62
|
+
}>>;
|
|
63
|
+
};
|
|
64
|
+
speechToText: {
|
|
65
|
+
'whisper-1': {
|
|
66
|
+
seconds: number;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
textToSpeech: {
|
|
70
|
+
'tts-1': {
|
|
71
|
+
charsCount: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export type UserFieldPath = NestedPathsAccess<User>;
|
|
77
|
+
export type UserFieldAnalyticsPath = NestedPathsAccess<UserAnalytics>;
|
|
78
|
+
//# sourceMappingURL=types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;AAED,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,YAAY,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QACL,WAAW,EAAE,OAAO,CAChB,MAAM,CACF,MAAM,EACN;YACI,kBAAkB,EAAE,MAAM,CAAC;YAC3B,mBAAmB,EAAE,MAAM,CAAC;SAC/B,CACJ,CACJ,CAAC;QACF,KAAK,EAAE;YACH,MAAM,CAAC,EAAE;gBACL,IAAI,EAAE;oBACF,KAAK,EAAE,MAAM,CAAC;oBACd,gBAAgB,EAAE,MAAM,CAAC;oBACzB,iBAAiB,EAAE,MAAM,CAAC;oBAC1B,eAAe,EAAE,MAAM,CAAC;iBAC3B,CAAC;gBACF,IAAI,EAAE;oBACF,KAAK,EAAE,MAAM,CAAC;iBACjB,CAAC;gBACF,IAAI,EAAE;oBACF,KAAK,EAAE,MAAM,CAAC;iBACjB,CAAC;aACL,CAAC;YACF,MAAM,EAAE,OAAO,CACX,MAAM,CACF,MAAM,EACN;gBACI,kBAAkB,EAAE,MAAM,CAAC;gBAC3B,mBAAmB,EAAE,MAAM,CAAC;aAC/B,CACJ,CACJ,CAAC;SACL,CAAC;QACF,YAAY,EAAE;YACV,WAAW,EAAE;gBACT,OAAO,EAAE,MAAM,CAAC;aACnB,CAAC;SACL,CAAC;QACF,YAAY,EAAE;YACV,OAAO,EAAE;gBACL,UAAU,EAAE,MAAM,CAAC;aACtB,CAAC;SACL,CAAC;KACL,CAAC;CACL;AAED,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAEpD,MAAM,MAAM,sBAAsB,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/modules/user/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,22 +1,64 @@
|
|
|
1
1
|
import { FieldValue } from 'firebase-admin/firestore';
|
|
2
|
-
import { User,
|
|
2
|
+
import { User, UserFieldPath } from './types';
|
|
3
3
|
import { AppNamespace } from '../app/types';
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
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
|
+
export declare class UserRepository {
|
|
10
|
+
private readonly db;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of UserRepository.
|
|
13
|
+
*/
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves a user by their ID.
|
|
17
|
+
* @param params - Query parameters
|
|
18
|
+
* @param params.userId - The user's unique identifier
|
|
19
|
+
* @param params.appNamespace - The application namespace/platform
|
|
20
|
+
* @returns Promise resolving to User or null if not found
|
|
21
|
+
*/
|
|
22
|
+
getByUserId(params: {
|
|
23
|
+
userId: string;
|
|
24
|
+
appNamespace: string;
|
|
25
|
+
}): Promise<User | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new user record in the database.
|
|
28
|
+
* @param params - User creation parameters
|
|
29
|
+
* @param params.user - The user data to create
|
|
30
|
+
* @param params.appNamespace - The application namespace/platform
|
|
31
|
+
* @returns Promise resolving when user is created
|
|
32
|
+
* @throws Error if user creation fails
|
|
33
|
+
*/
|
|
34
|
+
create(params: {
|
|
35
|
+
user: User;
|
|
36
|
+
appNamespace: string;
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Updates specific fields of a user identified by userId.
|
|
40
|
+
* @param params - Update parameters
|
|
41
|
+
* @param params.userId - The user's unique identifier
|
|
42
|
+
* @param params.appNamespace - The application namespace/platform
|
|
43
|
+
* @param params.fields - Array of field paths and values to update
|
|
44
|
+
* @throws Error if user not found or update fails
|
|
45
|
+
*/
|
|
46
|
+
updateFieldsByUserId(params: {
|
|
47
|
+
appNamespace: AppNamespace;
|
|
48
|
+
userId: string;
|
|
49
|
+
fields: UpdateDBUserFields;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Maps a Firestore document to a User entity.
|
|
53
|
+
* @param doc - Firestore document snapshot
|
|
54
|
+
* @returns User entity
|
|
55
|
+
*/
|
|
56
|
+
private mapDocumentToEntity;
|
|
57
|
+
/**
|
|
58
|
+
* Builds an update object from field tuples.
|
|
59
|
+
* @param fields - Array of field paths and values
|
|
60
|
+
* @returns Object with field paths as keys and values to update
|
|
61
|
+
*/
|
|
62
|
+
private buildUpdateObject;
|
|
63
|
+
}
|
|
22
64
|
//# 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,
|
|
1
|
+
{"version":3,"file":"userRepository.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA6C,MAAM,0BAA0B,CAAC;AACjG,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,aAAa,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;AAE5G;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAY;IAE/B;;OAEG;;IAKH;;;;;;OAMG;IACU,WAAW,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAYhG;;;;;;;OAOG;IACU,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhF;;;;;;;OAOG;IACU,oBAAoB,CAAC,MAAM,EAAE;QACtC,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,kBAAkB,CAAC;KAC9B,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -1,47 +1,84 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.addDBUser = addDBUser;
|
|
5
|
-
exports.updateDBUser = updateDBUser;
|
|
3
|
+
exports.UserRepository = void 0;
|
|
6
4
|
const firestore_1 = require("firebase-admin/firestore");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/**
|
|
6
|
+
* UserRepository class handles all database operations related to users.
|
|
7
|
+
* Implements repository pattern for user data access.
|
|
8
|
+
*/
|
|
9
|
+
class UserRepository {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of UserRepository.
|
|
12
|
+
*/
|
|
13
|
+
constructor() {
|
|
14
|
+
this.db = (0, firestore_1.getFirestore)();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves a user by their ID.
|
|
18
|
+
* @param params - Query parameters
|
|
19
|
+
* @param params.userId - The user's unique identifier
|
|
20
|
+
* @param params.appNamespace - The application namespace/platform
|
|
21
|
+
* @returns Promise resolving to User or null if not found
|
|
22
|
+
*/
|
|
23
|
+
async getByUserId(params) {
|
|
24
|
+
const { userId, appNamespace } = params;
|
|
25
|
+
const docSnapshot = await this.db.collection(`platform/${appNamespace}/users`).doc(userId).get();
|
|
26
|
+
if (!docSnapshot.exists) {
|
|
12
27
|
return null;
|
|
13
28
|
}
|
|
14
|
-
return
|
|
29
|
+
return this.mapDocumentToEntity(docSnapshot);
|
|
15
30
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new user record in the database.
|
|
33
|
+
* @param params - User creation parameters
|
|
34
|
+
* @param params.user - The user data to create
|
|
35
|
+
* @param params.appNamespace - The application namespace/platform
|
|
36
|
+
* @returns Promise resolving when user is created
|
|
37
|
+
* @throws Error if user creation fails
|
|
38
|
+
*/
|
|
39
|
+
async create(params) {
|
|
40
|
+
const { user, appNamespace } = params;
|
|
41
|
+
await this.db.collection(`platform/${appNamespace}/users`).doc(user.user.id).set(user);
|
|
21
42
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Updates specific fields of a user identified by userId.
|
|
45
|
+
* @param params - Update parameters
|
|
46
|
+
* @param params.userId - The user's unique identifier
|
|
47
|
+
* @param params.appNamespace - The application namespace/platform
|
|
48
|
+
* @param params.fields - Array of field paths and values to update
|
|
49
|
+
* @throws Error if user not found or update fails
|
|
50
|
+
*/
|
|
51
|
+
async updateFieldsByUserId(params) {
|
|
52
|
+
const { userId, appNamespace, fields } = params;
|
|
53
|
+
const updateObject = this.buildUpdateObject(fields);
|
|
54
|
+
const snapshot = await this.db.collection(`platform/${appNamespace}/users`).doc(userId).get();
|
|
55
|
+
if (!snapshot.exists) {
|
|
56
|
+
throw new Error(`User not found: ${userId}`);
|
|
57
|
+
}
|
|
58
|
+
await snapshot.ref.update(updateObject);
|
|
28
59
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
updateObject[f[0]] = f[1];
|
|
37
|
-
});
|
|
38
|
-
const snapshot = await db.collection(`platform/${appNamespace}/users`).doc(userId).get();
|
|
39
|
-
if (!snapshot.exists) {
|
|
40
|
-
throw new Error('User not found');
|
|
60
|
+
/**
|
|
61
|
+
* Maps a Firestore document to a User entity.
|
|
62
|
+
* @param doc - Firestore document snapshot
|
|
63
|
+
* @returns User entity
|
|
64
|
+
*/
|
|
65
|
+
mapDocumentToEntity(doc) {
|
|
66
|
+
return doc.data();
|
|
41
67
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Builds an update object from field tuples.
|
|
70
|
+
* @param fields - Array of field paths and values
|
|
71
|
+
* @returns Object with field paths as keys and values to update
|
|
72
|
+
*/
|
|
73
|
+
buildUpdateObject(fields) {
|
|
74
|
+
const updateObject = {};
|
|
75
|
+
fields
|
|
76
|
+
.filter((f) => Array.isArray(f))
|
|
77
|
+
.forEach(([fieldPath, value]) => {
|
|
78
|
+
updateObject[fieldPath] = value;
|
|
79
|
+
});
|
|
80
|
+
return updateObject;
|
|
45
81
|
}
|
|
46
82
|
}
|
|
83
|
+
exports.UserRepository = UserRepository;
|
|
47
84
|
//# sourceMappingURL=userRepository.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userRepository.js","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"userRepository.js","sourceRoot":"","sources":["../../../src/modules/user/userRepository.ts"],"names":[],"mappings":";;;AAAA,wDAAiG;AAMjG;;;GAGG;AACH,MAAa,cAAc;IAGvB;;OA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,CAAC;QACjD,CAAC;QAED,MAAM,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACK,mBAAmB,CAAC,GAAqB;QAC7C,OAAO,GAAG,CAAC,IAAI,EAAU,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACK,iBAAiB,CAAC,MAA0B;QAChD,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,MAAM;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aAC/B,OAAO,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;YAC5B,YAAY,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;QACpC,CAAC,CAAC,CAAC;QAEP,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ;AA9FD,wCA8FC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Logger } from '../logger/types';
|
|
2
|
+
import { UpdateDBUserFields } from './userRepository';
|
|
3
|
+
import { User } from './types';
|
|
4
|
+
import { AppNamespace } from '../app/types';
|
|
5
|
+
/**
|
|
6
|
+
* UserService class handles business logic related to users.
|
|
7
|
+
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
+
*/
|
|
9
|
+
export declare class UserService {
|
|
10
|
+
private readonly logger;
|
|
11
|
+
private readonly repository;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of UserService.
|
|
14
|
+
* @param logger - Application logger instance for logging operations
|
|
15
|
+
*/
|
|
16
|
+
constructor(logger: Logger);
|
|
17
|
+
/**
|
|
18
|
+
* Retrieves a user by their ID.
|
|
19
|
+
* @param params - Query parameters
|
|
20
|
+
* @param params.userId - The user's unique identifier
|
|
21
|
+
* @param params.appNamespace - The application namespace/platform
|
|
22
|
+
* @returns Promise resolving to User or null if not found
|
|
23
|
+
*/
|
|
24
|
+
getByUserId(params: {
|
|
25
|
+
userId: string;
|
|
26
|
+
appNamespace: string;
|
|
27
|
+
}): Promise<User | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a new user record in the database.
|
|
30
|
+
* @param params - User creation parameters
|
|
31
|
+
* @param params.user - The user data to create
|
|
32
|
+
* @param params.appNamespace - The application namespace/platform
|
|
33
|
+
* @returns Promise resolving when user is created
|
|
34
|
+
* @throws Error if user creation fails
|
|
35
|
+
*/
|
|
36
|
+
create(params: {
|
|
37
|
+
user: User;
|
|
38
|
+
appNamespace: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Updates specific fields of a user identified by userId.
|
|
42
|
+
* @param params - Update parameters
|
|
43
|
+
* @param params.userId - The user's unique identifier
|
|
44
|
+
* @param params.appNamespace - The application namespace/platform
|
|
45
|
+
* @param params.fields - Array of field paths and values to update
|
|
46
|
+
* @throws Error if user not found or update fails
|
|
47
|
+
*/
|
|
48
|
+
updateFieldsByUserId(params: {
|
|
49
|
+
appNamespace: AppNamespace;
|
|
50
|
+
userId: string;
|
|
51
|
+
fields: UpdateDBUserFields;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=userService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userService.d.ts","sourceRoot":"","sources":["../../../src/modules/user/userService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAkB,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiB;IAE5C;;;OAGG;gBACS,MAAM,EAAE,MAAM;IAK1B;;;;;;OAMG;IACU,WAAW,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAgBhG;;;;;;;OAOG;IACU,MAAM,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBhF;;;;;;;OAOG;IACU,oBAAoB,CAAC,MAAM,EAAE;QACtC,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,kBAAkB,CAAC;KAC9B,GAAG,OAAO,CAAC,IAAI,CAAC;CAiBpB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserService = void 0;
|
|
4
|
+
const userRepository_1 = require("./userRepository");
|
|
5
|
+
/**
|
|
6
|
+
* UserService class handles business logic related to users.
|
|
7
|
+
* Acts as an intermediary between controllers/handlers and the repository layer.
|
|
8
|
+
*/
|
|
9
|
+
class UserService {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of UserService.
|
|
12
|
+
* @param logger - Application logger instance for logging operations
|
|
13
|
+
*/
|
|
14
|
+
constructor(logger) {
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.repository = new userRepository_1.UserRepository();
|
|
17
|
+
}
|
|
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
|
+
async getByUserId(params) {
|
|
26
|
+
try {
|
|
27
|
+
return await this.repository.getByUserId(params);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
this.logger.error({
|
|
31
|
+
message: 'Error in user service getByUserId',
|
|
32
|
+
payload: {
|
|
33
|
+
userId: params.userId,
|
|
34
|
+
appNamespace: params.appNamespace,
|
|
35
|
+
error: JSON.stringify(error),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new user record in the database.
|
|
43
|
+
* @param params - User creation parameters
|
|
44
|
+
* @param params.user - The user data to create
|
|
45
|
+
* @param params.appNamespace - The application namespace/platform
|
|
46
|
+
* @returns Promise resolving when user is created
|
|
47
|
+
* @throws Error if user creation fails
|
|
48
|
+
*/
|
|
49
|
+
async create(params) {
|
|
50
|
+
try {
|
|
51
|
+
await this.repository.create(params);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.logger.error({
|
|
55
|
+
message: 'Error in user service create',
|
|
56
|
+
payload: {
|
|
57
|
+
userId: params.user.user.id,
|
|
58
|
+
appNamespace: params.appNamespace,
|
|
59
|
+
error: JSON.stringify(error),
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Updates specific fields of a user identified by userId.
|
|
67
|
+
* @param params - Update parameters
|
|
68
|
+
* @param params.userId - The user's unique identifier
|
|
69
|
+
* @param params.appNamespace - The application namespace/platform
|
|
70
|
+
* @param params.fields - Array of field paths and values to update
|
|
71
|
+
* @throws Error if user not found or update fails
|
|
72
|
+
*/
|
|
73
|
+
async updateFieldsByUserId(params) {
|
|
74
|
+
try {
|
|
75
|
+
await this.repository.updateFieldsByUserId(params);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.logger.error({
|
|
79
|
+
message: 'Error in user service updateFieldsByUserId',
|
|
80
|
+
payload: {
|
|
81
|
+
userId: params.userId,
|
|
82
|
+
appNamespace: params.appNamespace,
|
|
83
|
+
fields: JSON.stringify(params.fields),
|
|
84
|
+
error: JSON.stringify(error),
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.UserService = UserService;
|
|
92
|
+
//# sourceMappingURL=userService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"userService.js","sourceRoot":"","sources":["../../../src/modules/user/userService.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAItE;;;GAGG;AACH,MAAa,WAAW;IAIpB;;;OAGG;IACH,YAAY,MAAc;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,+BAAc,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CAAC,MAAgD;QACrE,IAAI,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,mCAAmC;gBAC5C,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YACH,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,MAAM,CAAC,MAA4C;QAC5D,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBACd,OAAO,EAAE,8BAA8B;gBACvC,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBAC3B,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,oBAAoB,CAAC,MAIjC;QACG,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,4CAA4C;gBACrD,OAAO,EAAE;oBACL,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;oBACrC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;iBAC/B;aACJ,CAAC,CAAC;YAEH,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AA1FD,kCA0FC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@misterhomer1992/miit-bot-payment",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A TypeScript utility library for payment validation and formatting",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dotenv": "17.2.2",
|
|
30
30
|
"axios": "1.12.2",
|
|
31
31
|
"firebase-admin": "^11.6.0",
|
|
32
|
-
"@misterhomer1992/wayforpay-api": "
|
|
32
|
+
"@misterhomer1992/wayforpay-api": "3.0.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^20.10.0",
|