如何在包含模型中获取最新条目数据

时间:2019-01-26 07:34:05

标签: javascript node.js sequelize.js

controller.js

const getUserByCardNum = async function(card){//returns token

if(!card) TE('Please provide the cardnum to get the user Details');
let user ;
[err, user] = await to(User.findOne({
    attributes: {exclude : ['password', 'role','branch']},
    as : 'user',
    where:{cardNum:card}, 
        include:[{
            model:wallet,
            as: 'wallet',
            // where :{cid:id},
            attributes:{exclude: 
 ['deposit','withdrawal','comments','online']},
            order: [ [ 'id', 'DESC' ]],
            required: true,

        }],

        // limit: 50,      
}));
if(err) TE(err.message);
return user;
}
module.exports.getUserByCardNum = getUserByCardNum;

现在我得到的答复是:

{
"user": {
    "id": 2022,
    "name": "coin",
    "email": "dineshgrt@gmail.com",
    "phone": "6516161615",
    "cardId": "65651661",
    "cardNum": "1004000000000077",
    "wallet": {
        "id": 7495,
        "cid": 2022,
        "available": 158496
    }
},
"success": true
}

输出

    but in my wallet table the last data is like this
+------+------+---------+------------+-----------+---------------------+--------+
| ID   | CID  | DEPOSIT | WITHDRAWAL | AVAILABLE | COMMENTS            | ONLINE |
+------+------+---------+------------+-----------+---------------------+--------  |
|  |
| 7495 | 2022 |     156 |       NULL |    158496 | 2019-01-25 07:18:34 | NULL   |
| 7496 | 2022 |     156 |       NULL |    158652 | 2019-01-25 07:23:41 | NULL   |
| 7497 | 2022 |     156 |       NULL |    158808 | 2019-01-25 07:26:32 | NULL   |
| 7498 | 2022 |     156 |       NULL |    158964 | 2019-01-25 07:28:34 | NULL   |
| 7499 | 2022 |     156 |       NULL |    159120 | 2019-01-26 05:23:17 | NULL   |
| 7500 | 2022 |     156 |       NULL |    159276 | 2019-01-26 05:25:15 | NULL   |
| 7501 | 2022 |     156 |       NULL |    159432 | 2019-01-26 05:31:17 | NULL   |
| 7502 | 2022 |     156 |       NULL |    159588 | 2019-01-26 05:36:00 | NULL   |
| 7503 | 2022 |     156 |       NULL |    159744 | 2019-01-26 05:44:09 | NULL   |
| 7504 | 2022 |     156 |       NULL |    159900 | 2019-01-26 06:28:47 | NULL   |
| 7505 | 2022 |     156 |       NULL |    160056 | 2019-01-26 06:35:45 | NULL   |
| 7506 | 2022 |     156 |       NULL |    160212 | 2019-01-26 06:36:42 | NULL   |
+------+------+---------+------------+-----------+---------------------+--------+
121 rows in set (0.00 sec)

0 个答案:

没有答案