H
H
hollanditkzn2017-11-14 15:48:40
Node.js
hollanditkzn, 2017-11-14 15:48:40

How to output your formats and your data from mongoose?

I don’t understand how to display data that is stored in the database in a different form, let’s say the time is displayed differently than Thu Nov 23 2017 12:00:00 GMT+0300 (Moscow time (winter)) was displayed, but it was displayed on November 23, 2017 12:00. And some data, the status is
0 => New
1 => In progress
2 => Completed
well, etc.
I didn’t understand how to display it in the model, I did it in the router. I know it's wrong, but where to go
Tried like this

let express = require('express'),
  Order = require('../models/order'),
    moment = require('moment'),
  router = express.Router();


/* GET users listing. */
router.get('/', (req, res) => {
  Order.find()
        .then(orders => {
            orders = orders.map((order) => {
                order.time = moment(order.time).format('DD MMMM YYYY hh:mm:ss');
                return order;
            });
            console.log(orders);
            res.render('user', {
                username: req.user.username,
                title: 'Главная страница',
                order: orders
            });
        })
        .catch(err => console.log(err));
});

And I use pug
mixin gridView()
    each val in order
        tr
          td=val.orderId
          td=val.time
          td=val.description
          td=val.tag
          td=val.shipping
          td=val.juid
          td=val.status

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question