"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),error_1=require("@b/utils/error"),query_1=require("@b/utils/query");exports.metadata={summary:"Update Status for a Post",operationId:"updatePostStatus",tags:["Content","Author","Post"],logModule:"BLOG",logTitle:"Update post status",parameters:[{index:0,name:"id",in:"path",required:!0,description:"ID of the Post to update",schema:{type:"string"}}],requestBody:{required:!0,content:{"application/json":{schema:{type:"object",properties:{status:{type:"string",enum:["PUBLISHED","DRAFT","TRASH"],description:"New status to apply to the Post"}},required:["status"]}}}},responses:(0,query_1.updateRecordResponses)("Post"),requiresAuth:!0};exports.default=async t=>{const{body:e,params:s,user:r,ctx:o}=t;if(!(null==r?void 0:r.id))throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"});const{id:a}=s;null==o||o.step("Verifying author credentials");const u=await db_1.models.author.findOne({where:{userId:r.id}});if(!u)throw(0,error_1.createError)({statusCode:404,message:"Author not found"});const{status:d}=e;null==o||o.step(`Updating post ${a} status to ${d}`);const i=await(0,query_1.updateStatus)("post",a,d,void 0,void 0,void 0,{authorId:u.id});null==o||o.success(`Post ${a} status updated to ${d} by author ${u.id}`);return i};