const PropertyStatus = require('./propertyStatusModel') const AppError = require('../../globalErrorHandler/AppError') const getAllStatuses = async () => { return PropertyStatus.find({}) } const getStatus = async (statusId) => { const status = await PropertyStatus.findById(statusId) if (!status) { throw new AppError('NoPropertyStatusFound', 404, {}) } return status } const createStatus = async (data) => { return PropertyStatus.create(data) } const updateStatus = async (statusId, data) => { const status = await PropertyStatus.findByIdAndUpdate(statusId, data, { new: true, runValidators: true }) if (!status) { throw new AppError('NoPropertyStatusFound', 404, {}) } return status } const deleteStatus = async (statusId) => { const status = await PropertyStatus.findByIdAndDelete(statusId) if (!status) { throw new AppError('NoPropertyStatusFound', 404, {}) } return null } module.exports = { getAllStatuses, getStatus, createStatus, updateStatus, deleteStatus }