Add a refresh() method to db.project.summary

This commit is contained in:
D. Berge
2023-11-02 11:55:25 +01:00
parent ca8dd68d10
commit 6c00f16b7e
2 changed files with 24 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
module.exports = {
get: require('./get'),
refresh: require('./refresh')
};

View File

@@ -0,0 +1,23 @@
const { setSurvey } = require('../../connection');
async function refresh (projectId, opts = {}) {
try {
const client = await setSurvey(projectId);
const text = `
REFRESH MATERIALIZED VIEW 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 = refresh;