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

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

	try {
		const json = await sequence.get(req.params.project, req.params.sequence, req.query);
		const geometry = req.query.geometry || "geometrypreplot";

		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);
	}


};
