"use strict";async function getPost(e){const t=await db_1.models.post.findOne({where:{slug:e},include:[{model:db_1.models.author,as:"author",include:[{model:db_1.models.user,as:"user",attributes:["id","firstName","lastName","email","avatar"],include:[{model:db_1.models.role,as:"role",attributes:["name"]}]}]},{model:db_1.models.category,as:"category"},{model:db_1.models.tag,as:"tags",through:{attributes:[]}},{model:db_1.models.comment,as:"comments",attributes:["id","content","createdAt"],include:[{model:db_1.models.user,as:"user",attributes:["id","firstName","lastName","email","avatar"]}]}]});if(!t)return null;const s=cache_1.CacheManager.getInstance(),o=await s.getSettings(),a=o.has("showRelatedPosts")?o.get("showRelatedPosts"):null,r="boolean"==typeof a?a:Boolean(a),i={...t.toJSON()};if(r){const e=await db_1.models.post.findAll({where:{id:{[sequelize_1.Op.ne]:t.id},categoryId:t.categoryId},limit:5,order:[["createdAt","DESC"]],attributes:["id","title","slug","image","createdAt"],include:[{model:db_1.models.author,as:"author",include:[{model:db_1.models.user,as:"user",attributes:["firstName","lastName"]}]}]});i.relatedPosts=e.map(e=>({...e.toJSON()}))}null===t.views?await t.update({views:1}):await t.increment("views",{by:1});return i}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;exports.getPost=getPost;const db_1=require("@b/db"),query_1=require("@b/utils/query"),utils_1=require("../utils"),sequelize_1=require("sequelize"),cache_1=require("@b/utils/cache");exports.metadata={summary:"Retrieves a single blog post by ID",description:"This endpoint retrieves a single blog post by its ID.",operationId:"getPostById",tags:["Blog"],requiresAuth:!1,parameters:[{index:0,name:"slug",in:"path",description:"The ID of the blog post to retrieve",required:!0,schema:{type:"string",description:"Post ID"}}],responses:{200:{description:"Blog post retrieved successfully",content:{"application/json":{schema:{type:"object",properties:utils_1.basePostSchema}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Post"),500:query_1.serverErrorResponse}};exports.default=async e=>{const{params:t,ctx:s}=e,{slug:o}=t;null==s||s.step(`Fetching blog post ${o}`);const a=await getPost(o);null==s||s.success("Blog post retrieved successfully");return a};