@@ -110,76 +110,6 @@ export const refundPayloadSchema = z.object({
110110 soroban : sorobanRefundMetadataSchema ,
111111} ) ;
112112
113- function singleCampaignListQueryParam ( value : unknown ) : string | undefined {
114- if ( value === undefined || value === null ) {
115- return undefined ;
116- }
117- const raw = Array . isArray ( value ) ? value [ 0 ] : value ;
118- if ( typeof raw !== "string" && typeof raw !== "number" ) {
119- return undefined ;
120- }
121- const s = String ( raw ) . trim ( ) ;
122- return s === "" ? undefined : s ;
123- }
124-
125- /**
126- * Parses optional `page` and `limit` for GET /api/campaigns.
127- * Omitting both means no pagination (caller lists the full filtered set).
128- * Supplying only one is invalid (400).
129- */
130- export function parseCampaignListPaginationQuery ( query : {
131- page ?: unknown ;
132- limit ?: unknown ;
133- } ) : { ok : true ; page ?: number ; limit ?: number } | { ok : false ; issues : z . core . $ZodIssue [ ] } {
134- const pageStr = singleCampaignListQueryParam ( query . page ) ;
135- const limitStr = singleCampaignListQueryParam ( query . limit ) ;
136-
137- if ( pageStr === undefined && limitStr === undefined ) {
138- return { ok : true } ;
139- }
140- if ( pageStr === undefined || limitStr === undefined ) {
141- return {
142- ok : false ,
143- issues : [
144- {
145- code : "custom" ,
146- message : "Pagination requires both page and limit query parameters." ,
147- path : pageStr === undefined ? [ "page" ] : [ "limit" ] ,
148- } ,
149- ] ,
150- } ;
151- }
152-
153- const pageNum = Number ( pageStr ) ;
154- const limitNum = Number ( limitStr ) ;
155- const issues : z . core . $ZodIssue [ ] = [ ] ;
156-
157- if ( ! Number . isFinite ( pageNum ) || ! Number . isInteger ( pageNum ) || pageNum < 1 ) {
158- issues . push ( {
159- code : "custom" ,
160- message : "page must be a positive integer." ,
161- path : [ "page" ] ,
162- } ) ;
163- }
164- if (
165- ! Number . isFinite ( limitNum ) ||
166- ! Number . isInteger ( limitNum ) ||
167- limitNum < 1 ||
168- limitNum > 100
169- ) {
170- issues . push ( {
171- code : "custom" ,
172- message : "limit must be an integer from 1 to 100." ,
173- path : [ "limit" ] ,
174- } ) ;
175- }
176-
177- if ( issues . length > 0 ) {
178- return { ok : false , issues } ;
179- }
180-
181- return { ok : true , page : pageNum , limit : limitNum } ;
182- }
183113
184114
185115export type ValidationIssue = {
0 commit comments