mirror of
https://github.com/PretendoNetwork/website.git
synced 2026-04-18 06:59:13 -05:00
Added morgan for some route debugging. Removed body-parser since it's built into express now. Made some error returns more clear and modern-ized some random snippets
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
/*
|
|
|
|
progress.js -
|
|
file for handling routes regarding progress
|
|
|
|
*/
|
|
|
|
// imports
|
|
const router = require('express').Router();
|
|
const apiHelper = require('../helpers/api');
|
|
const utilHelper = require('../helpers/util');
|
|
const progressListModel = require('../models/progress-list').progressListModel;
|
|
|
|
// display progress
|
|
router.get('/progress', (request, response) => {
|
|
|
|
progressListModel.find({}, (error, progress) => {
|
|
if (error) {
|
|
return utilHelper.send404(response);
|
|
}
|
|
|
|
// filtering games and backend
|
|
const games = progress.filter(i => i.isGame);
|
|
const backends = progress.filter(i => !i.isGame);
|
|
|
|
return response.render('progress', {
|
|
title: 'Pretendo | Progress',
|
|
games,
|
|
backends,
|
|
user: utilHelper.templateReadyUser(request),
|
|
locale: utilHelper.getLocale('US', 'en'),
|
|
page: 'progress'
|
|
});
|
|
});
|
|
});
|
|
|
|
/*
|
|
* /api/v1/listprogress
|
|
*
|
|
* gets a list of progress
|
|
*
|
|
* return {
|
|
* code: http code
|
|
* success: boolean - true if progress succesfull
|
|
* progressList: Objects[{_id, title, description, state}] - list of progress with information
|
|
* errors: Strings[messages]
|
|
* }
|
|
*/
|
|
router.get('/api/v1/listprogress', (request, response) => {
|
|
progressListModel.find({}, (error, progress) => {
|
|
// TODO format exception so it doesnt have a huge list of errors
|
|
if (error) {
|
|
return apiHelper.sendApiError(response, 500, [error]);
|
|
}
|
|
|
|
apiHelper.sendReturn(response, {
|
|
progressList: progress
|
|
});
|
|
});
|
|
});
|
|
|
|
// export router
|
|
module.exports = router;
|