From 8a520a5cfed7b475a17f0f824ab8f3a4ee31ebee Mon Sep 17 00:00:00 2001
From: Kim Siwon <shmd01@ajou.ac.kr>
Date: Fri, 6 Dec 2019 15:38:34 +0900
Subject: [PATCH] Remove unnecessary Voucher Attributes

---
 models/voucher.js | 30 ------------------------------
 routes/voucher.js | 32 ++++++--------------------------
 2 files changed, 6 insertions(+), 56 deletions(-)

diff --git a/models/voucher.js b/models/voucher.js
index 53119c8..dbdc433 100644
--- a/models/voucher.js
+++ b/models/voucher.js
@@ -8,36 +8,6 @@ module.exports = (sequelize, DataTypes) => {
         min: 0,
       },
     },
-    waitDays: {
-      type: DataTypes.INTEGER,
-      allowNull: true,
-      validate: {
-        isInt: true,
-        min: 0,
-      },
-    },
-    activeDays: {
-      type: DataTypes.INTEGER,
-      allowNull: true,
-      validate: {
-        isInt: true,
-        min: 1,
-      },
-    },
-    openAt: {
-      type: DataTypes.DATE,
-      allowNull: true,
-      validate: {
-        isDate: true,
-      },
-    },
-    closeAt: {
-      type: DataTypes.DATE,
-      allowNull: true,
-      validate: {
-        isDate: true,
-      },
-    },
   }, {
     underscored: true,
     timestamps: true,
diff --git a/routes/voucher.js b/routes/voucher.js
index f517b93..772be44 100644
--- a/routes/voucher.js
+++ b/routes/voucher.js
@@ -10,10 +10,6 @@ const { Voucher } = db;
   {
     "programId" : 1,
     "quantity" : 20,
-    "waitDays" : 0,
-    "activeDays" : null,
-    "openAt": "2019-12-01",
-    "closeAt": "2020-12-01"
   }
 */
 /* �⑤뜡�� voucher瑜� �낅젰�⑸땲��. */
@@ -30,10 +26,6 @@ router.get('/addrandom', (req, res) => {
     Voucher.create({
       programId: (seed % programId) + 1,
       quantity: (seed % 200),
-      waitDays: (seed % 20 < 14 ? seed % 20 : null),
-      activeDays: (seed % 200 < 180 ? (seed % 200) + 1 : null),
-      openAt: new Date((new Date(2019, 10, 1)).getTime() + 400000 * seed),
-      closeAt: new Date((new Date(2020, 5, 1)).getTime() + 1000000 * seed),
     }).then((result) => {
       res.json({ status: 'success', result });
     }).catch((err) => {
@@ -46,7 +38,7 @@ router.get('/addrandom', (req, res) => {
 // eslint-disable-next-line consistent-return
 router.get('/', (req, res) => {
   const queryOption = {
-    attributes: ['id', 'programId', 'quantity', 'waitDays', 'activeDays', 'openAt', 'closeAt', 'createdAt', 'updatedAt'],
+    attributes: ['id', 'programId', 'quantity', 'createdAt', 'updatedAt'],
   };
   Voucher.findAll(queryOption)
     .then((vouchers) => {
@@ -86,11 +78,6 @@ router.post('/', (req, res, next) => {
   const queryValue = {
     quantity: req.body.quantity,
     programId: req.body.programId,
-    waitDays: req.body.waitDays,
-    activeDays: req.body.activeDays,
-    openAt: req.body.openAt,
-    closeAt: req.body.closeAt,
-    programID: req.body.programId,
   };
   Voucher.create(queryValue)
     .then((voucher) => {
@@ -127,7 +114,7 @@ router.get('/:id', (req, res, next) => {
   }
 
   const queryOption = {
-    attributes: ['id', 'programId', 'quantity', 'waitDays', 'activeDays', 'openAt', 'closeAt', 'createdAt', 'updatedAt'],
+    attributes: ['id', 'programId', 'quantity', 'createdAt', 'updatedAt'],
   };
   Voucher.findByPk(req.params.id, queryOption)
     .then((voucher) => {
@@ -161,7 +148,7 @@ router.get('/:id', (req, res, next) => {
 /* Put Update voucher by ID */
 router.put('/:id', (req, res, next) => {
   const queryOption = {
-    attributes: ['id', 'programId', 'quantity', 'waitDays', 'activeDays', 'openAt', 'closeAt', 'createdAt', 'updatedAt'],
+    attributes: ['id', 'programId', 'quantity', 'createdAt', 'updatedAt'],
   };
   Voucher.findByPk(req.params.id, queryOption)
     .then((voucher) => {
@@ -172,18 +159,11 @@ router.put('/:id', (req, res, next) => {
 
         return next();
       }
-      // eslint-disable-next-line no-param-reassign
-      if ('quantity' in req.body) voucher.quantity = req.body.quantity;
-      // eslint-disable-next-line no-param-reassign
-      if ('waitDays' in req.body) voucher.waitDays = req.body.waitDays;
-      // eslint-disable-next-line no-param-reassign
-      if ('activeDays' in req.body) voucher.activeDays = req.body.activeDays;
-      // eslint-disable-next-line no-param-reassign
-      if ('openAt' in req.body) voucher.openAt = req.body.openAt;
-      // eslint-disable-next-line no-param-reassign
-      if ('closeAt' in req.body) voucher.closeAt = req.body.closeAt;
+
       // eslint-disable-next-line no-param-reassign
       if ('programId' in req.body) voucher.programId = req.body.programId;
+      // eslint-disable-next-line no-param-reassign
+      if ('quantity' in req.body) voucher.quantity = req.body.quantity;
 
       return voucher.save();
     })
-- 
GitLab