"use strict";async function getUserInvestment(e){const t=await db_1.models.investment.findAll({where:{userId:e,status:"ACTIVE"},include:[{model:db_1.models.investmentPlan,as:"plan"},{model:db_1.models.user,as:"user",attributes:["id","firstName","lastName","email","avatar"]}]});if(!t||0===t.length)throw(0,error_1.createError)({statusCode:404,message:"No active investments found"});return t.map(e=>e.get({plain:!0}))}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;exports.getUserInvestment=getUserInvestment;const db_1=require("@b/db"),error_1=require("@b/utils/error"),query_1=require("@b/utils/query"),utils_1=require("./utils");exports.metadata={summary:"Retrieves investments for the logged-in user",description:"Fetches all active investments associated with the currently authenticated user, including details about the investment plan and user information.",operationId:"getUserInvestments",tags:["Finance","Investment"],responses:{200:{description:"Investments retrieved successfully",content:{"application/json":{schema:{type:"array",items:{type:"object",properties:{...utils_1.baseInvestmentSchema,user:{type:"object",properties:utils_1.baseUserSchema},plan:{type:"object",properties:utils_1.baseInvestmentPlanSchema}}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Investment"),500:query_1.serverErrorResponse},requiresAuth:!0};exports.default=async e=>{var t;if(!(null===(t=e.user)||void 0===t?void 0:t.id))throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"});return getUserInvestment(e.user.id)};