Init commit

This commit is contained in:
2024-12-22 16:52:30 +03:30
parent 28ab698dfc
commit aeb38982ca
28 changed files with 1532 additions and 68 deletions
+40
View File
@@ -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
}