我如何将这些查询更改为常规序列化格式

时间:2019-09-08 05:45:48

标签: node.js postgresql sequelize.js

作为管理人员,我想查询数据库以获取状态为我所有直接报告为打开的请求

这是我的逻辑

  `static async getOpenRequest({ user: { id } }) {
const strQuery = 
SELECT A.source, A.destination, A.travelDate, A.returnDate, A.status, A.tripType, A.reason, A.accommodation, B.firstName, B.lastName 
FROM Requests A 
INNER JOIN Users B ON B.id = A.userId 
INNER JOIN UserDepartments C ON C.userId = B.Id 
INNER JOIN Departments D ON D.id = C.departmentId 
WHERE A.status='open' AND D.manager=:id";

    const openRequests = sequelize.query(strQuery, {
      replacements: { id },
      type: sequelize.QueryTypes.SELECT
    });

    if (openRequests.length < 1) error('There are no pending requests');

    return openRequests;
  }`

这可行,但是我想以常规的续集格式

0 个答案:

没有答案