"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:"Set satisfaction rating for a ticket",description:"Allows the ticket owner to submit a satisfaction rating (1-5)",operationId:"reviewTicket",tags:["Support"],requiresAuth:!0,logModule:"USER",logTitle:"Review support ticket",parameters:[{index:0,name:"id",in:"path",required:!0,description:"The UUID of the ticket to review",schema:{type:"string"}}],requestBody:{description:"The satisfaction rating",required:!0,content:{"application/json":{schema:{type:"object",properties:{satisfaction:{type:"number"}},required:["satisfaction"]}}}},responses:(0,query_1.updateRecordResponses)("Support Ticket")};exports.default=async t=>{const{params:e,user:i,body:r,ctx:a}=t,{id:s}=e;if(!(null==i?void 0:i.id)){null==a||a.fail("User not authenticated");throw(0,error_1.createError)(401,"Unauthorized")}null==a||a.step("Finding support ticket");const o=await db_1.models.supportTicket.findOne({where:{id:s,userId:i.id}});if(!o){null==a||a.fail("Ticket not found");throw(0,error_1.createError)(404,"Ticket not found")}if(o.satisfaction){null==a||a.fail("Satisfaction already set");throw(0,error_1.createError)(400,"Satisfaction already set")}null==a||a.step("Validating satisfaction rating");const{satisfaction:n}=r;if("number"!=typeof n||n<1||n>5){null==a||a.fail("Invalid satisfaction rating");throw(0,error_1.createError)(400,"Satisfaction must be between 1 and 5")}null==a||a.step("Saving satisfaction rating");o.satisfaction=n;await o.save();null==a||a.success("Satisfaction rating submitted");return{message:"Satisfaction submitted",data:o.get({plain:!0})}};