84 lines
2.3 KiB
JavaScript
84 lines
2.3 KiB
JavaScript
const catchAsync = require('../../globalErrorHandler/catchAsync')
|
|
const transactionService = require('./transactionService')
|
|
|
|
exports.searchTransactions = catchAsync(async (req, res, next) => {
|
|
const { facets, transactions, totalCount, pagesCount } = await transactionService.searchTransactions(req.query)
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
facets,
|
|
transactions,
|
|
totalCount,
|
|
pagesCount,
|
|
})
|
|
})
|
|
|
|
exports.indexAllTransactions = catchAsync(async (req, res, next) => {
|
|
const { indexedCount } = await transactionService.indexAllTransactions()
|
|
|
|
res.status(200).json({
|
|
status: 'success',
|
|
indexedCount,
|
|
})
|
|
})
|
|
|
|
exports.createTransaction = catchAsync(async (req, res, next) => {
|
|
req.body.userId = req.user._id
|
|
req.body.userName = req.user.name
|
|
console.log(req.body)
|
|
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.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) => {
|
|
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,
|
|
})
|
|
})
|
|
|
|
exports.deleteTransaction = catchAsync(async (req, res, next) => {
|
|
await transactionService.deleteTransaction(req.params.transactionId)
|
|
|
|
res.status(204).json({
|
|
status: 'success',
|
|
data: null,
|
|
})
|
|
})
|