123456789101112131415161718192021222324252627282930313233343536 |
- const router = require('express').Router()
- const moment = require('moment')
- const SHIPMENT = {
- normal: {
- price: 13.98,
- days: 7
- },
- fast: {
- price: 49.98,
- days: 3
- }
- }
- function shipmentPrice (shipmentOption) {
- let estimated = moment().add(shipmentOption.days, 'd').format('dddd MMMM Do')
- return {
- estimated,
- price: shipmentOption.price
- }
- }
- router.post('/shipment', (req, res) => {
- let shipment;
- if (req.body.shipment === 'normal') {
- shipment = shipmentPrice(SHIPMENT.normal)
- } else {
- shipment = shipmentPrice(SHIPMENT.fast)
- }
- res.json({
- success: true,
- shipment
- })
- })
- module.exports = router
|