"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const query_1=require("@b/utils/query"),utils_1=require("../utils"),cache_1=require("@b/utils/cache"),exchange_1=__importDefault(require("@b/utils/exchange")),db_1=require("@b/db");exports.metadata={summary:"Updates a specific exchange",operationId:"updateExchange",tags:["Admin","Exchanges"],parameters:[{index:0,name:"productId",in:"path",description:"Product ID of the exchange to update",required:!0,schema:{type:"string"}}],requestBody:{description:"New data for the exchange",content:{"application/json":{schema:utils_1.exchangeUpdateSchema}}},responses:(0,query_1.updateRecordResponses)("Exchange"),requiresAuth:!0,permission:"edit.exchange",logModule:"ADMIN_FIN",logTitle:"Update Exchange Provider"};exports.default=async e=>{const{body:a,params:t,ctx:r}=e,{productId:n}=t,{proxyUrl:c}=a,s=await db_1.models.exchange.findOne({where:{id:n}});if(!s)throw new Error("Exchange not found");null==r||r.step("Updating exchange provider");await s.update({proxyUrl:c});null==r||r.step("Clearing cache");const i=cache_1.CacheManager.getInstance();await i.clearCache();s.name&&exchange_1.default.removeExchange(s.name);null==r||r.success();return s};