Init commit
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user