From 4787ef3de75197f95fa3e4c7cff7df6cec00b6ce Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 18 Oct 2022 11:15:26 -0400 Subject: [PATCH] feat: api to check if there are pending transactions --- src/controllers/staging.controller.js | 15 +++++++++++++++ src/routes/v1/resources/staging.js | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/controllers/staging.controller.js b/src/controllers/staging.controller.js index e1038d8a..fa764593 100644 --- a/src/controllers/staging.controller.js +++ b/src/controllers/staging.controller.js @@ -16,6 +16,21 @@ import { assertStagingTableNotEmpty, } from '../utils/data-assertions'; +export const hasPendingTransactions = async (req, res) => { + try { + await assertNoPendingCommits(); + res.json({ + confirmed: true, + message: 'There are no pending transactions', + }); + } catch (error) { + res.json({ + confirmed: false, + message: 'There are currently pending transactions', + }); + } +}; + export const findAll = async (req, res) => { try { let { page, limit, type, table } = req.query; diff --git a/src/routes/v1/resources/staging.js b/src/routes/v1/resources/staging.js index 9e3cbc52..fb1e4715 100644 --- a/src/routes/v1/resources/staging.js +++ b/src/routes/v1/resources/staging.js @@ -45,4 +45,8 @@ StagingRouter.post( // Empty entire stagin table StagingRouter.delete('/clean', StagingController.clean); +StagingRouter.get('/hasPendingTransactions', (req, res) => { + return StagingController.hasPendingTransactions(req, res); +}); + export { StagingRouter };