Skip to content

Commit

Permalink
Merge pull request #23 from MengChiehLiu/develop
Browse files Browse the repository at this point in the history
Version 1.0.13
  • Loading branch information
MengChiehLiu authored Aug 23, 2023
2 parents 4e6f4b7 + 735a806 commit 8f6c8c8
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 56 deletions.
File renamed without changes.
34 changes: 29 additions & 5 deletions backend/server/controllers/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const router = require('express').Router();
const {checkAuthorization, checkDateFormat} = require('../utils/checkRequest');

// import models
const {getFS} = require('../models/fs');
const {getBS, getIS} = require('../models/fs');

async function routerGet(req, res){
async function routerGetBS(req, res){
try{
const user_id = req.user.id;
let date = req.query.timestamp
Expand All @@ -19,8 +19,31 @@ async function routerGet(req, res){
if (new Date(date) > new Date()) return res.status(400).json({error: 'Future Request Is Not Allowed'})
}

const fs = await getFS(user_id, date)
return res.json({data: {subjects: fs}});
const BS = await getBS(user_id, date)
return res.json({data: {subjects: BS}});

}catch(err){
console.error(err);
return res.status(500).json({error: 'Internal Server Error'});
};
};


async function routerGetIS(req, res){
try{
const user_id = req.user.id;
let date = req.query.timestamp

if (!date){
const [year, month] = new Date().toLocaleDateString('zh-TW', { timeZone: 'Asia/Taipei' }).split('/')
date = `${year}/${month}/1`
}else{
date = `${date.slice(0, 7)}-01`
if (new Date(date) > new Date()) return res.status(400).json({error: 'Future Request Is Not Allowed'})
}

const IS = await getIS(user_id, date)
return res.json({data: {subjects: IS}});

}catch(err){
console.error(err);
Expand All @@ -29,5 +52,6 @@ async function routerGet(req, res){
};

// router
router.get( '/', checkAuthorization, checkDateFormat(), routerGet);
router.get( '/bs', checkAuthorization, checkDateFormat(), routerGetBS);
router.get( '/is', checkAuthorization, checkDateFormat(), routerGetIS);
module.exports = router;
14 changes: 7 additions & 7 deletions backend/server/views/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ router.get('/api/1.0', function(req, res){res.send('Hello World!');})
router.use('/api/1.0/docs', require('./swagger.js'));

// routers
router.use('/api/1.0/data', require('./data.js'));
router.use('/api/1.0/entries', require('./entries.js'));
router.use('/api/1.0/registers', require('./registers.js'));
router.use('/api/1.0/fs', require('./fs.js'));
router.use('/api/1.0/stats', require('./stats.js'));
router.use('/api/1.0/goals', require('./goals.js'));
router.use('/api/1.0/users', require('./users.js'));
router.use('/api/1.0/data', require('../controllers/data.js'));
router.use('/api/1.0/entries', require('../controllers/entries.js'));
router.use('/api/1.0/registers', require('../controllers/registers.js'));
router.use('/api/1.0/fs', require('../controllers/fs.js'));
router.use('/api/1.0/stats', require('../controllers/stats.js'));
router.use('/api/1.0/goals', require('../controllers/goals.js'));
router.use('/api/1.0/users', require('../controllers/users.js'));


module.exports = router;
5 changes: 0 additions & 5 deletions backend/server/views/data.js

This file was deleted.

5 changes: 0 additions & 5 deletions backend/server/views/entries.js

This file was deleted.

5 changes: 0 additions & 5 deletions backend/server/views/fs.js

This file was deleted.

7 changes: 0 additions & 7 deletions backend/server/views/goals.js

This file was deleted.

6 changes: 0 additions & 6 deletions backend/server/views/incomeStatement.js

This file was deleted.

5 changes: 0 additions & 5 deletions backend/server/views/registers.js

This file was deleted.

5 changes: 0 additions & 5 deletions backend/server/views/stats.js

This file was deleted.

6 changes: 0 additions & 6 deletions backend/server/views/users.js

This file was deleted.

0 comments on commit 8f6c8c8

Please sign in to comment.