Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ot 63 add slides to public endpoint #88

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions controllers/organization.js
Original file line number Diff line number Diff line change
@@ -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 });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: en vez de response usaría el nombre organization.

} catch (error) {
return error;
}
Expand Down
12 changes: 12 additions & 0 deletions dao/slide.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ class SlidesDap {
throw new Error(error);
}
}
static async findSlidebyOrganization({ where, exclude = [], order = [] }) {
try {
const SlideData = await Slide.findAll({
where: where,
attributes: { exclude: exclude },
order: [order],
});
return SlideData;
} catch (error) {
throw new Error(error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Se pueden agregar excepciones custom para estos casos.

}
}
static async getSlides(attributes) {
try {
const slidesList = await Slide.findAll({
Expand Down