properly adding in project retrieval with organization
This commit is contained in:
+11
-10
@@ -1,12 +1,13 @@
|
||||
module.exports = {
|
||||
donor: require("./donor.controller"),
|
||||
grant: require("./grant.controller"),
|
||||
organization: require("./organization.controller"),
|
||||
stripe: require("./stripe.controller"),
|
||||
sendgrid: require("./sendgrid.controller"),
|
||||
region: require("./region.controller"),
|
||||
cause: require("./cause.controller"),
|
||||
user: require("./user.controller"),
|
||||
auth: require("./auth.controller"),
|
||||
charge: require("./charge.controller")
|
||||
donor: require('./donor.controller'),
|
||||
grant: require('./grant.controller'),
|
||||
organization: require('./organization.controller'),
|
||||
stripe: require('./stripe.controller'),
|
||||
sendgrid: require('./sendgrid.controller'),
|
||||
region: require('./region.controller'),
|
||||
cause: require('./cause.controller'),
|
||||
user: require('./user.controller'),
|
||||
auth: require('./auth.controller'),
|
||||
charge: require('./charge.controller'),
|
||||
project: require('./project.controller')
|
||||
};
|
||||
|
||||
@@ -181,15 +181,34 @@ exports.createOrganization = async (req, res, next) => {
|
||||
};
|
||||
|
||||
// FETCH all organizations
|
||||
exports.getAllOrganizations = (req, res, next) => {
|
||||
Organization.findAll()
|
||||
.then(organizations => {
|
||||
res.status(200).json({
|
||||
organizations,
|
||||
number_items: organizations.length
|
||||
});
|
||||
})
|
||||
.catch(error => next(error));
|
||||
exports.getAllOrganizations = async (req, res, next) => {
|
||||
const QUERY = `
|
||||
select
|
||||
o.*,
|
||||
p.id as project_id,
|
||||
p.title,
|
||||
p.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
|
||||
`;
|
||||
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
|
||||
|
||||
@@ -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"),
|
||||
router = express.Router(),
|
||||
checkAuth = require("../middleware/check-auth"),
|
||||
roles = require("../helpers/roles");
|
||||
const express = require('express'),
|
||||
router = express.Router(),
|
||||
checkAuth = require('../middleware/check-auth'),
|
||||
roles = require('../helpers/roles');
|
||||
|
||||
const { organization, cause, region, stripe } = require("../controllers");
|
||||
const {
|
||||
organization,
|
||||
cause,
|
||||
region,
|
||||
stripe,
|
||||
project
|
||||
} = require('../controllers');
|
||||
|
||||
// Charity signup route
|
||||
router.post("/", organization.createOrganization);
|
||||
router.post('/', organization.createOrganization);
|
||||
|
||||
// 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
|
||||
router.get(
|
||||
"/stripe/link",
|
||||
checkAuth(roles.ORGANIZATION),
|
||||
stripe.getExpressUILink
|
||||
'/stripe/link',
|
||||
checkAuth(roles.ORGANIZATION),
|
||||
stripe.getExpressUILink
|
||||
);
|
||||
|
||||
router.post('/project', checkAuth(roles.ORGANIZATION), project.createProject);
|
||||
|
||||
// // Add cause
|
||||
// router.post('/cause', checkAuth(roles.ORGANIZATION), cause.createCause);
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ module.exports = (sequelize, DataTypes) => {
|
||||
defaultValue: 0
|
||||
},
|
||||
|
||||
title: {
|
||||
type: DataTypes.STRING(1000),
|
||||
allowNull: false
|
||||
},
|
||||
description: DataTypes.STRING,
|
||||
isComplete: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
|
||||
Reference in New Issue
Block a user