adding payment status to a charge and getting all charges for a donor
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
const db = require("../../models"),
|
||||||
|
errorMaker = require("../helpers/error.maker");
|
||||||
|
|
||||||
|
const { Charge, sequelize } = db;
|
||||||
|
|
||||||
|
// Find grants with causes, regions, and organizations by donor_id
|
||||||
|
exports.getAllCharges = async (req, res, next) => {
|
||||||
|
const donor_id = req.user.id;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const charges = await db.sequelize.query(
|
||||||
|
`
|
||||||
|
SELECT
|
||||||
|
g.name,
|
||||||
|
g.monthly,
|
||||||
|
g.num_causes,
|
||||||
|
g.num_regions,
|
||||||
|
c.amount,
|
||||||
|
c.created_at
|
||||||
|
FROM grants as g
|
||||||
|
INNER JOIN charges as c on c.grant_id = g.id
|
||||||
|
WHERE g.donor_id = :donor_id;
|
||||||
|
`,
|
||||||
|
{ type: db.sequelize.QueryTypes.SELECT, replacements: { donor_id } }
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
charges
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
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")
|
||||||
};
|
};
|
||||||
|
|||||||
+28
-20
@@ -1,50 +1,58 @@
|
|||||||
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 { donor, grant, stripe, organization } = require('../controllers');
|
const {
|
||||||
|
donor,
|
||||||
|
grant,
|
||||||
|
stripe,
|
||||||
|
organization,
|
||||||
|
charge
|
||||||
|
} = require("../controllers");
|
||||||
|
|
||||||
// POST donor signup
|
// POST donor signup
|
||||||
router.post('/', donor.createDonor);
|
router.post("/", donor.createDonor);
|
||||||
|
|
||||||
// GET all Donors
|
// GET all Donors
|
||||||
router.get('/', checkAuth(roles.ADMIN), donor.getAllDonors);
|
router.get("/", checkAuth(roles.ADMIN), donor.getAllDonors);
|
||||||
|
|
||||||
// GET grants with causes, regions, charities by donor_id
|
// GET grants with causes, regions, charities by donor_id
|
||||||
router.get('/grants/', checkAuth(roles.DONOR), grant.findGrantsByDonorId);
|
router.get("/grants/", checkAuth(roles.DONOR), grant.findGrantsByDonorId);
|
||||||
|
|
||||||
/** POST Create grants with following body:
|
/** POST Create grants with following body:
|
||||||
* - List of id's of selected causes, regions, charities
|
* - List of id's of selected causes, regions, charities
|
||||||
* - Monthly: true or false
|
* - Monthly: true or false
|
||||||
* - donor_id
|
* - donor_id
|
||||||
* */
|
* */
|
||||||
router.post('/grants/', checkAuth(roles.DONOR), grant.createGrant);
|
router.post("/grants/", checkAuth(roles.DONOR), grant.createGrant);
|
||||||
|
|
||||||
// DELETE a grant of a donor
|
// DELETE a grant of a donor
|
||||||
router.delete(
|
router.delete(
|
||||||
'/grants/',
|
"/grants/",
|
||||||
checkAuth(roles.DONOR),
|
checkAuth(roles.DONOR),
|
||||||
stripe.deleteGrant,
|
stripe.deleteGrant,
|
||||||
grant.deleteGrant
|
grant.deleteGrant
|
||||||
);
|
);
|
||||||
|
|
||||||
// POST to get suggested organizations to distribute to
|
// POST to get suggested organizations to distribute to
|
||||||
// running "the algorithm"
|
// running "the algorithm"
|
||||||
router.post(
|
router.post(
|
||||||
'/organizations/',
|
"/organizations/",
|
||||||
checkAuth(roles.DONOR),
|
checkAuth(roles.DONOR),
|
||||||
organization.findSuggestedCharities
|
organization.findSuggestedCharities
|
||||||
);
|
);
|
||||||
|
|
||||||
// GET min and optimal amount to choose
|
// GET min and optimal amount to choose
|
||||||
router.get(
|
router.get(
|
||||||
'/organizations/amounts',
|
"/organizations/amounts",
|
||||||
checkAuth(roles.DONOR),
|
checkAuth(roles.DONOR),
|
||||||
organization.findOptimalBundleAmounts
|
organization.findOptimalBundleAmounts
|
||||||
);
|
);
|
||||||
|
|
||||||
router.get('/dashboard', checkAuth(roles.DONOR), donor.getDashboardData);
|
router.get("/dashboard", checkAuth(roles.DONOR), donor.getDashboardData);
|
||||||
|
|
||||||
|
router.get("/charges", checkAuth(roles.DONOR), charge.getAllCharges);
|
||||||
|
|
||||||
// // Retrieve a single Donor by Id
|
// // Retrieve a single Donor by Id
|
||||||
// router.get('/:donor_id', donor.findById);
|
// router.get('/:donor_id', donor.findById);
|
||||||
|
|||||||
+19
-8
@@ -1,10 +1,21 @@
|
|||||||
'use strict';
|
"use strict";
|
||||||
module.exports = (sequelize, DataTypes) => {
|
const PaymentStatus = require("./PaymentStatus");
|
||||||
const Charge = sequelize.define('Charge', {
|
|
||||||
id: { type: DataTypes.UUID, primaryKey: true, allowNull: false },
|
|
||||||
description: DataTypes.STRING,
|
|
||||||
amount: DataTypes.INTEGER
|
|
||||||
});
|
|
||||||
|
|
||||||
return Charge;
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
const Charge = sequelize.define("Charge", {
|
||||||
|
id: { type: DataTypes.UUID, primaryKey: true, allowNull: false },
|
||||||
|
description: DataTypes.STRING,
|
||||||
|
amount: DataTypes.INTEGER,
|
||||||
|
|
||||||
|
payment_status: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: PaymentStatus(sequelize, DataTypes),
|
||||||
|
key: "name"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return Charge;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
"use strict";
|
||||||
|
module.exports = (sequelize, DataTypes) => {
|
||||||
|
const PaymentStatus = sequelize.define("PaymentStatus", {
|
||||||
|
name: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return PaymentStatus;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user