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;
