getting all the status updates route
This commit is contained in:
@@ -4,6 +4,27 @@ const db = require('../../models'),
|
|||||||
|
|
||||||
const { Post, sequelize } = db;
|
const { Post, sequelize } = db;
|
||||||
|
|
||||||
|
// gets all posts for a charity
|
||||||
|
exports.getStatusUpdatesByOrg = async (req, res, next) => {
|
||||||
|
const { organization_id } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const posts = await sequelize.query(
|
||||||
|
`
|
||||||
|
SELECT * FROM posts
|
||||||
|
WHERE organization_id = :organization_id`,
|
||||||
|
{
|
||||||
|
type: db.Sequelize.QueryTypes.SELECT,
|
||||||
|
replacements: { organization_id }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({ posts, total: posts.length });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.createStatusUpdate = async (req, res, next) => {
|
exports.createStatusUpdate = async (req, res, next) => {
|
||||||
const { text } = req.body;
|
const { text } = req.body;
|
||||||
|
|
||||||
@@ -45,9 +66,9 @@ exports.addRibbon = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return res
|
return res.status(200).json({
|
||||||
.status(200)
|
message: 'Successfully added ribbon to post!'
|
||||||
.json({ message: 'Successfully added ribbon to post!' });
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ const {
|
|||||||
cause,
|
cause,
|
||||||
region,
|
region,
|
||||||
organization,
|
organization,
|
||||||
user
|
user,
|
||||||
|
post
|
||||||
} = require('../controllers');
|
} = require('../controllers');
|
||||||
|
|
||||||
// Retrieve all causes
|
// Retrieve all causes
|
||||||
@@ -21,6 +22,12 @@ router.get('/organizations', organization.getAllOrganizations);
|
|||||||
// Retrieve organization by id
|
// Retrieve organization by id
|
||||||
router.get('/organization/:charityId', organization.getOrganizationById);
|
router.get('/organization/:charityId', organization.getOrganizationById);
|
||||||
|
|
||||||
|
// get all posts for an organization
|
||||||
|
router.get(
|
||||||
|
'/organizations/statusupdates/:organization_id',
|
||||||
|
post.getStatusUpdatesByOrg
|
||||||
|
);
|
||||||
|
|
||||||
// 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