proper getting charity by id
This commit is contained in:
@@ -186,8 +186,8 @@ exports.getAllOrganizations = async (req, res, next) => {
|
|||||||
select
|
select
|
||||||
o.*,
|
o.*,
|
||||||
p.id as project_id,
|
p.id as project_id,
|
||||||
p.title,
|
p.title as project_title,
|
||||||
p.description,
|
p.description as project_description,
|
||||||
p.isComplete
|
p.isComplete
|
||||||
from organizations as o
|
from organizations as o
|
||||||
left join (
|
left join (
|
||||||
@@ -235,3 +235,34 @@ exports.searchOrganizations = (req, res, next) => {
|
|||||||
})
|
})
|
||||||
.catch(error => next(error));
|
.catch(error => next(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getOrganizationById = async (req, res, next) => {
|
||||||
|
const { charityId } = req.params;
|
||||||
|
|
||||||
|
const QUERY = `
|
||||||
|
select
|
||||||
|
o.*,
|
||||||
|
p.id as project_id,
|
||||||
|
p.title as project_title,
|
||||||
|
p.description as project_description,
|
||||||
|
p.isComplete
|
||||||
|
from organizations as o
|
||||||
|
left join (
|
||||||
|
SELECT * from projects
|
||||||
|
where id in (
|
||||||
|
select
|
||||||
|
max(id)
|
||||||
|
from projects
|
||||||
|
group by organization_id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
as p on p.organization_id = o.id
|
||||||
|
WHERE o.id = :charityId
|
||||||
|
`;
|
||||||
|
const org = await db.sequelize.query(QUERY, {
|
||||||
|
replacements: { charityId },
|
||||||
|
type: db.Sequelize.QueryTypes.SELECT
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json(org[0]);
|
||||||
|
};
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ router.get('/regions', region.getAllRegions);
|
|||||||
// Retrieve all organizations
|
// Retrieve all organizations
|
||||||
router.get('/organizations', organization.getAllOrganizations);
|
router.get('/organizations', organization.getAllOrganizations);
|
||||||
|
|
||||||
|
// Retrieve organization by id
|
||||||
|
router.get('/organization/:charityId', organization.getOrganizationById);
|
||||||
|
|
||||||
// Retrieve charities based on inputted search
|
// Retrieve charities based on inputted search
|
||||||
// TODO: fix sql injection attack
|
// TODO: fix sql injection attack
|
||||||
router.get('/organizations/:search', organization.searchOrganizations);
|
router.get('/organizations/:search', organization.searchOrganizations);
|
||||||
|
|||||||
Reference in New Issue
Block a user