Skip to content
Permalink
76c98371fa
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
70 lines (62 sloc) 2.38 KB
const db = require('../helpers/database');
//list all the applications in the database
exports.getAll = async function getAll (page, limit, order, direction) {
const offset = (page - 1) * limit;
let query;
if (direction === 'DESC') {
query = "SELECT * FROM applications ORDER BY ?? DESC LIMIT ? OFFSET ?;";
} else {
query = "SELECT * FROM applications ORDER BY ?? ASC LIMIT ? OFFSET ?;";
}
const values = [order, parseInt(limit), parseInt(offset)];
const data = await db.run_query(query, values);
return data;
}
//get a single application by its id
exports.getById = async function getById (id) {
const query = "SELECT * FROM applications WHERE ID = ?;";
const values = [id];
const data = await db.run_query(query, values);
return data;
}
//create a new application in the database
exports.add = async function add (application) {
const query = "INSERT INTO articles SET ?";
const data = await db.run_query(query, article);
return data;
}
//delete an application by its id
exports.delById = async function delById (id) {
const query = "DELETE FROM appications WHERE ID = ?;";
const values = [id];
const data = await db.run_query(query, values);
return data;
}
//update an existing application
exports.update = async function update (appication) {
const query = "UPDATE applications SET ? WHERE ID = ?;";
const values = [appication, appication.ID];
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;
}