/var/www/p4ela.kz/server/delivery/api/controllers/account
Edit: /var/www/p4ela.kz/server/delivery/api/controllers/account/history.js (1114B)
const { NotFound, BadRequest } = require('../../responseModels/errors')
const { isSet, isEmpty } = require('../../utils/validator.util')
const checkPermission = require('../../utils/checkPermission.util')
module.exports = function ({ db, logger }) {
return async (req, res, next) => {
logger.child({ path: req.path, request: req.query }).info()
let t1 = performance.now()
try {
const { uid, page, limit } = req.query
if (!isSet(uid))
throw new BadRequest({ code: 1027, lang: req.user?.languageCode })
let offset = page > 0 ? (page - 1) * (limit || 10) : 0
const account = await db.account.findOne({ where: { uid } })
if (!account) throw new NotFound({ code: 1030, lang: req.user?.languageCode })
const rows = await db.accountHistory.findAll({
order:[['createdAt', 'desc']],
offset,
limit: parseInt(limit) || 10
})
if (rows.length == 0) throw new NotFound({ code: 404, lang: req.user?.languageCode })
const time = performance.now() - t1
return res.status(200).json({ list: rows, count: rows.length, time, page })
} catch (err) {
next(err)
}
}
}