const { ERROR, INFO, DEBUG } = require('DOUGAL_ROOT/debug')(__filename);

const { sequence } = require('../../../../lib/db');

module.exports = async function (req, res, next) {

	try {
		const ts0 = Date.now();
		const json = await sequence.get(req.params.project, null, req.query);
		const geometry = req.query.geometry || "geometrypreplot";
		const δt = Date.now()-ts0;
		DEBUG("Full-project data retrieval completed in %.3f s", δt / 1000);


		const geojson = {
			type: "FeatureCollection",
			features: json.map(feature => {
				return {
					type: "Feature",
					geometry: feature[geometry],
					properties: {...feature}
				}
			})
		};

		res.status(200).send(geojson);
		next();
	} catch (err) {
		next(err);
	}


};
