Merge pull request #6 from kavehhn174/transaction

Transaction
This commit is contained in:
Kaveh HajiNajaf
2025-04-21 00:38:33 +03:30
committed by GitHub
4 changed files with 622 additions and 595 deletions
@@ -21,6 +21,16 @@ exports.getUserTransaction = catchAsync(async (req, res, next) => {
}) })
}) })
exports.getTransactionByBelongingId = catchAsync(async (req, res, next) => {
const transactions = await transactionService.getTransactionByBelongingId(req.params.belongingId)
res.status(200).json({
status: 'success',
results: transactions.length,
data: transactions,
})
})
exports.getBelongingInventory = catchAsync(async (req, res, next) => { exports.getBelongingInventory = catchAsync(async (req, res, next) => {
const result = await transactionService.getBelongingInventory(req.params.belongingId) const result = await transactionService.getBelongingInventory(req.params.belongingId)
@@ -25,6 +25,12 @@ router.get(
transactionController.getBelongingInventory transactionController.getBelongingInventory
) )
router.get(
'/admin/belonging/:belongingId',
// perm.requires('getallbelongings'),
transactionController.getTransactionByBelongingId
)
router.patch( router.patch(
'/admin/update/:transactionId', '/admin/update/:transactionId',
// perm.requires('getallbelongings'), // perm.requires('getallbelongings'),
+12 -1
View File
@@ -54,6 +54,10 @@ const getUserTransaction = async (userId) => {
return Transaction.find({ userId }, null, null) return Transaction.find({ userId }, null, null)
} }
const getTransactionByBelongingId = async (belongingId) => {
return Transaction.find({ belongingId }, null, null)
}
const getBelongingInventory = async (belongingId) => { const getBelongingInventory = async (belongingId) => {
const belonging = await Belonging.findById(belongingId, null, null) const belonging = await Belonging.findById(belongingId, null, null)
@@ -147,4 +151,11 @@ const deleteTransaction = async (transactionId) => {
return null return null
} }
module.exports = { createTransaction, getUserTransaction, getBelongingInventory, updateTransaction, deleteTransaction } module.exports = {
createTransaction,
getUserTransaction,
getBelongingInventory,
updateTransaction,
deleteTransaction,
getTransactionByBelongingId,
}