@@ -62,7 +62,7 @@ responseBodySchema.example = {
62
62
} ,
63
63
} ;
64
64
65
- export async function checkTxStatus ( fastify : FastifyInstance ) {
65
+ export async function getTransactionStatusRoute ( fastify : FastifyInstance ) {
66
66
fastify . route < {
67
67
Params : Static < typeof requestSchema > ;
68
68
Reply : Static < typeof responseBodySchema > ;
@@ -135,3 +135,50 @@ export async function checkTxStatus(fastify: FastifyInstance) {
135
135
} ,
136
136
} ) ;
137
137
}
138
+
139
+ // An alterate route that accepts the queueId as a query param.
140
+ export async function getTransactionStatusQueryParamRoute (
141
+ fastify : FastifyInstance ,
142
+ ) {
143
+ fastify . route < {
144
+ Querystring : Static < typeof requestSchema > ;
145
+ Reply : Static < typeof responseBodySchema > ;
146
+ } > ( {
147
+ method : "GET" ,
148
+ url : "/transaction/status" ,
149
+ schema : {
150
+ summary : "Get transaction status" ,
151
+ description : "Get the status for a transaction request." ,
152
+ tags : [ "Transaction" ] ,
153
+ operationId : "status" ,
154
+ querystring : requestSchema ,
155
+ response : {
156
+ ...standardResponseSchema ,
157
+ [ StatusCodes . OK ] : responseBodySchema ,
158
+ } ,
159
+ } ,
160
+ handler : async ( request , reply ) => {
161
+ const { queueId } = request . query ;
162
+ if ( ! queueId ) {
163
+ throw createCustomError (
164
+ "Queue ID is required." ,
165
+ StatusCodes . BAD_REQUEST ,
166
+ "QUEUE_ID_REQUIRED" ,
167
+ ) ;
168
+ }
169
+
170
+ const transaction = await TransactionDB . get ( queueId ) ;
171
+ if ( ! transaction ) {
172
+ throw createCustomError (
173
+ "Transaction not found." ,
174
+ StatusCodes . BAD_REQUEST ,
175
+ "TRANSACTION_NOT_FOUND" ,
176
+ ) ;
177
+ }
178
+
179
+ reply . status ( StatusCodes . OK ) . send ( {
180
+ result : toTransactionSchema ( transaction ) ,
181
+ } ) ;
182
+ } ,
183
+ } ) ;
184
+ }
0 commit comments