refactor: update

This commit is contained in:
dancingCycle 2023-11-24 11:32:07 +01:00
parent 2b81926861
commit a833b9513e
4 changed files with 36 additions and 43 deletions

View File

@ -1,22 +1,17 @@
const debug=require('debug')('debug');
const db = require('./db');
const helper = require('../helper');
require('dotenv').config();
/**
* Get all agencies with all columns
*
* @return Array of agency objects
*/
async function get() {
debug('agency-all start...');
const schema = process.env.DB_SCHEMA || 'schema';
debug('agency-all schema: ' + schema );
const query = 'SELECT * FROM ' + schema + '.agency';
debug('agency-all query: ' + query );
const DATA = await db.query( query );
debug('DATA length: '+DATA.length);
debug('agency-all done.');
return DATA;
return await db.query( query );
}
module.exports = {
get

View File

@ -1,22 +1,15 @@
const debug=require('debug')('debug');
const db = require('./db');
const helper = require('../helper');
require('dotenv').config();
async function get(oset = 1,limit = 100) {
debug('agency-oset-limit start...');
const schema = process.env.DB_SCHEMA || 'schema';
const query = 'SELECT * FROM ' + schema + '.agency OFFSET $1 LIMIT $2'
const offset = helper.getOffset(oset, limit);
const rows = await db.query(
query,
[offset, limit]
);
const data = helper.emptyOrRows(rows);
debug('agency-oset-limit done.');
return data;
const rows = await db.query(query, [offset, limit]);
return helper.emptyOrRows(rows);
};
module.exports = {
get

View File

@ -1,26 +1,31 @@
const DEBUG=require('debug')('agency');
DEBUG('agency start...');
const debug=require('debug')('agency');
require('dotenv').config();
const db = require('./db');
const helper = require('../helper');
const config = require('../config');
async function getMultiple(page = 1) {
const offset = helper.getOffset(page, config.listPerPage);
const rows = await db.query(
'SELECT * FROM agency OFFSET $1 LIMIT $2',
[offset, config.listPerPage]
);
const data = helper.emptyOrRows(rows);
const meta = {page};
return {
data,
meta
}
}
debug('agency start...');
const schema = process.env.DB_SCHEMA || 'schema';
const query =`SELECT * FROM ` + schema + `.agency OFFSET $1 LIMIT $2`;
debug('query: ' + query );
const offset = helper.getOffset(page, config.listPerPage);
const rows = await db.query(query, [offset, config.listPerPage]);
const data = helper.emptyOrRows(rows);
const meta = {page};
debug('agency done.');
return {
data,
meta
};
};
module.exports = {
getMultiple
}
DEBUG('agency done.');
};

View File

@ -1,16 +1,16 @@
const debug=require('debug')('debug');
require('dotenv').config();
const db = require('./db');
/**
* Get id and name of all agencies
*
* @return Array of agency objects containing id and name
*/
async function get() {
const schema = process.env.DB_SCHEMA || 'schema';
debug('schema: ' + schema );
const DATA = await db.query(
'SELECT agency.agency_id, agency.agency_name FROM ' + schema + '.agency');
return DATA;
const query = 'SELECT agency.agency_id, agency.agency_name FROM ' + schema + '.agency;'
return await db.query(query );
}
module.exports = {
get