Skip to content

Commit

Permalink
Added method to load fundDonations by person
Browse files Browse the repository at this point in the history
  • Loading branch information
jzongker committed Nov 19, 2024
1 parent 5909bf8 commit bc6e1d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/controllers/DonationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export class DonationController extends GivingBaseController {
});
}

@httpGet("/my")
public async getMy(req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
const result = await this.repositories.donation.loadByPersonId(au.churchId, au.personId);
return this.repositories.donation.convertAllToModel(au.churchId, result);
});
}

@httpGet("/:id")
public async get(@requestParam("id") id: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
Expand Down
11 changes: 11 additions & 0 deletions src/controllers/FundDonationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { Permissions } from '../helpers/Permissions'
@controller("/funddonations")
export class FundDonationController extends GivingBaseController {

@httpGet("/my")
public async getMy(req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
return this.repositories.fundDonation.loadByPersonId(au.churchId, au.personId);
});
}

@httpGet("/:id")
public async get(@requestParam("id") id: string, req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
Expand All @@ -15,13 +22,17 @@ export class FundDonationController extends GivingBaseController {
});
}



@httpGet("/")
public async getAll(req: express.Request<{}, {}, null>, res: express.Response): Promise<interfaces.IHttpActionResult> {
return this.actionWrapper(req, res, async (au) => {
if (!au.checkAccess(Permissions.donations.view)) return this.json({}, 401);
else {
let result;

if (req.query.donationId !== undefined) result = await this.repositories.fundDonation.loadByDonationId(au.churchId, req.query.donationId.toString());
else if (req.query.personId !== undefined) result = await this.repositories.fundDonation.loadByPersonId(au.churchId, req.query.personId.toString());
else if (req.query.fundId !== undefined) {
if (req.query.startDate === undefined) result = await this.repositories.fundDonation.loadByFundId(au.churchId, req.query.fundId.toString());
else {
Expand Down
4 changes: 4 additions & 0 deletions src/repositories/FundDonationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export class FundDonationRepository {
return DB.query("SELECT * FROM fundDonations WHERE churchId=? AND donationId=?;", [churchId, donationId]);
}

public loadByPersonId(churchId: string, personId: string) {
return DB.query("SELECT fd.* FROM donations d inner join fundDonations fd on fd.churchId=d.churchId and fd.donationId=d.id WHERE d.churchId=? AND d.personId=?;", [churchId, personId]);
}

public loadByFundId(churchId: string, fundId: string) {
return DB.query("SELECT fd.*, d.donationDate, d.batchId, d.personId FROM fundDonations fd INNER JOIN donations d ON d.id=fd.donationId WHERE fd.churchId=? AND fd.fundId=? ORDER by d.donationDate desc;", [churchId, fundId]);
}
Expand Down

0 comments on commit bc6e1d9

Please sign in to comment.