Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
1.2 kB
2
Indexable
Never
app.get('/api/sdh/de-tai/page/:pageNumber/:pageSize', app.permission.check('sdhDeTai:read'), async (req, res) => {
    try {
      const { pageNumber, pageSize } = req.params;
      let { filter } = req.query || {};
      filter = filter || {};

      const { rows: list, pagenumber, pagesize, pagetotal, totalitem, newestsoquyetdinh } = await app.model.sdhDeTai.searchPage(Number(pageNumber), Number(pageSize), app.utils.stringify(filter));
      list.forEach(item => {
        if (item.canBo !== '[{"MSCB":null,"vaiTro":null,"hoTenCanBo":null,"from":null}]') {
          console.log(item.canBo);
          try {
            let cleanedString = item.canBo
              .replace(/\\"/g, '"')
              .replace(/""/g, '"');

            item.canBo = JSON.parse(cleanedString);
          } catch (err) {
            item.canBo = [];
          }
        } else {
          item.canBo = [];
        }
      });

      res.send({ page: { list, pageNumber: pagenumber, pageSize: pagesize, pageTotal: pagetotal, totalItem: totalitem, newestSoQuyetDinh: newestsoquyetdinh } });
    } catch (error) {
      app.consoleError(error);
      res.send({ error });
    }
  });
Leave a Comment