"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),db_1=require("@b/db"),utils_1=require("@b/api/finance/transaction/utils"),error_1=require("@b/utils/error");exports.metadata={summary:"Updates an existing transaction",operationId:"updateTransaction",tags:["Admin","Wallets","Transactions"],parameters:[{index:0,name:"id",in:"path",description:"The ID of the transaction to update",required:!0,schema:{type:"string"}}],requestBody:{required:!0,description:"Updated data for the transaction",content:{"application/json":{schema:utils_1.transactionUpdateSchema}}},responses:(0,query_1.updateRecordResponses)("Transaction"),requiresAuth:!0,permission:"edit.transaction",logModule:"ADMIN_FIN",logTitle:"Update Transaction"};exports.default=async e=>{const{body:t,params:a,ctx:r}=e,{id:s}=a,{status:n,amount:i,fee:o,description:d,referenceId:c}=t,u=await db_1.models.transaction.findOne({where:{id:s}});if(!u)throw(0,error_1.createError)({statusCode:404,message:"Transaction not found"});if("PENDING"!==u.status)throw(0,error_1.createError)({statusCode:400,message:"Only pending transactions can be updated"});u.amount=i;u.fee=o;u.description=d;u.referenceId=c;return await db_1.sequelize.transaction(async e=>{u.status=n;await u.save({transaction:e});return{message:"Transaction updated successfully"}})};