41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
const Belonging = require('./belongingModel')
|
|
const AppError = require('../../globalErrorHandler/AppError')
|
|
|
|
module.exports.getAllBelongings = async () => {
|
|
return Belonging.find({}, null, null)
|
|
}
|
|
|
|
module.exports.createBelonging = async (data) => {
|
|
return Belonging.create(data, null)
|
|
}
|
|
|
|
module.exports.getBelonging = async (belongingId) => {
|
|
const belonging = await Belonging.findById(belongingId, null, null)
|
|
|
|
if (!belonging) {
|
|
throw new AppError('NoBelongingFound', 404, {})
|
|
}
|
|
|
|
return belonging
|
|
}
|
|
|
|
module.exports.updateBelonging = async (belongingId, data) => {
|
|
const belonging = await Belonging.findOneAndUpdate({ _id: belongingId }, data, { new: true })
|
|
|
|
if (!belonging) {
|
|
throw new AppError('NoBelongingFound', 404, {})
|
|
}
|
|
|
|
return belonging
|
|
}
|
|
|
|
module.exports.deleteBelonging = async (belongingId) => {
|
|
const belonging = await Belonging.findByIdAndUpdate(belongingId, { isActive: false }, { new: true })
|
|
|
|
if (!belonging) {
|
|
throw new AppError('NoBelongingFound', 404, {})
|
|
}
|
|
|
|
return null
|
|
}
|