<commit_before>
var auth 				= require('./auth'),
    search 				= require('../controllers/search'),
	users 				= require('../controllers/users'),
	datasets  			= require('../controllers/datasets'),
	commodities 		= require('../controllers/commodities'),
	concessions 		= require('../controllers/concessions'),
	companies 			= require('../controllers/companies'),
	projects 			= require('../controllers/projects'),
	transfers 			= require('../controllers/transfers'),
	contracts 			= require('../controllers/contracts'),
	companyGroups 		= require('../controllers/companyGroups'),
	countries 			= require('../controllers/countries'),
	sources 			= require('../controllers/sources'),
	sites 				= require('../controllers/sites'),
	project_tables 		= require('../controllers/project_tables'),
	concession_tables 	= require('../controllers/concession_tables'),
	contract_tables 	= require('../controllers/contract_tables'),
	source_tables 		= require('../controllers/source_tables'),
	production_tables 	= require('../controllers/production_tables'),
	transfer_tables 	= require('../controllers/transfer_tables'),
	site_tables 		= require('../controllers/site_tables'),
	company_tables 		= require('../controllers/company_tables'),
	map 				= require('../controllers/map'),
	sourceTypes 		= require('../controllers/sourceTypes'),
	summaryStats 		= require('../controllers/summaryStats'),
	lastAdded 			= require('../controllers/lastAdded'),
	sunburst 			= require('../controllers/sunburst'),
	content 			= require('../controllers/content'),
	cors 				= require('cors');
	//etl         = require('../controllers/etl');
	// answers 	= require('../controllers/answers'),
	// questions 	= require('../controllers/questions'),
	// assessments = require('../controllers/assessments');
	// mongoose 	= require('mongoose');
	// User 		= mongoose.model('User');

module.exports	= function(app) {
	app.use(function(req, res, next) {
		res.header("Access-Control-Allow-Origin", "*");
		res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
		next();
	});
	app.get('/api/search', search.searchText);

	//CONTRACTS
	app.get('/api/contracts/:limit/:skip', contracts.getContracts);
	app.get('/api/contracts/:id', contracts.getContractByID);


	/////////////////////////
	/// CONCESSIONS CRUD ///
	////////////////////////
	app.get('/api/concessions/:limit/:skip', concessions.getConcessions);
	app.get('/api/concessions/:id', concessions.getConcessionByID);
	// POST
	app.post('/api/concessions',auth.requiresApiLogin, auth.requiresRole('admin'),  concessions.createConcession);
	// PUT
	app.put('/api/concessions', auth.requiresApiLogin, auth.requiresRole('admin'), concessions.updateConcession);
	// DELETE
	app.delete('/api/concessions/:id',auth.requiresApiLogin, auth.requiresRole('admin'), concessions.deleteConcession);

	/////////////////////
	/// PROJECTS CRUD ///
	/////////////////////
	app.get('/api/projects/:limit/:skip', projects.getProjects);
	app.get('/api/projects/:id', projects.getProjectByID);
	app.get('/api/projects/', projects.getProjectsMap);
	app.get('/api/projects/:iso2/:limit/:skip', projects.getProjectsWithIso);
	app.get('/api/projects/:limit/:skip', projects.getProjects);
	// POST
	app.post('/api/projects',auth.requiresApiLogin, auth.requiresRole('admin'),  projects.createProject);
	// PUT
	app.put('/api/projects', auth.requiresApiLogin, auth.requiresRole('admin'), projects.updateProject);
	// DELETE
	app.delete('/api/projects/:id',  auth.requiresApiLogin, auth.requiresRole('admin'), projects.deleteProject);

	/////////////////////////////
	///// TRANSFERS CRUD ////////
	/////////////////////////////
	app.get('/api/transfers/:limit/:skip', transfers.getTransfers);
	// app.get('/api/transfers/:id', transfers.getPaymentByID);
	// // POST
	// app.post('/api/transfers',auth.requiresApiLogin, auth.requiresRole('admin'),  transfers.createProject);
	// // PUT
	// app.put('/api/transfers', auth.requiresApiLogin, auth.requiresRole('admin'), transfers.updateProject);
	// // DELETE
	// app.delete('/api/transfers/:id',  auth.requiresApiLogin, auth.requiresRole('admin'), transfers.deleteProject);

	//////////////////////
	/// COMPANIES CRUD ///
	//////////////////////
	//app.get('/api/companies/:limit/:skip', companies.getCompanies);
	app.get('/api/companies/:limit/:skip', companies.getCompanies);
	app.get('/api/companies/:id', companies.getCompanyID);
	app.get('/api/companydata/:id', companies.getCompanyByID);
	
    // POST
	app.post('/api/companies',auth.requiresApiLogin, auth.requiresRole('admin'),  companies.createCompany);
	// PUT
	app.put('/api/companies', auth.requiresApiLogin, auth.requiresRole('admin'), companies.updateCompany);
	// DELETE
	app.delete('/api/companies/:id',auth.requiresApiLogin, auth.requiresRole('admin'), companies.deleteCompany);

	//////////////////////////
	/// COMPANYGROUPS CRUD ///
	//////////////////////////
	app.get('/api/companyGroups/:limit/:skip', companyGroups.getCompanyGroups);
	app.get('/api/companyGroups/:id', companyGroups.getCompanyGroupID);
	app.get('/api/companyGroupData/:id', companyGroups.getCompanyGroupByID);
	// POST
	app.post('/api/companyGroups',auth.requiresApiLogin, auth.requiresRole('admin'),  companyGroups.createCompanyGroup);
	// PUT
	app.put('/api/companyGroups', auth.requiresApiLogin, auth.requiresRole('admin'), companyGroups.updateCompanyGroup);
	// DELETE
	app.delete('/api/companyGroups/:id',auth.requiresApiLogin, auth.requiresRole('admin'), companyGroups.deleteCompanyGroup);

	///////////////////
	/// COMMODITIES ///
	///////////////////
	app.get('/api/commodities/:limit/:skip', commodities.getCommodities);
	app.get('/api/commodities/:id', commodities.getCommodityByID);
	// POST
	app.post('/api/commodities', auth.requiresApiLogin, auth.requiresRole('admin'), commodities.createCommodity);
	// PUT
	app.put('/api/commodities',  auth.requiresApiLogin, auth.requiresRole('admin'),commodities.updateCommodity);
	// DELETE
	app.delete('/api/commodities/:id', auth.requiresApiLogin, auth.requiresRole('admin'),commodities.deleteCommodity);

	//////////////////////
	/// COUNTRIES CRUD ///
	//////////////////////
	app.get('/api/countries/:limit/:skip', countries.getCountries);
	app.get('/api/countries/:id', countries.getCountryByID);
	app.get('/api/countrycommodity/:id', countries.getAllCommodityCountryByID);
	// POST
	app.post('/api/countries', auth.requiresApiLogin, auth.requiresRole('admin'), countries.createCountry);
	// PUT
	app.put('/api/countries', auth.requiresApiLogin, auth.requiresRole('admin'), countries.updateCountry);
	// DELETE
	app.delete('/api/countries/:id', auth.requiresApiLogin, auth.requiresRole('admin'), countries.deleteCountry);

	////////////////////
	/// SOURCES CRUD ///
	////////////////////
	app.get('/api/sources/:limit/:skip', sources.getSources);
	app.get('/api/sources/:id', sources.getSourceByID);

	// POST
	app.post('/api/sources', auth.requiresApiLogin, auth.requiresRole('admin'), sources.createSource);
	// PUT
	app.put('/api/sources', auth.requiresApiLogin, auth.requiresRole('admin'), sources.updateSource);
	// DELETE
	app.delete('/api/sources/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sources.deleteSource);

	/////////////////////////
	/// SOURCE TYPES CRUD ///
	/////////////////////////
	app.get('/api/sourcetypes/:limit/:skip', sourceTypes.getSourceTypes);
	app.get('/api/sourcetypes/:id', sourceTypes.getSourceTypeByID);

	// POST
	app.post('/api/sourcetypes', auth.requiresApiLogin, auth.requiresRole('admin'),  sourceTypes.createSourceType);
	// PUT
	app.put('/api/sourcetypes', auth.requiresApiLogin, auth.requiresRole('admin'), sourceTypes.updateSourceType);
	// DELETE
	app.delete('/api/sourcetypes/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sourceTypes.deleteSourceType);


	//////////////////
	/// SITES CRUD ///
	//////////////////
	app.get('/api/sites/:limit/:skip/:field', sites.getSites);
	app.get('/api/sites/:id', sites.getSiteByID);
	app.get('/api/sites/map/:field', sites.getSitesMap);
	// POST
	app.post('/api/sites',auth.requiresApiLogin, auth.requiresRole('admin'),  sites.createSite);
	// PUT
	app.put('/api/sites',auth.requiresApiLogin, auth.requiresRole('admin'),  sites.updateSite);
	// DELETE
	app.delete('/api/sites/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sites.deleteSite);



	//DATASETS - TODO: protect with admin?
	app.get('/api/datasets', datasets.getDatasets);
	app.get('/api/datasets/:limit/:skip', datasets.getDatasets);
	app.get('/api/datasets/:id', datasets.getDatasetByID);

	//Reporting
	app.get('/admin/etl/datasets/:dataset_id/actions/:action_id/report',
		datasets.getActionReport,
		function(req, res) {
		    res.render('actionreport', {report: req.report});
	});

	//Create a dataset - todo protect with admin<commit_msg>SAVEPOINT<commit_after>
var auth 				= require('./auth'),
    search 				= require('../controllers/search'),
	users 				= require('../controllers/users'),
	datasets  			= require('../controllers/datasets'),
	commodities 		= require('../controllers/commodities'),
	concessions 		= require('../controllers/concessions'),
	companies 			= require('../controllers/companies'),
	projects 			= require('../controllers/projects'),
	transfers 			= require('../controllers/transfers'),
	contracts 			= require('../controllers/contracts'),
	companyGroups 		= require('../controllers/companyGroups'),
	countries 			= require('../controllers/countries'),
	sources 			= require('../controllers/sources'),
	sites 				= require('../controllers/sites'),
	project_tables 		= require('../controllers/project_tables'),
	concession_tables 	= require('../controllers/concession_tables'),
	contract_tables 	= require('../controllers/contract_tables'),
	source_tables 		= require('../controllers/source_tables'),
	production_tables 	= require('../controllers/production_tables'),
	transfer_tables 	= require('../controllers/transfer_tables'),
	site_tables 		= require('../controllers/site_tables'),
	company_tables 		= require('../controllers/company_tables'),
	map 				= require('../controllers/map'),
	sourceTypes 		= require('../controllers/sourceTypes'),
	summaryStats 		= require('../controllers/summaryStats'),
	lastAdded 			= require('../controllers/lastAdded'),
	sunburst 			= require('../controllers/sunburst'),
	content 			= require('../controllers/content'),
	cors 				= require('cors');
	//etl         = require('../controllers/etl');
	// answers 	= require('../controllers/answers'),
	// questions 	= require('../controllers/questions'),
	// assessments = require('../controllers/assessments');
	// mongoose 	= require('mongoose');
	// User 		= mongoose.model('User');

module.exports	= function(app) {
	app.use(function(req, res, next) {
		res.header("Access-Control-Allow-Origin", "*");
		res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
		next();
	});
	app.get('/api/search', search.searchText);

	//CONTRACTS
	app.get('/api/contracts/:limit/:skip', contracts.getContracts);
	app.get('/api/contracts/:id', contracts.getContractByID);


	/////////////////////////
	/// CONCESSIONS CRUD ///
	////////////////////////
	app.get('/api/concessions/:limit/:skip', concessions.getConcessions);
	app.get('/api/concessions/:id', concessions.getConcessionByID);
	// POST
	app.post('/api/concessions',auth.requiresApiLogin, auth.requiresRole('admin'),  concessions.createConcession);
	// PUT
	app.put('/api/concessions', auth.requiresApiLogin, auth.requiresRole('admin'), concessions.updateConcession);
	// DELETE
	app.delete('/api/concessions/:id',auth.requiresApiLogin, auth.requiresRole('admin'), concessions.deleteConcession);

	/////////////////////
	/// PROJECTS CRUD ///
	/////////////////////
	app.get('/api/projects/:limit/:skip', projects.getProjects);
	app.get('/api/projects/:id', projects.getProjectByID);
	app.get('/api/projects/', projects.getProjectsMap);
	app.get('/api/projects/:iso2/:limit/:skip', projects.getProjectsWithIso);
	app.get('/api/projects/:limit/:skip', projects.getProjects);
	// POST
	app.post('/api/projects',auth.requiresApiLogin, auth.requiresRole('admin'),  projects.createProject);
	// PUT
	app.put('/api/projects', auth.requiresApiLogin, auth.requiresRole('admin'), projects.updateProject);
	// DELETE
	app.delete('/api/projects/:id',  auth.requiresApiLogin, auth.requiresRole('admin'), projects.deleteProject);

	/////////////////////////////
	///// TRANSFERS CRUD ////////
	/////////////////////////////
	app.get('/api/transfers/:limit/:skip', transfers.getTransfers);
	// app.get('/api/transfers/:id', transfers.getPaymentByID);
	// // POST
	// app.post('/api/transfers',auth.requiresApiLogin, auth.requiresRole('admin'),  transfers.createProject);
	// // PUT
	// app.put('/api/transfers', auth.requiresApiLogin, auth.requiresRole('admin'), transfers.updateProject);
	// // DELETE
	// app.delete('/api/transfers/:id',  auth.requiresApiLogin, auth.requiresRole('admin'), transfers.deleteProject);

	//////////////////////
	/// COMPANIES CRUD ///
	//////////////////////
	//app.get('/api/companies/:limit/:skip', companies.getCompanies);
	app.get('/api/companies/:limit/:skip', companies.getCompanies);
	app.get('/api/companies/:id', companies.getCompanyID);
	app.get('/api/companydata/:id', companies.getCompanyByID);
	
    // POST
	app.post('/api/companies',auth.requiresApiLogin, auth.requiresRole('admin'),  companies.createCompany);
	// PUT
	app.put('/api/companies', auth.requiresApiLogin, auth.requiresRole('admin'), companies.updateCompany);
	// DELETE
	app.delete('/api/companies/:id',auth.requiresApiLogin, auth.requiresRole('admin'), companies.deleteCompany);

	//////////////////////////
	/// COMPANYGROUPS CRUD ///
	//////////////////////////
	app.get('/api/companyGroups/:limit/:skip', companyGroups.getCompanyGroups);
	app.get('/api/companyGroups/:id', companyGroups.getCompanyGroupID);
	app.get('/api/companyGroupData/:id', companyGroups.getCompanyGroupByID);
	// POST
	app.post('/api/companyGroups',auth.requiresApiLogin, auth.requiresRole('admin'),  companyGroups.createCompanyGroup);
	// PUT
	app.put('/api/companyGroups', auth.requiresApiLogin, auth.requiresRole('admin'), companyGroups.updateCompanyGroup);
	// DELETE
	app.delete('/api/companyGroups/:id',auth.requiresApiLogin, auth.requiresRole('admin'), companyGroups.deleteCompanyGroup);

	///////////////////
	/// COMMODITIES ///
	///////////////////
	app.get('/api/commodities/:limit/:skip', commodities.getCommodities);
	app.get('/api/commodities/:id', commodities.getCommodityByID);
	// POST
	app.post('/api/commodities', auth.requiresApiLogin, auth.requiresRole('admin'), commodities.createCommodity);
	// PUT
	app.put('/api/commodities',  auth.requiresApiLogin, auth.requiresRole('admin'),commodities.updateCommodity);
	// DELETE
	app.delete('/api/commodities/:id', auth.requiresApiLogin, auth.requiresRole('admin'),commodities.deleteCommodity);

	//////////////////////
	/// COUNTRIES CRUD ///
	//////////////////////
	app.get('/api/countries/:limit/:skip', countries.getCountries);
	app.get('/api/countries/:id', countries.getCountryByID);
	app.get('/api/countrycommodity/:id', countries.getAllCommodityCountryByID);
	// POST
	app.post('/api/countries', auth.requiresApiLogin, auth.requiresRole('admin'), countries.createCountry);
	// PUT
	app.put('/api/countries', auth.requiresApiLogin, auth.requiresRole('admin'), countries.updateCountry);
	// DELETE
	app.delete('/api/countries/:id', auth.requiresApiLogin, auth.requiresRole('admin'), countries.deleteCountry);

	////////////////////
	/// SOURCES CRUD ///
	////////////////////
	app.get('/api/sources/:limit/:skip', sources.getSources);
	app.get('/api/sources/:id', sources.getSourceByID);

	// POST
	app.post('/api/sources', auth.requiresApiLogin, auth.requiresRole('admin'), sources.createSource);
	// PUT
	app.put('/api/sources', auth.requiresApiLogin, auth.requiresRole('admin'), sources.updateSource);
	// DELETE
	app.delete('/api/sources/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sources.deleteSource);

	/////////////////////////
	/// SOURCE TYPES CRUD ///
	/////////////////////////
	app.get('/api/sourcetypes/:limit/:skip', sourceTypes.getSourceTypes);
	app.get('/api/sourcetypes/:id', sourceTypes.getSourceTypeByID);

	// POST
	app.post('/api/sourcetypes', auth.requiresApiLogin, auth.requiresRole('admin'),  sourceTypes.createSourceType);
	// PUT
	app.put('/api/sourcetypes', auth.requiresApiLogin, auth.requiresRole('admin'), sourceTypes.updateSourceType);
	// DELETE
	app.delete('/api/sourcetypes/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sourceTypes.deleteSourceType);


	//////////////////
	/// SITES CRUD ///
	//////////////////
	app.get('/api/sites/:limit/:skip/:field', sites.getSites);
	app.get('/api/sites/:id', sites.getSiteByID);
	app.get('/api/sites/map/:field', sites.getSitesMap);
	// POST
	app.post('/api/sites',auth.requiresApiLogin, auth.requiresRole('admin'),  sites.createSite);
	// PUT
	app.put('/api/sites',auth.requiresApiLogin, auth.requiresRole('admin'),  sites.updateSite);
	// DELETE
	app.delete('/api/sites/:id', auth.requiresApiLogin, auth.requiresRole('admin'), sites.deleteSite);

	//DATASETS - TODO: protect with admin?
	app.get('/api/datasets', datasets.getDatasets);
	app.get('/api/datasets/:limit/:skip', datasets.getDatasets);
	app.get('/api/datasets/:id', datasets.getDatasetByID);

	//Reporting
	app.get('/admin/etl/datasets/:dataset_id/actions/:action_id/report',
		datasets.getActionReport,
		function(req, res) {
		    res.render('actionreport', {report: req.report});
	});

	//Create a dataset - todo protect with admin
{'fraction_non_alphanumeric': 0.23177379059732, 'fraction_numerical': 0.00011355893708834885, 'mean_word_length': 3.604705882352941, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '886504', 'n_tokens_mistral': 5765, 'n_tokens_neox': 5544, 'n_words': 661}