properly adding in project retrieval with organization
This commit is contained in:
+11
-10
@@ -1,12 +1,13 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
donor: require("./donor.controller"),
|
donor: require('./donor.controller'),
|
||||||
grant: require("./grant.controller"),
|
grant: require('./grant.controller'),
|
||||||
organization: require("./organization.controller"),
|
organization: require('./organization.controller'),
|
||||||
stripe: require("./stripe.controller"),
|
stripe: require('./stripe.controller'),
|
||||||
sendgrid: require("./sendgrid.controller"),
|
sendgrid: require('./sendgrid.controller'),
|
||||||
region: require("./region.controller"),
|
region: require('./region.controller'),
|
||||||
cause: require("./cause.controller"),
|
cause: require('./cause.controller'),
|
||||||
user: require("./user.controller"),
|
user: require('./user.controller'),
|
||||||
auth: require("./auth.controller"),
|
auth: require('./auth.controller'),
|
||||||
charge: require("./charge.controller")
|
charge: require('./charge.controller'),
|
||||||
|
project: require('./project.controller')
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -181,15 +181,34 @@ exports.createOrganization = async (req, res, next) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// FETCH all organizations
|
// FETCH all organizations
|
||||||
exports.getAllOrganizations = (req, res, next) => {
|
exports.getAllOrganizations = async (req, res, next) => {
|
||||||
Organization.findAll()
|
const QUERY = `
|
||||||
.then(organizations => {
|
select
|
||||||
res.status(200).json({
|
o.*,
|
||||||
organizations,
|
p.id as project_id,
|
||||||
number_items: organizations.length
|
p.title,
|
||||||
});
|
p.description,
|
||||||
})
|
p.isComplete
|
||||||
.catch(error => next(error));
|
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
|
||||||
|
`;
|
||||||
|
const organizations = await db.sequelize.query(QUERY, {
|
||||||
|
type: db.Sequelize.QueryTypes.SELECT
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
organizations,
|
||||||
|
number_items: organizations.length
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// FETCH depending on the given search
|
// FETCH depending on the given search
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
const db = require('../../models'),
|
||||||
|
errorMaker = require('../helpers/error.maker'),
|
||||||
|
textCleaner = require('../helpers/text_cleaner');
|
||||||
|
|
||||||
|
const { Project } = db;
|
||||||
|
|
||||||
|
exports.createProject = async (req, res, next) => {
|
||||||
|
const { org_id } = req.user.id;
|
||||||
|
|
||||||
|
var project = await db.sequelize.query(`
|
||||||
|
SELECT *
|
||||||
|
FROM project
|
||||||
|
WHERE organization_id = :org_id
|
||||||
|
ORDER BY created_at `);
|
||||||
|
};
|
||||||
@@ -1,23 +1,31 @@
|
|||||||
const express = require("express"),
|
const express = require('express'),
|
||||||
router = express.Router(),
|
router = express.Router(),
|
||||||
checkAuth = require("../middleware/check-auth"),
|
checkAuth = require('../middleware/check-auth'),
|
||||||
roles = require("../helpers/roles");
|
roles = require('../helpers/roles');
|
||||||
|
|
||||||
const { organization, cause, region, stripe } = require("../controllers");
|
const {
|
||||||
|
organization,
|
||||||
|
cause,
|
||||||
|
region,
|
||||||
|
stripe,
|
||||||
|
project
|
||||||
|
} = require('../controllers');
|
||||||
|
|
||||||
// Charity signup route
|
// Charity signup route
|
||||||
router.post("/", organization.createOrganization);
|
router.post('/', organization.createOrganization);
|
||||||
|
|
||||||
// GET Activate org's stripe connected account
|
// GET Activate org's stripe connected account
|
||||||
router.get("/stripe/connect", stripe.activateStripeAccount);
|
router.get('/stripe/connect', stripe.activateStripeAccount);
|
||||||
|
|
||||||
// GET stripe express ui account link
|
// GET stripe express ui account link
|
||||||
router.get(
|
router.get(
|
||||||
"/stripe/link",
|
'/stripe/link',
|
||||||
checkAuth(roles.ORGANIZATION),
|
checkAuth(roles.ORGANIZATION),
|
||||||
stripe.getExpressUILink
|
stripe.getExpressUILink
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.post('/project', checkAuth(roles.ORGANIZATION), project.createProject);
|
||||||
|
|
||||||
// // Add cause
|
// // Add cause
|
||||||
// router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);
|
// router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
defaultValue: 0
|
defaultValue: 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
title: {
|
||||||
|
type: DataTypes.STRING(1000),
|
||||||
|
allowNull: false
|
||||||
|
},
|
||||||
description: DataTypes.STRING,
|
description: DataTypes.STRING,
|
||||||
isComplete: {
|
isComplete: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
|
|||||||
Reference in New Issue
Block a user