@temboplus/tembo-dashboard 0.0.9 → 0.0.11
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.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/query/query.builder.d.ts +1 -1
- package/dist/modules/collection/collection.api-contract.d.ts +16 -16
- package/dist/modules/collection/collection.model.d.ts +1 -1
- package/dist/modules/collection/collection.query.d.ts +119 -0
- package/dist/modules/collection/collection.repository.d.ts +14 -92
- package/dist/modules/collection/{collection.dtos.d.ts → collection.types.d.ts} +3 -41
- package/dist/modules/collection/index.d.ts +3 -4
- package/dist/modules/payout/index.d.ts +3 -3
- package/dist/modules/payout/payout.api-contract.d.ts +17 -62
- package/dist/modules/payout/payout.model.d.ts +1 -1
- package/dist/modules/payout/payout.query.d.ts +119 -0
- package/dist/modules/payout/payout.repository.d.ts +48 -7
- package/dist/modules/payout/{payout.dtos.d.ts → payout.types.d.ts} +82 -6
- package/package.json +1 -1
- package/dist/modules/collection/collection.query-builder.d.ts +0 -27
- package/dist/modules/collection/collection.query-params.model.d.ts +0 -218
- package/dist/modules/collection/collection.utils.d.ts +0 -96
- package/dist/modules/payout/payout.query-builder.d.ts +0 -25
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { BaseRepository, PaginationDTO } from "@/lib/api";
|
|
2
2
|
import { payoutContract } from "./payout.api-contract";
|
|
3
|
-
import { type PayoutQueryParamsDTO } from "./payout.dtos";
|
|
4
3
|
import { Payout } from "./payout.model";
|
|
5
|
-
import {
|
|
4
|
+
import { PayoutQuery } from "./payout.query";
|
|
5
|
+
import { PayoutFilters } from "./payout.types";
|
|
6
|
+
/**
|
|
7
|
+
* Flexible query input type - supports the class, filters interface, URL params, etc.
|
|
8
|
+
*/
|
|
9
|
+
export type PayoutQueryInput = PayoutQuery | PayoutFilters | Record<string, string> | URLSearchParams | null | undefined;
|
|
6
10
|
/**
|
|
7
11
|
* Repository class for managing payouts through API interactions.
|
|
8
|
-
* Handles payout operations, filtering, and
|
|
12
|
+
* Handles payout operations, filtering, and summary data retrieval.
|
|
13
|
+
* Simplified to use PayoutQuery as the primary query interface.
|
|
9
14
|
*/
|
|
10
15
|
export declare class PayoutRepository extends BaseRepository<typeof payoutContract> {
|
|
11
16
|
constructor(options?: {
|
|
@@ -13,9 +18,36 @@ export declare class PayoutRepository extends BaseRepository<typeof payoutContra
|
|
|
13
18
|
root?: string;
|
|
14
19
|
});
|
|
15
20
|
/**
|
|
16
|
-
* Get all payouts with filtering and pagination
|
|
21
|
+
* Get all payouts with filtering and pagination.
|
|
22
|
+
* Accepts flexible input types and normalizes them to PayoutQuery.
|
|
23
|
+
*
|
|
24
|
+
* @param query - Query parameters in any supported format
|
|
25
|
+
* @returns Promise resolving to payouts and pagination info
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // From API route with URL search params
|
|
30
|
+
* const { searchParams } = new URL(req.url);
|
|
31
|
+
* const result = await repo.getPayouts(searchParams);
|
|
32
|
+
*
|
|
33
|
+
* // From client with typed params
|
|
34
|
+
* const filters: PayoutFilters = { page: 1, limit: 20, status: 'PAYMENT_ACCEPTED' };
|
|
35
|
+
* const result2 = await repo.getPayouts(filters);
|
|
36
|
+
*
|
|
37
|
+
* // With PayoutQuery instance
|
|
38
|
+
* const query = PayoutQuery.create().whereSuccessful().withPagination(1, 50);
|
|
39
|
+
* const result3 = await repo.getPayouts(query);
|
|
40
|
+
* ```
|
|
17
41
|
*/
|
|
18
|
-
getPayouts(query?:
|
|
42
|
+
getPayouts(query?: PayoutQueryInput): Promise<{
|
|
43
|
+
payouts: Payout[];
|
|
44
|
+
pagination: PaginationDTO;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Convenience method for Next.js API routes
|
|
48
|
+
* Extracts search params directly from Request object
|
|
49
|
+
*/
|
|
50
|
+
getPayoutsFromRequest(req: Request): Promise<{
|
|
19
51
|
payouts: Payout[];
|
|
20
52
|
pagination: PaginationDTO;
|
|
21
53
|
}>;
|
|
@@ -26,9 +58,18 @@ export declare class PayoutRepository extends BaseRepository<typeof payoutContra
|
|
|
26
58
|
/**
|
|
27
59
|
* Get payout summary statistics
|
|
28
60
|
*/
|
|
29
|
-
getPayoutSummary(): Promise<
|
|
61
|
+
getPayoutSummary(): Promise<{
|
|
62
|
+
yesterday: number;
|
|
63
|
+
today: number;
|
|
64
|
+
thisMonth: number;
|
|
65
|
+
lastMonth: number;
|
|
66
|
+
}>;
|
|
30
67
|
/**
|
|
31
68
|
* Get account balance and status information
|
|
32
69
|
*/
|
|
33
|
-
|
|
70
|
+
getBalance(): Promise<{
|
|
71
|
+
balance: number;
|
|
72
|
+
currency: string;
|
|
73
|
+
lastUpdated: string;
|
|
74
|
+
}>;
|
|
34
75
|
}
|
|
@@ -111,7 +111,7 @@ export declare const PayoutDTOSchemas: {
|
|
|
111
111
|
reversedTransactionId?: string | null | undefined;
|
|
112
112
|
isReconciled?: number | undefined;
|
|
113
113
|
}>;
|
|
114
|
-
|
|
114
|
+
payoutFilters: z.ZodObject<{
|
|
115
115
|
page: z.ZodDefault<z.ZodNumber>;
|
|
116
116
|
limit: z.ZodDefault<z.ZodNumber>;
|
|
117
117
|
sortBy: z.ZodDefault<z.ZodString>;
|
|
@@ -157,6 +157,85 @@ export declare const PayoutDTOSchemas: {
|
|
|
157
157
|
maxAmount?: number | undefined;
|
|
158
158
|
ref?: string | undefined;
|
|
159
159
|
}>;
|
|
160
|
+
payoutURLQueryParams: z.ZodObject<{
|
|
161
|
+
page: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
162
|
+
limit: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
163
|
+
sortBy: z.ZodDefault<z.ZodString>;
|
|
164
|
+
sortOrder: z.ZodDefault<z.ZodEnum<["asc", "desc"]>>;
|
|
165
|
+
startDate: z.ZodOptional<z.ZodString>;
|
|
166
|
+
endDate: z.ZodOptional<z.ZodString>;
|
|
167
|
+
msisdn: z.ZodOptional<z.ZodString>;
|
|
168
|
+
id: z.ZodOptional<z.ZodString>;
|
|
169
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
170
|
+
channel: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, MOBILE_PAYOUT_CHANNEL | BANK_PAYOUT_CHANNEL, string>>;
|
|
171
|
+
status: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, PAYOUT_STATUS, string>>;
|
|
172
|
+
minAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
173
|
+
maxAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
|
|
174
|
+
search: z.ZodOptional<z.ZodString>;
|
|
175
|
+
}, "strip", z.ZodTypeAny, {
|
|
176
|
+
sortBy: string;
|
|
177
|
+
sortOrder: "asc" | "desc";
|
|
178
|
+
status?: PAYOUT_STATUS | undefined;
|
|
179
|
+
startDate?: string | undefined;
|
|
180
|
+
endDate?: string | undefined;
|
|
181
|
+
page?: number | undefined;
|
|
182
|
+
limit?: number | undefined;
|
|
183
|
+
search?: string | undefined;
|
|
184
|
+
id?: string | undefined;
|
|
185
|
+
msisdn?: string | undefined;
|
|
186
|
+
channel?: MOBILE_PAYOUT_CHANNEL | BANK_PAYOUT_CHANNEL | undefined;
|
|
187
|
+
minAmount?: number | undefined;
|
|
188
|
+
maxAmount?: number | undefined;
|
|
189
|
+
ref?: string | undefined;
|
|
190
|
+
}, {
|
|
191
|
+
status?: string | undefined;
|
|
192
|
+
startDate?: string | undefined;
|
|
193
|
+
endDate?: string | undefined;
|
|
194
|
+
page?: string | undefined;
|
|
195
|
+
limit?: string | undefined;
|
|
196
|
+
search?: string | undefined;
|
|
197
|
+
id?: string | undefined;
|
|
198
|
+
msisdn?: string | undefined;
|
|
199
|
+
channel?: string | undefined;
|
|
200
|
+
sortBy?: string | undefined;
|
|
201
|
+
sortOrder?: "asc" | "desc" | undefined;
|
|
202
|
+
minAmount?: string | undefined;
|
|
203
|
+
maxAmount?: string | undefined;
|
|
204
|
+
ref?: string | undefined;
|
|
205
|
+
}>;
|
|
206
|
+
payoutStatus: z.ZodNativeEnum<typeof PAYOUT_STATUS>;
|
|
207
|
+
payoutChannel: z.ZodUnion<[z.ZodNativeEnum<typeof MOBILE_PAYOUT_CHANNEL>, z.ZodNativeEnum<typeof BANK_PAYOUT_CHANNEL>]>;
|
|
208
|
+
mobileChannel: z.ZodNativeEnum<typeof MOBILE_PAYOUT_CHANNEL>;
|
|
209
|
+
bankChannel: z.ZodNativeEnum<typeof BANK_PAYOUT_CHANNEL>;
|
|
210
|
+
walletSummary: z.ZodObject<{
|
|
211
|
+
balance: z.ZodNumber;
|
|
212
|
+
currency: z.ZodString;
|
|
213
|
+
lastUpdated: z.ZodString;
|
|
214
|
+
}, "strip", z.ZodTypeAny, {
|
|
215
|
+
balance: number;
|
|
216
|
+
currency: string;
|
|
217
|
+
lastUpdated: string;
|
|
218
|
+
}, {
|
|
219
|
+
balance: number;
|
|
220
|
+
currency: string;
|
|
221
|
+
lastUpdated: string;
|
|
222
|
+
}>;
|
|
223
|
+
transactionSummary: z.ZodObject<{
|
|
224
|
+
yesterday: z.ZodNumber;
|
|
225
|
+
today: z.ZodNumber;
|
|
226
|
+
thisMonth: z.ZodNumber;
|
|
227
|
+
lastMonth: z.ZodNumber;
|
|
228
|
+
}, "strip", z.ZodTypeAny, {
|
|
229
|
+
yesterday: number;
|
|
230
|
+
today: number;
|
|
231
|
+
thisMonth: number;
|
|
232
|
+
lastMonth: number;
|
|
233
|
+
}, {
|
|
234
|
+
yesterday: number;
|
|
235
|
+
today: number;
|
|
236
|
+
thisMonth: number;
|
|
237
|
+
lastMonth: number;
|
|
238
|
+
}>;
|
|
160
239
|
pagination: z.ZodObject<{
|
|
161
240
|
page: z.ZodNumber;
|
|
162
241
|
limit: z.ZodNumber;
|
|
@@ -179,10 +258,7 @@ export declare const PayoutDTOSchemas: {
|
|
|
179
258
|
hasNext: boolean;
|
|
180
259
|
hasPrev: boolean;
|
|
181
260
|
}>;
|
|
182
|
-
payoutStatus: z.ZodNativeEnum<typeof PAYOUT_STATUS>;
|
|
183
|
-
payoutChannel: z.ZodUnion<[z.ZodNativeEnum<typeof MOBILE_PAYOUT_CHANNEL>, z.ZodNativeEnum<typeof BANK_PAYOUT_CHANNEL>]>;
|
|
184
|
-
mobileChannel: z.ZodNativeEnum<typeof MOBILE_PAYOUT_CHANNEL>;
|
|
185
|
-
bankChannel: z.ZodNativeEnum<typeof BANK_PAYOUT_CHANNEL>;
|
|
186
261
|
};
|
|
187
262
|
export type PayoutDTO = z.infer<typeof PayoutDTOSchemas.payout>;
|
|
188
|
-
export type
|
|
263
|
+
export type PayoutFilters = z.infer<typeof PayoutDTOSchemas.payoutFilters>;
|
|
264
|
+
export type PayoutURLQueryParams = z.infer<typeof PayoutDTOSchemas.payoutURLQueryParams>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/tembo-dashboard",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "A foundational library for Temboplus-Dashboard projects providing type-safe data layer abstraction with API contracts, domain models, and repositories.",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { QueryBuilder } from "@/lib/query";
|
|
2
|
-
import { COLLECTION_STATUS, COLLECTION_CHANNEL, CollectionQueryParamsDTO } from "./collection.dtos";
|
|
3
|
-
/**
|
|
4
|
-
* Specialized query builder for collection queries
|
|
5
|
-
*/
|
|
6
|
-
export declare class CollectionQueryBuilder extends QueryBuilder {
|
|
7
|
-
static create(): CollectionQueryBuilder;
|
|
8
|
-
static forCollections(): CollectionQueryBuilder;
|
|
9
|
-
static fromDTO(dto: CollectionQueryParamsDTO): CollectionQueryBuilder;
|
|
10
|
-
whereStatus(status: COLLECTION_STATUS): this;
|
|
11
|
-
whereChannel(channel: COLLECTION_CHANNEL): this;
|
|
12
|
-
wherePending(): this;
|
|
13
|
-
whereSuccessful(): this;
|
|
14
|
-
whereFailed(): this;
|
|
15
|
-
whereAmountBetween(min: number, max: number): this;
|
|
16
|
-
whereSender(msisdn: string): this;
|
|
17
|
-
whereAccount(accountNo: string): this;
|
|
18
|
-
whereReference(reference: string): this;
|
|
19
|
-
wherePartnerReference(partnerReference: string): this;
|
|
20
|
-
whereSearch(searchTerm: string): this;
|
|
21
|
-
toCollectionQuery(): CollectionQueryParamsDTO;
|
|
22
|
-
private extractFilterValues;
|
|
23
|
-
private extractSortField;
|
|
24
|
-
private extractSortOrder;
|
|
25
|
-
private isValidChannel;
|
|
26
|
-
private isValidStatus;
|
|
27
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { COLLECTION_STATUS, COLLECTION_CHANNEL, CollectionQueryParamsDTO } from "./collection.dtos";
|
|
2
|
-
/**
|
|
3
|
-
* Collection query parameters class with built-in conversion methods.
|
|
4
|
-
* Supports creation from various input types and conversion to different formats.
|
|
5
|
-
*/
|
|
6
|
-
export declare class CollectionQueryParams {
|
|
7
|
-
readonly page: number;
|
|
8
|
-
readonly limit: number;
|
|
9
|
-
readonly sortBy: string;
|
|
10
|
-
readonly sortOrder: "asc" | "desc";
|
|
11
|
-
readonly startDate?: string;
|
|
12
|
-
readonly endDate?: string;
|
|
13
|
-
readonly msisdn?: string;
|
|
14
|
-
readonly id?: string;
|
|
15
|
-
readonly reference?: string;
|
|
16
|
-
readonly accountNo?: string;
|
|
17
|
-
readonly partnerReference?: string;
|
|
18
|
-
readonly channel?: COLLECTION_CHANNEL;
|
|
19
|
-
readonly status?: COLLECTION_STATUS;
|
|
20
|
-
readonly minAmount?: number;
|
|
21
|
-
readonly maxAmount?: number;
|
|
22
|
-
readonly search?: string;
|
|
23
|
-
constructor(params?: Partial<CollectionQueryParamsDTO>);
|
|
24
|
-
/**
|
|
25
|
-
* Robust type guard that also validates the data structure.
|
|
26
|
-
* Stricter than `is()` method - validates all properties against schema.
|
|
27
|
-
*
|
|
28
|
-
* @param obj - Object to check and validate
|
|
29
|
-
* @returns True if the object is a valid CollectionQueryParams instance with valid data
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* const validParams = new CollectionQueryParams({ page: 1, limit: 20 });
|
|
34
|
-
* const invalidParams = { page: -1, limit: 'invalid' };
|
|
35
|
-
*
|
|
36
|
-
* console.log(CollectionQueryParams.isValid(validParams)); // true
|
|
37
|
-
* console.log(CollectionQueryParams.isValid(invalidParams)); // false
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
static is(obj: any): obj is CollectionQueryParams;
|
|
41
|
-
/**
|
|
42
|
-
* Create from URL search parameters (strings)
|
|
43
|
-
* @param params - URL search parameters as string key-value pairs
|
|
44
|
-
* @returns New CollectionQueryParams instance
|
|
45
|
-
* @throws Error if validation fails
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const params = CollectionQueryParams.fromUrlParams({
|
|
50
|
-
* page: "1",
|
|
51
|
-
* limit: "20",
|
|
52
|
-
* status: "PAYMENT_ACCEPTED"
|
|
53
|
-
* });
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
static fromUrlParams(params: Record<string, string>): CollectionQueryParams;
|
|
57
|
-
/**
|
|
58
|
-
* Create from URLSearchParams object
|
|
59
|
-
* @param searchParams - URLSearchParams instance
|
|
60
|
-
* @returns New CollectionQueryParams instance
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* ```typescript
|
|
64
|
-
* const url = new URL('https://api.example.com/collections?page=1&limit=20');
|
|
65
|
-
* const params = CollectionQueryParams.fromSearchParams(url.searchParams);
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
static fromSearchParams(searchParams: URLSearchParams): CollectionQueryParams;
|
|
69
|
-
/**
|
|
70
|
-
* Create from a Next.js Request object
|
|
71
|
-
* @param request - Next.js Request object
|
|
72
|
-
* @returns New CollectionQueryParams instance
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // In API route
|
|
77
|
-
* export async function GET(req: Request) {
|
|
78
|
-
* const params = CollectionQueryParams.fromRequest(req);
|
|
79
|
-
* // use params...
|
|
80
|
-
* }
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
static fromRequest(request: Request): CollectionQueryParams;
|
|
84
|
-
/**
|
|
85
|
-
* Create from typed DTO object
|
|
86
|
-
* @param dto - Typed CollectionQueryParamsDTO object
|
|
87
|
-
* @returns New CollectionQueryParams instance
|
|
88
|
-
*/
|
|
89
|
-
static fromDTO(dto: CollectionQueryParamsDTO): CollectionQueryParams;
|
|
90
|
-
/**
|
|
91
|
-
* Create from any supported input type
|
|
92
|
-
* @param input - Any supported input type
|
|
93
|
-
* @returns New CollectionQueryParams instance
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* // Works with all these types
|
|
98
|
-
* const params1 = CollectionQueryParams.from({ page: 1, limit: 20 });
|
|
99
|
-
* const params2 = CollectionQueryParams.from({ page: "1", limit: "20" });
|
|
100
|
-
* const params3 = CollectionQueryParams.from(new URLSearchParams("page=1"));
|
|
101
|
-
* const params4 = CollectionQueryParams.from(null); // defaults
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
static from(input: CollectionQueryParamsDTO | Record<string, string> | URLSearchParams | null | undefined): CollectionQueryParams;
|
|
105
|
-
/**
|
|
106
|
-
* Type guard to check if input is a string-based record
|
|
107
|
-
*/
|
|
108
|
-
private static isStringRecord;
|
|
109
|
-
/**
|
|
110
|
-
* Convert to URL-safe string parameters
|
|
111
|
-
* @returns Object with string values for URLSearchParams
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const params = new CollectionQueryParams({ page: 1, limit: 20 });
|
|
116
|
-
* const urlParams = params.toUrlParams();
|
|
117
|
-
* const queryString = new URLSearchParams(urlParams).toString();
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
toUrlParams(): Record<string, string>;
|
|
121
|
-
/**
|
|
122
|
-
* Convert to URLSearchParams object
|
|
123
|
-
* @returns URLSearchParams instance
|
|
124
|
-
*/
|
|
125
|
-
toSearchParams(): URLSearchParams;
|
|
126
|
-
/**
|
|
127
|
-
* Convert to query string
|
|
128
|
-
* @returns URL query string (without leading ?)
|
|
129
|
-
*/
|
|
130
|
-
toQueryString(): string;
|
|
131
|
-
/**
|
|
132
|
-
* Convert to typed DTO object
|
|
133
|
-
* @returns Plain object matching CollectionQueryParamsDTO interface
|
|
134
|
-
*/
|
|
135
|
-
toDTO(): CollectionQueryParamsDTO;
|
|
136
|
-
/**
|
|
137
|
-
* Convert to JSON string
|
|
138
|
-
* @returns JSON string representation
|
|
139
|
-
*/
|
|
140
|
-
toJSON(): string;
|
|
141
|
-
/**
|
|
142
|
-
* Create a new instance with updated pagination
|
|
143
|
-
* @param page - Page number
|
|
144
|
-
* @param limit - Items per page
|
|
145
|
-
* @returns New CollectionQueryParams instance
|
|
146
|
-
*/
|
|
147
|
-
withPagination(page: number, limit?: number): CollectionQueryParams;
|
|
148
|
-
/**
|
|
149
|
-
* Create a new instance with updated sorting
|
|
150
|
-
* @param sortBy - Field to sort by
|
|
151
|
-
* @param sortOrder - Sort direction
|
|
152
|
-
* @returns New CollectionQueryParams instance
|
|
153
|
-
*/
|
|
154
|
-
withSorting(sortBy: string, sortOrder?: "asc" | "desc"): CollectionQueryParams;
|
|
155
|
-
/**
|
|
156
|
-
* Create a new instance with date range filter
|
|
157
|
-
* @param startDate - Start date (ISO string)
|
|
158
|
-
* @param endDate - End date (ISO string)
|
|
159
|
-
* @returns New CollectionQueryParams instance
|
|
160
|
-
*/
|
|
161
|
-
withDateRange(startDate?: string, endDate?: string): CollectionQueryParams;
|
|
162
|
-
/**
|
|
163
|
-
* Create a new instance with status filter
|
|
164
|
-
* @param status - Collection status
|
|
165
|
-
* @returns New CollectionQueryParams instance
|
|
166
|
-
*/
|
|
167
|
-
withStatus(status?: COLLECTION_STATUS): CollectionQueryParams;
|
|
168
|
-
/**
|
|
169
|
-
* Create a new instance with channel filter
|
|
170
|
-
* @param channel - Collection channel
|
|
171
|
-
* @returns New CollectionQueryParams instance
|
|
172
|
-
*/
|
|
173
|
-
withChannel(channel?: COLLECTION_CHANNEL): CollectionQueryParams;
|
|
174
|
-
/**
|
|
175
|
-
* Create a new instance with amount range filter
|
|
176
|
-
* @param minAmount - Minimum amount
|
|
177
|
-
* @param maxAmount - Maximum amount
|
|
178
|
-
* @returns New CollectionQueryParams instance
|
|
179
|
-
*/
|
|
180
|
-
withAmountRange(minAmount?: number, maxAmount?: number): CollectionQueryParams;
|
|
181
|
-
/**
|
|
182
|
-
* Create a new instance with search filter
|
|
183
|
-
* @param search - Search term
|
|
184
|
-
* @returns New CollectionQueryParams instance
|
|
185
|
-
*/
|
|
186
|
-
withSearch(search?: string): CollectionQueryParams;
|
|
187
|
-
/**
|
|
188
|
-
* Create a new instance with multiple filters
|
|
189
|
-
* @param filters - Partial filter object
|
|
190
|
-
* @returns New CollectionQueryParams instance
|
|
191
|
-
*/
|
|
192
|
-
withFilters(filters: Partial<CollectionQueryParamsDTO>): CollectionQueryParams;
|
|
193
|
-
/**
|
|
194
|
-
* Reset to first page (useful when changing filters)
|
|
195
|
-
* @returns New CollectionQueryParams instance with page = 1
|
|
196
|
-
*/
|
|
197
|
-
resetPage(): CollectionQueryParams;
|
|
198
|
-
/**
|
|
199
|
-
* Check if this represents the default/empty query
|
|
200
|
-
* @returns True if all values are at their defaults
|
|
201
|
-
*/
|
|
202
|
-
isDefault(): boolean;
|
|
203
|
-
/**
|
|
204
|
-
* Check if any filters are applied (excluding pagination and sorting)
|
|
205
|
-
* @returns True if any filter fields are set
|
|
206
|
-
*/
|
|
207
|
-
hasFilters(): boolean;
|
|
208
|
-
/**
|
|
209
|
-
* Get a summary of active filters
|
|
210
|
-
* @returns Array of human-readable filter descriptions
|
|
211
|
-
*/
|
|
212
|
-
getActiveFilters(): string[];
|
|
213
|
-
/**
|
|
214
|
-
* Create a clone of this instance
|
|
215
|
-
* @returns New CollectionQueryParams instance with same values
|
|
216
|
-
*/
|
|
217
|
-
clone(): CollectionQueryParams;
|
|
218
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { CollectionQueryParamsDTO } from "./collection.dtos";
|
|
2
|
-
/**
|
|
3
|
-
* Converts URL search parameters (string-based) to properly typed CollectionQueryParamsDTO.
|
|
4
|
-
*
|
|
5
|
-
* This function handles the conversion from URL search parameters (which are always strings)
|
|
6
|
-
* to the typed DTO used internally. It performs validation and type conversion for:
|
|
7
|
-
* - Numbers (page, limit, amounts)
|
|
8
|
-
* - Enums (status, channel)
|
|
9
|
-
* - Dates (startDate, endDate)
|
|
10
|
-
* - Optional string fields
|
|
11
|
-
*
|
|
12
|
-
* @param urlParams - Raw URL search parameters as key-value string pairs
|
|
13
|
-
* @returns Validated and typed CollectionQueryParamsDTO object
|
|
14
|
-
*
|
|
15
|
-
* @throws {ZodError} When URL parameters fail validation (invalid enum values, malformed numbers, etc.)
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const urlParams = {
|
|
20
|
-
* page: "1",
|
|
21
|
-
* limit: "20",
|
|
22
|
-
* status: "PAYMENT_ACCEPTED",
|
|
23
|
-
* minAmount: "100.50"
|
|
24
|
-
* };
|
|
25
|
-
*
|
|
26
|
-
* const queryParams = urlParamsToQueryParams(urlParams);
|
|
27
|
-
* // Result: { page: 1, limit: 20, status: COLLECTION_STATUS.PAYMENT_ACCEPTED, minAmount: 100.5 }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Usage in API route
|
|
33
|
-
* export async function GET(req: NextRequest) {
|
|
34
|
-
* const searchParams = Object.fromEntries(req.nextUrl.searchParams.entries());
|
|
35
|
-
* const queryParams = urlParamsToQueryParams(searchParams);
|
|
36
|
-
* // Now you have properly typed parameters
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
declare function urlParamsToQueryParams(urlParams: Record<string, string>): CollectionQueryParamsDTO;
|
|
41
|
-
/**
|
|
42
|
-
* Converts typed CollectionQueryParamsDTO to URL-safe string parameters.
|
|
43
|
-
*
|
|
44
|
-
* This function transforms the typed DTO back into string-based key-value pairs
|
|
45
|
-
* suitable for URL search parameters or form submission. It:
|
|
46
|
-
* - Filters out undefined and null values
|
|
47
|
-
* - Converts all values to strings
|
|
48
|
-
* - Preserves the original parameter names
|
|
49
|
-
*
|
|
50
|
-
* @param queryParams - Typed collection query parameters
|
|
51
|
-
* @returns Object with string values suitable for URLSearchParams or query string construction
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* const queryParams: CollectionQueryParamsDTO = {
|
|
56
|
-
* page: 1,
|
|
57
|
-
* limit: 20,
|
|
58
|
-
* status: COLLECTION_STATUS.PAYMENT_ACCEPTED,
|
|
59
|
-
* minAmount: 100.50,
|
|
60
|
-
* search: "test query"
|
|
61
|
-
* };
|
|
62
|
-
*
|
|
63
|
-
* const urlParams = queryParamsToURLParams(queryParams);
|
|
64
|
-
* // Result: {
|
|
65
|
-
* // page: "1",
|
|
66
|
-
* // limit: "20",
|
|
67
|
-
* // status: "PAYMENT_ACCEPTED",
|
|
68
|
-
* // minAmount: "100.5",
|
|
69
|
-
* // search: "test query"
|
|
70
|
-
* // }
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* // Usage with URLSearchParams
|
|
76
|
-
* const queryParams = { page: 1, limit: 20, status: COLLECTION_STATUS.PAYMENT_ACCEPTED };
|
|
77
|
-
* const urlParams = queryParamsToURLParams(queryParams);
|
|
78
|
-
* const searchParams = new URLSearchParams(urlParams);
|
|
79
|
-
* const queryString = searchParams.toString();
|
|
80
|
-
* // Result: "page=1&limit=20&status=PAYMENT_ACCEPTED"
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* // Usage in client-side API calls
|
|
86
|
-
* const filters = { status: COLLECTION_STATUS.PENDING_ACK, minAmount: 50 };
|
|
87
|
-
* const urlParams = queryParamsToURLParams(filters);
|
|
88
|
-
* const response = await fetch(`/api/collections?${new URLSearchParams(urlParams)}`);
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
declare function queryParamsToURLParams(queryParams: CollectionQueryParamsDTO): Record<string, string>;
|
|
92
|
-
export declare const CollectionUtils: {
|
|
93
|
-
urlParamsToQueryParams: typeof urlParamsToQueryParams;
|
|
94
|
-
queryParamsToURLParams: typeof queryParamsToURLParams;
|
|
95
|
-
};
|
|
96
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { QueryBuilder } from "@/lib/query";
|
|
2
|
-
import { PAYOUT_STATUS, PAYOUT_CHANNEL, PayoutQueryParamsDTO } from "./payout.dtos";
|
|
3
|
-
/**
|
|
4
|
-
* Specialized query builder for payout queries
|
|
5
|
-
*/
|
|
6
|
-
export declare class PayoutQueryBuilder extends QueryBuilder {
|
|
7
|
-
static create(): PayoutQueryBuilder;
|
|
8
|
-
static fromDTO(dto: PayoutQueryParamsDTO): PayoutQueryBuilder;
|
|
9
|
-
whereStatus(status: PAYOUT_STATUS): this;
|
|
10
|
-
whereChannel(channel: PAYOUT_CHANNEL): this;
|
|
11
|
-
wherePending(): this;
|
|
12
|
-
whereSuccessful(): this;
|
|
13
|
-
whereFailed(): this;
|
|
14
|
-
whereAmountBetween(min: number, max: number): this;
|
|
15
|
-
whereRecipient(msisdn: string): this;
|
|
16
|
-
whereReference(ref: string): this;
|
|
17
|
-
whereSearch(searchTerm: string): this;
|
|
18
|
-
toPayoutQuery(): PayoutQueryParamsDTO;
|
|
19
|
-
private extractFilterValues;
|
|
20
|
-
private extractSortField;
|
|
21
|
-
private extractSortOrder;
|
|
22
|
-
private isValidChannel;
|
|
23
|
-
private isValidStatus;
|
|
24
|
-
static forPayouts(): PayoutQueryBuilder;
|
|
25
|
-
}
|