js 外部获取then里面的值

作者: adm 分类: node 发布时间: 2022-08-11

service

async getOrderList(where) {
    
    return new Promise((resolve, reject)=>{

      CargoOrderCommonModel.findAndCountAll({

        //offset,
        //limit: parseInt(req.query.limit) || 20,
        include: [
          {
            model: CargoOrderModel,
            attributes: ['cupboard', 'cupboard_num', 'pkg', 'kgs']
          }
        ],
        where: where,
        order: [['create_time', 'DESC']]
      }).then(function (result) {
        resolve(result.rows); 
       
        
      }).catch(err => {
        reject(err);
      })
   });

controller

async getOrderList(req, res) {
        let where = {}

        if (req.body.pick_up_time_begin && req.body.pick_up_time_end) {
            where = {
                pick_up_time: {
                    [Op.between]: [req.body.pick_up_time_begin, req.body.pick_up_time_end]
                },
                is_delete: 0
            }
        }
        const resp = await orderService.getOrderList(where) 
       

        res.send({
            code: 200,
            msg: "请求数据成功",
            data: resp
        })



    }

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!