@temboplus/afloat 0.1.49 → 0.1.51
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/esm/src/features/wallet/contract.d.ts +32 -1
- package/esm/src/features/wallet/contract.d.ts.map +1 -1
- package/esm/src/features/wallet/contract.js +4 -1
- package/esm/src/features/wallet/repository.d.ts +6 -3
- package/esm/src/features/wallet/repository.d.ts.map +1 -1
- package/esm/src/features/wallet/repository.js +7 -5
- package/esm/src/models/wallet/schemas.d.ts +48 -22
- package/esm/src/models/wallet/schemas.d.ts.map +1 -1
- package/esm/src/models/wallet/schemas.js +25 -0
- package/package.json +1 -1
- package/script/src/features/wallet/contract.d.ts +32 -1
- package/script/src/features/wallet/contract.d.ts.map +1 -1
- package/script/src/features/wallet/contract.js +4 -1
- package/script/src/features/wallet/repository.d.ts +6 -3
- package/script/src/features/wallet/repository.d.ts.map +1 -1
- package/script/src/features/wallet/repository.js +6 -4
- package/script/src/models/wallet/schemas.d.ts +48 -22
- package/script/src/models/wallet/schemas.d.ts.map +1 -1
- package/script/src/models/wallet/schemas.js +25 -0
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const contract: {
|
|
3
3
|
getWallets: {
|
|
4
|
+
query: z.ZodObject<{
|
|
5
|
+
id: z.ZodOptional<z.ZodString>;
|
|
6
|
+
profileId: z.ZodOptional<z.ZodString>;
|
|
7
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
8
|
+
accountName: z.ZodOptional<z.ZodString>;
|
|
9
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
10
|
+
countryCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
11
|
+
currencyCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
id?: string | undefined;
|
|
14
|
+
accountNo?: string | undefined;
|
|
15
|
+
channel?: string | undefined;
|
|
16
|
+
profileId?: string | undefined;
|
|
17
|
+
accountName?: string | undefined;
|
|
18
|
+
countryCode?: string | undefined;
|
|
19
|
+
currencyCode?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
id?: string | undefined;
|
|
22
|
+
accountNo?: string | undefined;
|
|
23
|
+
channel?: string | undefined;
|
|
24
|
+
profileId?: string | undefined;
|
|
25
|
+
accountName?: string | undefined;
|
|
26
|
+
countryCode?: string | undefined;
|
|
27
|
+
currencyCode?: string | undefined;
|
|
28
|
+
}>;
|
|
4
29
|
method: "GET";
|
|
5
30
|
path: "/";
|
|
6
31
|
responses: {
|
|
@@ -39,7 +64,13 @@ export declare const contract: {
|
|
|
39
64
|
};
|
|
40
65
|
getBalance: {
|
|
41
66
|
method: "POST";
|
|
42
|
-
body: z.ZodObject<{
|
|
67
|
+
body: z.ZodObject<{
|
|
68
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
accountNo?: string | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
accountNo?: string | undefined;
|
|
73
|
+
}>;
|
|
43
74
|
path: "/balance";
|
|
44
75
|
responses: {
|
|
45
76
|
201: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnB,CAAC"}
|
|
@@ -5,6 +5,7 @@ export const contract = initContract().router({
|
|
|
5
5
|
getWallets: {
|
|
6
6
|
method: "GET",
|
|
7
7
|
path: "/",
|
|
8
|
+
query: WalletSchemas.walletQuery,
|
|
8
9
|
responses: {
|
|
9
10
|
200: z.array(WalletSchemas.wallet),
|
|
10
11
|
},
|
|
@@ -12,7 +13,9 @@ export const contract = initContract().router({
|
|
|
12
13
|
getBalance: {
|
|
13
14
|
method: "POST",
|
|
14
15
|
path: "/balance",
|
|
15
|
-
body: z.object({
|
|
16
|
+
body: z.object({
|
|
17
|
+
accountNo: z.string().optional(),
|
|
18
|
+
}),
|
|
16
19
|
responses: {
|
|
17
20
|
201: z.object({
|
|
18
21
|
availableBalance: z.coerce.number(),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BaseRepository } from "../../shared/base_repository.js";
|
|
2
2
|
import { contract } from "./contract.js";
|
|
3
|
-
import { Wallet, WalletStatementEntry } from "../../models/wallet/index.js";
|
|
3
|
+
import { Wallet, type WalletSchemas, WalletStatementEntry } from "../../models/wallet/index.js";
|
|
4
4
|
import type { AfloatAuth } from "../auth/manager.js";
|
|
5
|
+
import type z from "zod";
|
|
5
6
|
/**
|
|
6
7
|
* Repository class for managing wallet operations including balance checking,
|
|
7
8
|
* statement generation, and wallet information retrieval.
|
|
@@ -24,13 +25,15 @@ export declare class WalletRepo extends BaseRepository<typeof contract> {
|
|
|
24
25
|
* @throws {Error} If the balance fetch operation fails
|
|
25
26
|
* @returns {Promise<number>} The available balance amount
|
|
26
27
|
*/
|
|
27
|
-
getBalance(
|
|
28
|
+
getBalance(props: {
|
|
29
|
+
accountNo?: string;
|
|
30
|
+
}): Promise<number>;
|
|
28
31
|
/**
|
|
29
32
|
* Retrieves all wallets associated with the current context.
|
|
30
33
|
* @throws {Error} If the wallet fetch operation fails
|
|
31
34
|
* @returns {Promise<Wallet[]>} Array of wallet objects
|
|
32
35
|
*/
|
|
33
|
-
getWallets(): Promise<Wallet[]>;
|
|
36
|
+
getWallets(args?: z.infer<typeof WalletSchemas.walletQuery>): Promise<Wallet[]>;
|
|
34
37
|
/**
|
|
35
38
|
* Retrieves wallet statement items for a specified date range and account.
|
|
36
39
|
* If no range is provided, defaults to the current month (1st to 30th).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,MAAM,EACN,KAAK,aAAa,EAClB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAC7D;;;;;OAKG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAOxD;;;;;OAKG;IACG,UAAU,CAAC,KAAK,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBhE;;;;OAIG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,WAAW,CAAC,GAC/C,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpB;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE;YAAE,SAAS,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,IAAI,CAAA;SAAE,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,oBAAoB,EAAE,CAAC;CA2BnC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseRepository } from "../../shared/base_repository.js";
|
|
2
2
|
import { contract } from "./contract.js";
|
|
3
|
-
import { Wallet, WalletStatementEntry } from "../../models/wallet/index.js";
|
|
3
|
+
import { Wallet, WalletStatementEntry, } from "../../models/wallet/index.js";
|
|
4
4
|
import { Permissions } from "../../models/permission.js";
|
|
5
5
|
import { PermissionError } from "../../errors/index.js";
|
|
6
6
|
/**
|
|
@@ -27,7 +27,7 @@ export class WalletRepo extends BaseRepository {
|
|
|
27
27
|
* @throws {Error} If the balance fetch operation fails
|
|
28
28
|
* @returns {Promise<number>} The available balance amount
|
|
29
29
|
*/
|
|
30
|
-
async getBalance() {
|
|
30
|
+
async getBalance(props) {
|
|
31
31
|
const auth = this.getAuthForPermissionCheck();
|
|
32
32
|
const requirePerm = Permissions.Wallet.ViewBalance;
|
|
33
33
|
if (!auth.checkPermission(requirePerm)) {
|
|
@@ -36,7 +36,9 @@ export class WalletRepo extends BaseRepository {
|
|
|
36
36
|
requiredPermissions: [requirePerm],
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
const result = await this.client.getBalance(
|
|
39
|
+
const result = await this.client.getBalance({
|
|
40
|
+
body: { accountNo: props.accountNo },
|
|
41
|
+
});
|
|
40
42
|
if (result.status === 201) {
|
|
41
43
|
return result.body.availableBalance;
|
|
42
44
|
}
|
|
@@ -47,8 +49,8 @@ export class WalletRepo extends BaseRepository {
|
|
|
47
49
|
* @throws {Error} If the wallet fetch operation fails
|
|
48
50
|
* @returns {Promise<Wallet[]>} Array of wallet objects
|
|
49
51
|
*/
|
|
50
|
-
async getWallets() {
|
|
51
|
-
const result = await this.client.getWallets();
|
|
52
|
+
async getWallets(args) {
|
|
53
|
+
const result = await this.client.getWallets({ query: args });
|
|
52
54
|
if (result.status === 200) {
|
|
53
55
|
return result.body.map((w) => Wallet.from(w));
|
|
54
56
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
/**
|
|
2
3
|
* Collection of wallet-related schemas for export.
|
|
3
4
|
* Provides access to both wallet and statement entry validation schemas.
|
|
4
5
|
*/
|
|
5
6
|
export declare const WalletSchemas: {
|
|
6
|
-
wallet:
|
|
7
|
-
id:
|
|
8
|
-
profileId:
|
|
9
|
-
accountNo:
|
|
10
|
-
accountName:
|
|
11
|
-
channel:
|
|
12
|
-
countryCode:
|
|
13
|
-
currencyCode:
|
|
14
|
-
createdAt:
|
|
15
|
-
updatedAt:
|
|
16
|
-
}, "strip",
|
|
7
|
+
wallet: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
profileId: z.ZodString;
|
|
10
|
+
accountNo: z.ZodString;
|
|
11
|
+
accountName: z.ZodString;
|
|
12
|
+
channel: z.ZodString;
|
|
13
|
+
countryCode: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
14
|
+
currencyCode: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
15
|
+
createdAt: z.ZodString;
|
|
16
|
+
updatedAt: z.ZodString;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
18
|
id: string;
|
|
18
19
|
accountNo: string;
|
|
19
20
|
channel: string;
|
|
@@ -34,17 +35,42 @@ export declare const WalletSchemas: {
|
|
|
34
35
|
countryCode?: string | undefined;
|
|
35
36
|
currencyCode?: string | undefined;
|
|
36
37
|
}>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
walletQuery: z.ZodObject<{
|
|
39
|
+
id: z.ZodOptional<z.ZodString>;
|
|
40
|
+
profileId: z.ZodOptional<z.ZodString>;
|
|
41
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
42
|
+
accountName: z.ZodOptional<z.ZodString>;
|
|
43
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
44
|
+
countryCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
45
|
+
currencyCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
id?: string | undefined;
|
|
48
|
+
accountNo?: string | undefined;
|
|
49
|
+
channel?: string | undefined;
|
|
50
|
+
profileId?: string | undefined;
|
|
51
|
+
accountName?: string | undefined;
|
|
52
|
+
countryCode?: string | undefined;
|
|
53
|
+
currencyCode?: string | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
id?: string | undefined;
|
|
56
|
+
accountNo?: string | undefined;
|
|
57
|
+
channel?: string | undefined;
|
|
58
|
+
profileId?: string | undefined;
|
|
59
|
+
accountName?: string | undefined;
|
|
60
|
+
countryCode?: string | undefined;
|
|
61
|
+
currencyCode?: string | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
statementEntry: z.ZodObject<{
|
|
64
|
+
accountNo: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
65
|
+
debitOrCredit: z.ZodString;
|
|
66
|
+
tranRefNo: z.ZodString;
|
|
67
|
+
narration: z.ZodString;
|
|
68
|
+
txnDate: z.ZodDate;
|
|
69
|
+
valueDate: z.ZodDate;
|
|
70
|
+
amountCredited: z.ZodNumber;
|
|
71
|
+
amountDebited: z.ZodNumber;
|
|
72
|
+
balance: z.ZodNumber;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
74
|
debitOrCredit: string;
|
|
49
75
|
tranRefNo: string;
|
|
50
76
|
narration: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/schemas.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIzB,CAAC"}
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { Wallet } from "./wallet.js";
|
|
2
2
|
import { WalletStatementEntry } from "./statement_entry.js";
|
|
3
|
+
import { Currency, ISO2CountryCodesSet, ValidCurrencyCodesSet, } from "@temboplus/frontend-core";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/**
|
|
6
|
+
* Zod schema definition for validating Wallet data structures.
|
|
7
|
+
* Ensures data integrity for wallet objects, including runtime validation
|
|
8
|
+
* of country codes against the imported ISO2CountryCodesSet.
|
|
9
|
+
*/
|
|
10
|
+
const walletQuerySchema = z.object({
|
|
11
|
+
id: z.string().optional(),
|
|
12
|
+
profileId: z.string().optional(),
|
|
13
|
+
accountNo: z.string().optional(),
|
|
14
|
+
accountName: z.string().optional(),
|
|
15
|
+
channel: z.string().optional(),
|
|
16
|
+
// Validate countryCode as a string present in the imported Set
|
|
17
|
+
countryCode: z.string().default("TZ")
|
|
18
|
+
.refine((code) => ISO2CountryCodesSet.has(code), { message: "Provided country code is not a valid ISO2 code." }).optional(),
|
|
19
|
+
// Validate currencyCode as a string present in the imported Set
|
|
20
|
+
currencyCode: z.string().default("TZS")
|
|
21
|
+
.refine((code) => {
|
|
22
|
+
const currency = Currency.from(code);
|
|
23
|
+
return currency !== undefined &&
|
|
24
|
+
ValidCurrencyCodesSet.has(currency.code);
|
|
25
|
+
}, { message: "Provided currency code is not a valid currency code." }).optional(),
|
|
26
|
+
});
|
|
3
27
|
/**
|
|
4
28
|
* Collection of wallet-related schemas for export.
|
|
5
29
|
* Provides access to both wallet and statement entry validation schemas.
|
|
6
30
|
*/
|
|
7
31
|
export const WalletSchemas = {
|
|
8
32
|
wallet: Wallet.schema,
|
|
33
|
+
walletQuery: walletQuerySchema,
|
|
9
34
|
statementEntry: WalletStatementEntry.schema,
|
|
10
35
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const contract: {
|
|
3
3
|
getWallets: {
|
|
4
|
+
query: z.ZodObject<{
|
|
5
|
+
id: z.ZodOptional<z.ZodString>;
|
|
6
|
+
profileId: z.ZodOptional<z.ZodString>;
|
|
7
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
8
|
+
accountName: z.ZodOptional<z.ZodString>;
|
|
9
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
10
|
+
countryCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
11
|
+
currencyCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
id?: string | undefined;
|
|
14
|
+
accountNo?: string | undefined;
|
|
15
|
+
channel?: string | undefined;
|
|
16
|
+
profileId?: string | undefined;
|
|
17
|
+
accountName?: string | undefined;
|
|
18
|
+
countryCode?: string | undefined;
|
|
19
|
+
currencyCode?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
id?: string | undefined;
|
|
22
|
+
accountNo?: string | undefined;
|
|
23
|
+
channel?: string | undefined;
|
|
24
|
+
profileId?: string | undefined;
|
|
25
|
+
accountName?: string | undefined;
|
|
26
|
+
countryCode?: string | undefined;
|
|
27
|
+
currencyCode?: string | undefined;
|
|
28
|
+
}>;
|
|
4
29
|
method: "GET";
|
|
5
30
|
path: "/";
|
|
6
31
|
responses: {
|
|
@@ -39,7 +64,13 @@ export declare const contract: {
|
|
|
39
64
|
};
|
|
40
65
|
getBalance: {
|
|
41
66
|
method: "POST";
|
|
42
|
-
body: z.ZodObject<{
|
|
67
|
+
body: z.ZodObject<{
|
|
68
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, "strip", z.ZodTypeAny, {
|
|
70
|
+
accountNo?: string | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
accountNo?: string | undefined;
|
|
73
|
+
}>;
|
|
43
74
|
path: "/balance";
|
|
44
75
|
responses: {
|
|
45
76
|
201: z.ZodObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnB,CAAC"}
|
|
@@ -8,6 +8,7 @@ exports.contract = (0, core_1.initContract)().router({
|
|
|
8
8
|
getWallets: {
|
|
9
9
|
method: "GET",
|
|
10
10
|
path: "/",
|
|
11
|
+
query: index_js_1.WalletSchemas.walletQuery,
|
|
11
12
|
responses: {
|
|
12
13
|
200: zod_1.z.array(index_js_1.WalletSchemas.wallet),
|
|
13
14
|
},
|
|
@@ -15,7 +16,9 @@ exports.contract = (0, core_1.initContract)().router({
|
|
|
15
16
|
getBalance: {
|
|
16
17
|
method: "POST",
|
|
17
18
|
path: "/balance",
|
|
18
|
-
body: zod_1.z.object({
|
|
19
|
+
body: zod_1.z.object({
|
|
20
|
+
accountNo: zod_1.z.string().optional(),
|
|
21
|
+
}),
|
|
19
22
|
responses: {
|
|
20
23
|
201: zod_1.z.object({
|
|
21
24
|
availableBalance: zod_1.z.coerce.number(),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BaseRepository } from "../../shared/base_repository.js";
|
|
2
2
|
import { contract } from "./contract.js";
|
|
3
|
-
import { Wallet, WalletStatementEntry } from "../../models/wallet/index.js";
|
|
3
|
+
import { Wallet, type WalletSchemas, WalletStatementEntry } from "../../models/wallet/index.js";
|
|
4
4
|
import type { AfloatAuth } from "../auth/manager.js";
|
|
5
|
+
import type z from "zod";
|
|
5
6
|
/**
|
|
6
7
|
* Repository class for managing wallet operations including balance checking,
|
|
7
8
|
* statement generation, and wallet information retrieval.
|
|
@@ -24,13 +25,15 @@ export declare class WalletRepo extends BaseRepository<typeof contract> {
|
|
|
24
25
|
* @throws {Error} If the balance fetch operation fails
|
|
25
26
|
* @returns {Promise<number>} The available balance amount
|
|
26
27
|
*/
|
|
27
|
-
getBalance(
|
|
28
|
+
getBalance(props: {
|
|
29
|
+
accountNo?: string;
|
|
30
|
+
}): Promise<number>;
|
|
28
31
|
/**
|
|
29
32
|
* Retrieves all wallets associated with the current context.
|
|
30
33
|
* @throws {Error} If the wallet fetch operation fails
|
|
31
34
|
* @returns {Promise<Wallet[]>} Array of wallet objects
|
|
32
35
|
*/
|
|
33
|
-
getWallets(): Promise<Wallet[]>;
|
|
36
|
+
getWallets(args?: z.infer<typeof WalletSchemas.walletQuery>): Promise<Wallet[]>;
|
|
34
37
|
/**
|
|
35
38
|
* Retrieves wallet statement items for a specified date range and account.
|
|
36
39
|
* If no range is provided, defaults to the current month (1st to 30th).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/src/features/wallet/repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EACL,MAAM,EACN,KAAK,aAAa,EAClB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,cAAc,CAAC,OAAO,QAAQ,CAAC;IAC7D;;;;;OAKG;gBACS,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,UAAU,CAAA;KAAE;IAOxD;;;;;OAKG;IACG,UAAU,CAAC,KAAK,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBhE;;;;OAIG;IACG,UAAU,CACd,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,WAAW,CAAC,GAC/C,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpB;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE;YAAE,SAAS,EAAE,IAAI,CAAC;YAAC,OAAO,EAAE,IAAI,CAAA;SAAE,CAAC;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GACA,OAAO,CAAC,oBAAoB,EAAE,CAAC;CA2BnC"}
|
|
@@ -30,7 +30,7 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
30
30
|
* @throws {Error} If the balance fetch operation fails
|
|
31
31
|
* @returns {Promise<number>} The available balance amount
|
|
32
32
|
*/
|
|
33
|
-
async getBalance() {
|
|
33
|
+
async getBalance(props) {
|
|
34
34
|
const auth = this.getAuthForPermissionCheck();
|
|
35
35
|
const requirePerm = permission_js_1.Permissions.Wallet.ViewBalance;
|
|
36
36
|
if (!auth.checkPermission(requirePerm)) {
|
|
@@ -39,7 +39,9 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
39
39
|
requiredPermissions: [requirePerm],
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
const result = await this.client.getBalance(
|
|
42
|
+
const result = await this.client.getBalance({
|
|
43
|
+
body: { accountNo: props.accountNo },
|
|
44
|
+
});
|
|
43
45
|
if (result.status === 201) {
|
|
44
46
|
return result.body.availableBalance;
|
|
45
47
|
}
|
|
@@ -50,8 +52,8 @@ class WalletRepo extends base_repository_js_1.BaseRepository {
|
|
|
50
52
|
* @throws {Error} If the wallet fetch operation fails
|
|
51
53
|
* @returns {Promise<Wallet[]>} Array of wallet objects
|
|
52
54
|
*/
|
|
53
|
-
async getWallets() {
|
|
54
|
-
const result = await this.client.getWallets();
|
|
55
|
+
async getWallets(args) {
|
|
56
|
+
const result = await this.client.getWallets({ query: args });
|
|
55
57
|
if (result.status === 200) {
|
|
56
58
|
return result.body.map((w) => index_js_1.Wallet.from(w));
|
|
57
59
|
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
/**
|
|
2
3
|
* Collection of wallet-related schemas for export.
|
|
3
4
|
* Provides access to both wallet and statement entry validation schemas.
|
|
4
5
|
*/
|
|
5
6
|
export declare const WalletSchemas: {
|
|
6
|
-
wallet:
|
|
7
|
-
id:
|
|
8
|
-
profileId:
|
|
9
|
-
accountNo:
|
|
10
|
-
accountName:
|
|
11
|
-
channel:
|
|
12
|
-
countryCode:
|
|
13
|
-
currencyCode:
|
|
14
|
-
createdAt:
|
|
15
|
-
updatedAt:
|
|
16
|
-
}, "strip",
|
|
7
|
+
wallet: z.ZodObject<{
|
|
8
|
+
id: z.ZodString;
|
|
9
|
+
profileId: z.ZodString;
|
|
10
|
+
accountNo: z.ZodString;
|
|
11
|
+
accountName: z.ZodString;
|
|
12
|
+
channel: z.ZodString;
|
|
13
|
+
countryCode: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
14
|
+
currencyCode: z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>;
|
|
15
|
+
createdAt: z.ZodString;
|
|
16
|
+
updatedAt: z.ZodString;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
18
|
id: string;
|
|
18
19
|
accountNo: string;
|
|
19
20
|
channel: string;
|
|
@@ -34,17 +35,42 @@ export declare const WalletSchemas: {
|
|
|
34
35
|
countryCode?: string | undefined;
|
|
35
36
|
currencyCode?: string | undefined;
|
|
36
37
|
}>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
walletQuery: z.ZodObject<{
|
|
39
|
+
id: z.ZodOptional<z.ZodString>;
|
|
40
|
+
profileId: z.ZodOptional<z.ZodString>;
|
|
41
|
+
accountNo: z.ZodOptional<z.ZodString>;
|
|
42
|
+
accountName: z.ZodOptional<z.ZodString>;
|
|
43
|
+
channel: z.ZodOptional<z.ZodString>;
|
|
44
|
+
countryCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
45
|
+
currencyCode: z.ZodOptional<z.ZodEffects<z.ZodDefault<z.ZodString>, string, string | undefined>>;
|
|
46
|
+
}, "strip", z.ZodTypeAny, {
|
|
47
|
+
id?: string | undefined;
|
|
48
|
+
accountNo?: string | undefined;
|
|
49
|
+
channel?: string | undefined;
|
|
50
|
+
profileId?: string | undefined;
|
|
51
|
+
accountName?: string | undefined;
|
|
52
|
+
countryCode?: string | undefined;
|
|
53
|
+
currencyCode?: string | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
id?: string | undefined;
|
|
56
|
+
accountNo?: string | undefined;
|
|
57
|
+
channel?: string | undefined;
|
|
58
|
+
profileId?: string | undefined;
|
|
59
|
+
accountName?: string | undefined;
|
|
60
|
+
countryCode?: string | undefined;
|
|
61
|
+
currencyCode?: string | undefined;
|
|
62
|
+
}>;
|
|
63
|
+
statementEntry: z.ZodObject<{
|
|
64
|
+
accountNo: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
65
|
+
debitOrCredit: z.ZodString;
|
|
66
|
+
tranRefNo: z.ZodString;
|
|
67
|
+
narration: z.ZodString;
|
|
68
|
+
txnDate: z.ZodDate;
|
|
69
|
+
valueDate: z.ZodDate;
|
|
70
|
+
amountCredited: z.ZodNumber;
|
|
71
|
+
amountDebited: z.ZodNumber;
|
|
72
|
+
balance: z.ZodNumber;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
74
|
debitOrCredit: string;
|
|
49
75
|
tranRefNo: string;
|
|
50
76
|
narration: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/src/models/wallet/schemas.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB;;;GAGG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIzB,CAAC"}
|
|
@@ -3,11 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WalletSchemas = void 0;
|
|
4
4
|
const wallet_js_1 = require("./wallet.js");
|
|
5
5
|
const statement_entry_js_1 = require("./statement_entry.js");
|
|
6
|
+
const frontend_core_1 = require("@temboplus/frontend-core");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
/**
|
|
9
|
+
* Zod schema definition for validating Wallet data structures.
|
|
10
|
+
* Ensures data integrity for wallet objects, including runtime validation
|
|
11
|
+
* of country codes against the imported ISO2CountryCodesSet.
|
|
12
|
+
*/
|
|
13
|
+
const walletQuerySchema = zod_1.z.object({
|
|
14
|
+
id: zod_1.z.string().optional(),
|
|
15
|
+
profileId: zod_1.z.string().optional(),
|
|
16
|
+
accountNo: zod_1.z.string().optional(),
|
|
17
|
+
accountName: zod_1.z.string().optional(),
|
|
18
|
+
channel: zod_1.z.string().optional(),
|
|
19
|
+
// Validate countryCode as a string present in the imported Set
|
|
20
|
+
countryCode: zod_1.z.string().default("TZ")
|
|
21
|
+
.refine((code) => frontend_core_1.ISO2CountryCodesSet.has(code), { message: "Provided country code is not a valid ISO2 code." }).optional(),
|
|
22
|
+
// Validate currencyCode as a string present in the imported Set
|
|
23
|
+
currencyCode: zod_1.z.string().default("TZS")
|
|
24
|
+
.refine((code) => {
|
|
25
|
+
const currency = frontend_core_1.Currency.from(code);
|
|
26
|
+
return currency !== undefined &&
|
|
27
|
+
frontend_core_1.ValidCurrencyCodesSet.has(currency.code);
|
|
28
|
+
}, { message: "Provided currency code is not a valid currency code." }).optional(),
|
|
29
|
+
});
|
|
6
30
|
/**
|
|
7
31
|
* Collection of wallet-related schemas for export.
|
|
8
32
|
* Provides access to both wallet and statement entry validation schemas.
|
|
9
33
|
*/
|
|
10
34
|
exports.WalletSchemas = {
|
|
11
35
|
wallet: wallet_js_1.Wallet.schema,
|
|
36
|
+
walletQuery: walletQuerySchema,
|
|
12
37
|
statementEntry: statement_entry_js_1.WalletStatementEntry.schema,
|
|
13
38
|
};
|