Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
만료일을 탄력적으로 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
5d-jh committed Dec 6, 2018
1 parent 88d248d commit f5bc2a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
18 changes: 15 additions & 3 deletions api/responseCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ class ResponseCache {
}

const date = new Date();
NODE_ENV === 'development' ? date.setMinutes(date.getMinutes() + 2) : date.setDate(date.getDate() + 6);

const condition = ((date.getFullYear() < this.menuYear) ||
((date.getMonth()+1 < this.menuMonth)));

if (condition) {
date.setDate(date.getDate() + 1);
} else {
NODE_ENV === 'development'
? date.setMinutes(date.getMinutes() + 2)
: date.setFullYear(date.getFullYear() + 3);
}

return date;
}

Expand Down Expand Up @@ -68,7 +79,6 @@ class ResponseCache {
}

if (schoolMenu.length !== 0) {
console.log(schoolMenu)
return schoolMenu;
} else {
throw new Error('식단을 찾을 수 없습니다. 학교 코드를 다시 확인해 주세요.');
Expand Down Expand Up @@ -108,4 +118,6 @@ class ResponseCache {
}
}

module.exports = ResponseCache;
module.exports = (schoolType, schoolCode, menuYear, menuMonth) => {
return new ResponseCache(schoolType, schoolCode, menuYear, menuMonth);
}
14 changes: 5 additions & 9 deletions api/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const express = require('express');

const router = express.Router();

const ResponseCache = require('./ResponseCache');
const responseCache = require('./responseCache');

const removeAllergyInfo = (month, hideAllergyInfo) => {
let singleDay = false;
Expand Down Expand Up @@ -34,8 +34,7 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => {
const menuYear = Number(req.query.year) || new Date().getFullYear();
const menuMonth = Number(req.query.month) || new Date().getMonth()+1;

const responseCache = new ResponseCache(req.params.schoolType, req.params.schoolCode, menuYear, menuMonth);
responseCache.getCache()
responseCache(req.params.schoolType, req.params.schoolCode, menuYear, menuMonth).getCache()
.then((schoolMenuData) => {
const responseJSON = {
menu: schoolMenuData.schoolMenu,
Expand All @@ -51,17 +50,17 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => {
const remainingHours = Math.floor(remainingTime / (3600000 * (remainingDays+1)));
remainingMessage = `${remainingDays}${remainingHours}시간`;
if ((remainingDays && remainingHours) === 0) {
const remainingMins = Math.floor(remainingTime / 60000);
const remainingMins = Math.floor((remainingTime / 60000) % 60);
const remainingSecs = Math.ceil((remainingTime / 1000) % 60);
remainingMessage += ` ${remainingMins}${remainingSecs}초`;
};
remainingMessage += ` 후 식단이 갱신됩니다.`;
}

const hideAllergyInfo = req.query.hideAllergy === "true" ? true : false;
const date = req.query.date;
const menuDate = Number(req.query.date);

responseJSON.menu = date ? responseJSON.menu[Number(date)-1] : responseJSON.menu;
if (menuDate) responseJSON.menu =responseJSON.menu[menuDate-1];
responseJSON.menu = removeAllergyInfo(responseJSON.menu, hideAllergyInfo);

responseJSON.server_message.push(...require('./serverMessage.json').content);
Expand All @@ -70,9 +69,6 @@ router.get('/:schoolType/:schoolCode', (req, res, next) => {
res.json(responseJSON);
})
.catch(err => next(err));
/*responseCache.getCache(, (schoolMenuCache, err) => {
}); */
});

module.exports.router = router;

0 comments on commit f5bc2a4

Please sign in to comment.