import express from 'express';
import passport from 'passport';

// Route imports
import testRoute from './test.js';
import versionRoute from './version.js';

import user_route from './user.js';
import user_schema from './user_schema.js';

import products_route from './products.js';
import products_schema from './products_schema.js';

// Router base is '/api/v1'
const Router = express.Router({ strict: false });

// All empty strings are undefined (not null!) values (body)
Router.use('*', function (req, res, next) {
	for (let key in req.body) {
		if (req.body[key] === '') {
			req.body[key] = undefined;
		}
	}
	next();
});

// All api routes lowercase! Yea I know but when strict: true it matters.
Router.route('/user').get(user_route.get).post(user_route.post).patch(user_route.patch).delete(user_route.del);
Router.route('/user/describe').get(user_schema);

Router.route('/products').get(products_route.get).post(products_route.post).patch(products_route.patch).delete(products_route.del);
Router.route('/products/describe').get(products_schema);

Router.route('/version').get(versionRoute.get);
Router.route('/test').get(testRoute.get);

export default Router;
