"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.getUserById=void 0;const db_1=require("@b/db"),console_1=require("@b/utils/console"),error_1=require("@b/utils/error"),getUserById=async e=>{const r=await db_1.models.user.findOne({where:{id:e},include:[{model:db_1.models.role,as:"role",attributes:["id","name"],include:[{model:db_1.models.permission,as:"permissions",through:{attributes:[]},attributes:["id","name"]}]},{model:db_1.models.twoFactor,as:"twoFactor",attributes:["type","enabled"]},{model:db_1.models.kycApplication,as:"kyc",attributes:["status"],include:[{model:db_1.models.kycLevel,as:"level",attributes:["id","name","level","features"],paranoid:!1}]},{model:db_1.models.author,as:"author",attributes:["id","status"]},{model:db_1.models.providerUser,as:"providers",attributes:["provider","providerUserId"]}],attributes:{exclude:["password"]}});if(!r)throw(0,error_1.createError)({statusCode:404,message:"User not found"});const s=r.get({plain:!0});let t=[];if(s.kyc&&"APPROVED"===s.kyc.status&&s.kyc.level){s.kycLevel=s.kyc.level.level;try{if(s.kyc.level.features){"string"==typeof s.kyc.level.features?t=JSON.parse(s.kyc.level.features):Array.isArray(s.kyc.level.features)&&(t=s.kyc.level.features);Array.isArray(t)||(t=[])}}catch(e){console_1.logger.error("USER","Error parsing KYC level features",e);t=[]}}else s.kycLevel=0;s.featureAccess=t;return s};exports.getUserById=getUserById;