Skip to content
Permalink
Browse files
adding status to routes and models
  • Loading branch information
skondram committed Nov 26, 2021
1 parent 5bc154c commit 76c98371faad4ea92d88b1150a2f3980d374b275
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
@@ -44,3 +44,27 @@ exports.update = async function update (appication) {
const data = await db.run_query(query, values);
return data;
}

// get all applications with a pending status
exports.getByPendingStatus = async function getByPendingStatus (applicationStatus) {
const query = "SELECT * FROM applications WHERE applicationStatus = 'pending';";
const values = [applicationStatus];
const data = await db.run_query(query, values);
return data;
}

// get all applications with an accepted status
exports.getByAcceptedStatus = async function getByAcceptedStatus (currentStatus) {
const query = "SELECT * FROM applications WHERE applicationStatus = 'accepted';";
const values = [applicationStatus];
const data = await db.run_query(query, values);
return data;
}

// get all applications with a rejected status
exports.getByStatusRejected = async function getByRejectedStatus (applicationStatus) {
const query = "SELECT * FROM applications WHERE currentStatus = 'rejected';";
const values = [applicationStatus];
const data = await db.run_query(query, values);
return data;
}
@@ -15,6 +15,11 @@ router.get('/:id([0-9]{1,})', getById);
router.put('/:id([0-9]{1,})', auth, bodyParser(), validateApplication, updateApplication);
router.del('/:id([0-9]{1,})', auth, deleteApplication);

// application status routes
router.get('/status/pending', getByPendingStatus);
router.get('/status/accepted', getByAcceptedStatus);
router.get('/status/rejected', getByRejectedStatus);

async function getAll(ctx) {
const {page=1, limit=100, order="id", direction='ASC'} = ctx.request.query;
const result = await applications.getAll(page, limit, order, direction);
@@ -66,5 +71,29 @@ async function deleteApplication(ctx) {
}
}

async function getByPendingStatus(ctx) {
const status = ctx.params.id;
const result = await applications.getByPendingStatus(status);
if (result.length) {
ctx.body = result;
}
}

async function getByAcceptedStatus(ctx) {
const status = ctx.params.id;
const result = await applications.getByAcceptedStatus(status);
if (result.length) {
ctx.body = result;
}
}

async function getByRejectedStatus(ctx) {
const status = ctx.params.id;
const result = await applications.getByRejectedStatus(status);
if (result.length) {
ctx.body = result;
}
}


module.exports = router;

0 comments on commit 76c9837

Please sign in to comment.