41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const transactionService = require('./transactionService')
|
|
|
|
exports.createTransaction = catchAsync(async (req, res, next) => {
|
|
const transactions = await transactionService.createTransaction(req.body)
|
|
|
|
res.status(201).json({
|
|
status: 'success',
|
|
results: transactions.length,
|
|
data: transactions,
|
|
})
|
|
})
|
|
|
|
exports.getUserTransaction = catchAsync(async (req, res, next) => {
|
|
const transactions = await transactionService.getUserTransaction(req.user._id)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
results: transactions.length,
|
|
data: transactions,
|
|
})
|
|
})
|
|
|
|
exports.getBelongingInventory = catchAsync(async (req, res, next) => {
|
|
const result = await transactionService.getBelongingInventory(req.params.belongingId)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: result,
|
|
})
|
|
})
|
|
|
|
exports.updateTransaction = catchAsync(async (req, res, next) => {
|
|
const transaction = await transactionService.updateTransaction(req.params.transactionId, req.body)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
data: transaction,
|
|
})
|
|
})
|