From 31db52088f49d62af878b37561ad72c28241fd9f Mon Sep 17 00:00:00 2001 From: rehabas Date: Wed, 1 Apr 2020 02:59:06 +0300 Subject: [PATCH] edit get projects route relates #12 --- .../routes/user/project/getProjectsData.js | 19 ++++++++++--------- test/index.test.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/controllers/routes/user/project/getProjectsData.js b/server/controllers/routes/user/project/getProjectsData.js index 4ea79407..486b33d5 100644 --- a/server/controllers/routes/user/project/getProjectsData.js +++ b/server/controllers/routes/user/project/getProjectsData.js @@ -2,15 +2,16 @@ const { getProjects, } = require('../../../../database/queries/project/getProjects'); -const getProjectsData = (req, res, next) => { - getProjects() - .then(({ rows }) => - res.json({ - StatusCode: 200, - data: rows, - }), - ) - .catch((err) => next(err)); +const getProjectsData = async (req, res, next) => { + try { + const { rows } = await getProjects(); + res.json({ + StatusCode: 200, + data: rows, + }); + } catch (err) { + next(err); + } }; module.exports = { diff --git a/test/index.test.js b/test/index.test.js index 637ae897..71111ea5 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -14,8 +14,8 @@ test('Get projects route', (done) => { .expect(200) .expect('Content-Type', /json/) .end(async (err, res) => { - const { data } = res.body; if (err) return done(err); + const { data } = res.body; expect(data).toHaveLength(2); done(); });