mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Refactor project DB functions.
The old db.project.list() function is now db.project.get() and the old db.project.get() is not db.project.summary.get(). If a project does not exist, db.project.summary.get() now throws a 404 rather than a database error.
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
const { setSurvey } = require('../connection');
|
||||
const { setSurvey, pool } = require('../connection');
|
||||
|
||||
async function get (projectId, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
const text = `
|
||||
SELECT *
|
||||
FROM project_summary;
|
||||
`;
|
||||
|
||||
const res = await client.query(text);
|
||||
client.release();
|
||||
return res.rows[0];
|
||||
async function get () {
|
||||
const res = await pool.query("SELECT pid, name, schema FROM public.projects;");
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
module.exports = get;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
module.exports = {
|
||||
list: require('./list'),
|
||||
get: require('./get'),
|
||||
post: require('./post'),
|
||||
put: require('./put'),
|
||||
delete: require('./delete')
|
||||
delete: require('./delete'),
|
||||
summary: require('./summary'),
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
const { setSurvey, pool } = require('../connection');
|
||||
|
||||
async function list () {
|
||||
const res = await pool.query("SELECT * FROM public.projects;");
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
module.exports = list;
|
||||
24
lib/www/server/lib/db/project/summary/get.js
Normal file
24
lib/www/server/lib/db/project/summary/get.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const { setSurvey } = require('../../connection');
|
||||
|
||||
async function get (projectId, opts = {}) {
|
||||
try {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
const text = `
|
||||
SELECT *
|
||||
FROM project_summary;
|
||||
`;
|
||||
|
||||
const res = await client.query(text);
|
||||
client.release();
|
||||
return res.rows[0];
|
||||
} catch (err) {
|
||||
if (err.code == "42P01") {
|
||||
throw { status: 404, message: "Not found" };
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = get;
|
||||
3
lib/www/server/lib/db/project/summary/index.js
Normal file
3
lib/www/server/lib/db/project/summary/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
get: require('./get'),
|
||||
};
|
||||
Reference in New Issue
Block a user