"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.listComplaints = listComplaints; exports.getComplaint = getComplaint; exports.createComplaint = createComplaint; exports.updateComplaint = updateComplaint; exports.deleteComplaint = deleteComplaint; const errors_1 = require("../../http/errors"); const repo = __importStar(require("./complaint.repo")); async function listComplaints(companyId, query) { const { status, severity, category, page, pageSize } = query; const where = {}; if (status) where.status = status; if (severity) where.severity = severity; if (category) where.category = category; const [complaints, total] = await repo.findMany(companyId, where, (page - 1) * pageSize, pageSize); return { data: complaints, meta: { total, page, pageSize, totalPages: Math.ceil(total / pageSize) }, }; } async function getComplaint(id, companyId) { const complaint = await repo.findById(id, companyId); if (!complaint) throw new errors_1.NotFoundError('Complaint not found'); return complaint; } async function createComplaint(companyId, data) { return repo.create({ companyId, ...data }); } async function updateComplaint(id, companyId, data) { const existing = await repo.findById(id, companyId); if (!existing) throw new errors_1.NotFoundError('Complaint not found'); const updateData = { ...data }; // When status changes to RESOLVED, set resolvedAt if (data.status === 'RESOLVED' && existing.status !== 'RESOLVED') { updateData.resolvedAt = new Date(); } return repo.updateById(id, updateData); } async function deleteComplaint(id, companyId) { const existing = await repo.findById(id, companyId); if (!existing) throw new errors_1.NotFoundError('Complaint not found'); await repo.deleteById(id); return { success: true }; } //# sourceMappingURL=complaint.service.js.map