const { setSurvey } = require('../../connection');

async function accept (projectId, payload) {
	const client = await setSurvey(projectId);

	const text = `
		UPDATE event_log_full
		SET
			labels = array_append(labels, 'QCAccepted')
		WHERE
			validity @> current_timestamp
			AND id = ANY($1)
			AND NOT ('QCAccepted' = ANY(labels));
	`;

	const values = [ payload ];

	await client.query(text, values);
	client.release();
	return;
}

module.exports = accept;
