From 8221988b5d7337ce79d87070bc3a3c6a9a7eec4e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2022 11:39:50 -0300 Subject: [PATCH 1/3] create findSlidebyOrganization function --- dao/slide.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dao/slide.js b/dao/slide.js index 0b14dba..9b08bf4 100644 --- a/dao/slide.js +++ b/dao/slide.js @@ -19,6 +19,19 @@ class SlidesDap { throw new Error(error); } } + static async findSlidebyOrganization({ where, exclude = [], order = [] }) { + try { + console.log(where) + const SlideData = await Slide.findAll({ + where: where, + attributes: { exclude: exclude }, + order: [order] + }); + return SlideData; + } catch (error) { + throw new Error(error); + } + } } module.exports = SlidesDap; From b27fdd7e39d90053881cabd510a0462925fa22cc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2022 11:40:14 -0300 Subject: [PATCH 2/3] add slides to organization controller --- controllers/organization.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/organization.js b/controllers/organization.js index 7a24673..39ed2f4 100644 --- a/controllers/organization.js +++ b/controllers/organization.js @@ -1,15 +1,21 @@ const { Organization } = require('../models/'); +const SlidesDao = require('../dao/slide'); class OrganizationController { static async findOrganization(req, res) { try { const response = await Organization.findOne({ where: { name: 'Big Org' }, - attributes: ['name', 'image', 'phone', 'address'], + attributes: ['id', 'name', 'image', 'phone', 'address'], + }); + const slides = await SlidesDao.findSlidebyOrganization({ + where: { organizationId: response.id }, + exclude: ['createdAt', 'updatedAt', 'deletedAt'], + order: ['order', 'ASC'], }); response === null ? res.status(404).json({ msg: 'Could not find information' }) - : res.status(200).json(response); + : res.status(200).json({ response, slides }); } catch (error) { return error; } From 4a69793f391ea878ddadf586f4827b32f47a627a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 29 Sep 2022 13:22:05 -0300 Subject: [PATCH 3/3] remove console.log --- dao/slide.js | 1 - 1 file changed, 1 deletion(-) diff --git a/dao/slide.js b/dao/slide.js index 9b08bf4..5cada32 100644 --- a/dao/slide.js +++ b/dao/slide.js @@ -21,7 +21,6 @@ class SlidesDap { } static async findSlidebyOrganization({ where, exclude = [], order = [] }) { try { - console.log(where) const SlideData = await Slide.findAll({ where: where, attributes: { exclude: exclude },