Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

refactor: merge contribution data into same table #428

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"test": "jest --setupFiles dotenv/config"
},
"dependencies": {
"@beabee/beabee-common": "^0.21.0",
"@beabee/beabee-common": "^0.21.1-alpha.2",
"@captchafox/node": "^1.2.0",
"@inquirer/prompts": "^3.3.0",
"@sendgrid/mail": "^8.1.0",
Expand Down Expand Up @@ -131,10 +131,10 @@
"rimraf": "^5.0.5",
"sass": "1.57.*",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"tsc-watch": "^6.0.4",
"tsconfig": "^7.0.0",
"typescript": "^5.3.3",
"ts-node": "^10.9.2"
"typescript": "^5.3.3"
},
"browserslist": [
"last 1 versions",
Expand All @@ -155,4 +155,4 @@
"postcss": "8.4.32"
}
}
}
}
33 changes: 17 additions & 16 deletions src/api/controllers/ContactController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ export class ContactController {
}
}

if (data.contribution) {
await ContactsService.forceUpdateContactContribution(
contact,
data.contribution
);
}
// TODO
// if (data.contribution) {
// await ContactsService.forceUpdateContactContribution(
// contact,
// data.contribution
// );
// }

return ContactTransformer.convert(
contact,
Expand Down Expand Up @@ -301,15 +302,15 @@ export class ContactController {
* @param data
* @returns
*/
@Authorized("admin")
@Patch("/:id/contribution/force")
async forceUpdateContribution(
@TargetUser() target: Contact,
@Body() data: ForceUpdateContributionDto
): Promise<GetContributionInfoDto> {
await ContactsService.forceUpdateContactContribution(target, data);
return await this.getContribution(target);
}
// @Authorized("admin")
// @Patch("/:id/contribution/force")
// async forceUpdateContribution(
// @TargetUser() target: Contact,
// @Body() data: ForceUpdateContributionDto
// ): Promise<GetContributionInfoDto> {
// await ContactsService.forceUpdateContactContribution(target, data);
// return await this.getContribution(target);
// }

@Get("/:id/payment")
async getPayments(
Expand All @@ -333,7 +334,7 @@ export class ContactController {
): Promise<GetPaymentFlowDto> {
const paymentMethod =
data.paymentMethod ||
(await PaymentService.getContribution(target)).method;
(await PaymentService.getCurrentContribution(target)).method;
if (!paymentMethod) {
throw new NoPaymentMethod();
}
Expand Down
13 changes: 5 additions & 8 deletions src/api/dto/ContactDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
NewsletterStatus,
RoleType,
RoleTypes,
PaymentSource
PaymentSource,
PaymentMethod
} from "@beabee/beabee-common";
import { Type } from "class-transformer";
import {
Expand Down Expand Up @@ -69,17 +70,13 @@ export class ListContactsDto extends GetPaginatedQuery {
}

export class GetContributionInfoDto implements ContributionInfo {
@IsEnum(ContributionType)
type!: ContributionType;
@IsEnum(PaymentMethod)
method!: PaymentMethod;

@IsOptional()
@IsNumber()
amount?: number;

@IsOptional()
@IsNumber()
nextAmount?: number;

@IsOptional()
@IsEnum(ContributionPeriod)
period?: ContributionPeriod;
Expand Down Expand Up @@ -190,7 +187,7 @@ export interface ExportContactDto {
LastName: string;
Joined: string;
Tags: string;
ContributionType: ContributionType;
PaymentMethod: PaymentMethod;
ContributionMonthlyAmount: number | null;
ContributionPeriod: ContributionPeriod | null;
ContributionDescription: string;
Expand Down
3 changes: 1 addition & 2 deletions src/api/dto/PaymentFlowDto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PaymentFlowParams } from "@beabee/beabee-common";
import { IsOptional, IsString } from "class-validator";

import { PaymentFlowParams } from "@type/index";

export class GetPaymentFlowDto implements PaymentFlowParams {
@IsOptional()
@IsString()
Expand Down
6 changes: 4 additions & 2 deletions src/api/transformers/BaseContactTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export abstract class BaseContactTransformer<
contributionCancelled: contributionField("cancelledAt"),
manualPaymentSource: (qb, args) => {
contributionField("mandateId")(qb, args);
qb.andWhere(`${args.fieldPrefix}contributionType = 'Manual'`);
// TODO
// qb.andWhere(`${args.fieldPrefix}contributionType = 'Manual'`);
}
};

Expand Down Expand Up @@ -123,7 +124,8 @@ function contributionField(field: keyof ContactContribution): FilterHandler {
.subQuery()
.select(`cc.contactId`)
.from(ContactContribution, "cc")
.where(convertToWhereClause(`cc.${field}`));
.where("cc.status = 'current'")
.andWhere(convertToWhereClause(`cc.${field}`));

qb.where(`${fieldPrefix}id IN ${subQb.getQuery()}`);
};
Expand Down
14 changes: 9 additions & 5 deletions src/api/transformers/ContactExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class ContactExporter extends BaseContactTransformer<
LastName: contact.lastname,
Joined: contact.joined.toISOString(),
Tags: contact.profile.tags.join(", "),
ContributionType: contact.contributionType,
ContributionMonthlyAmount: contact.contributionMonthlyAmount,
ContributionPeriod: contact.contributionPeriod,
ContributionDescription: contact.contributionDescription,
PaymentMethod: contact.contribution.method,
ContributionMonthlyAmount: contact.contribution.monthlyAmount,
ContributionPeriod: contact.contribution.period,
ContributionDescription: contact.contribution.description,
ContributionCancelled:
contact.contribution.cancelledAt?.toISOString() || "",
MembershipStarts: contact.membership?.dateAdded.toISOString() || "",
Expand All @@ -51,7 +51,11 @@ class ContactExporter extends BaseContactTransformer<
qb.orderBy(`${fieldPrefix}joined`);
qb.leftJoinAndSelect(`${fieldPrefix}roles`, "roles");
qb.leftJoinAndSelect(`${fieldPrefix}profile`, "profile");
qb.leftJoinAndSelect(`${fieldPrefix}contribution`, "contribution");
qb.leftJoinAndSelect(
`${fieldPrefix}contribution`,
"contribution",
"contribution.status = 'current'"
);
}

async export(
Expand Down
10 changes: 6 additions & 4 deletions src/api/transformers/ContactTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class ContactTransformer extends BaseContactTransformer<
...(contact.lastSeen && {
lastSeen: contact.lastSeen
}),
...(contact.contributionAmount && {
contributionAmount: contact.contributionAmount
...(contact.contribution.amount !== null && {
contributionAmount: contact.contribution.amount
}),
...(contact.contributionPeriod && {
contributionPeriod: contact.contributionPeriod
...(contact.contribution.period && {
contributionPeriod: contact.contribution.period
}),
...(opts?.with?.includes(GetContactWith.Profile) &&
contact.profile && {
Expand Down Expand Up @@ -86,6 +86,8 @@ class ContactTransformer extends BaseContactTransformer<
query: ListContactsDto
): void {
{
qb.innerJoinAndSelect(`${fieldPrefix}contribution`, "contribution");

if (query.with?.includes(GetContactWith.Profile)) {
qb.innerJoinAndSelect(`${fieldPrefix}profile`, "profile");
}
Expand Down
7 changes: 4 additions & 3 deletions src/apps/members/apps/member/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ app.use(
relations: { profile: true }
});
if (contact) {
const contribution = await PaymentService.getCurrentContribution(contact);
contact.contribution = contribution;

req.model = contact;
const { method, ...contribution } =
await PaymentService.getContribution(contact);
res.locals.contribution = contribution;
res.locals.paymentMethod = method;
res.locals.paymentMethod = contribution.method;
next();
} else {
next("route");
Expand Down
38 changes: 18 additions & 20 deletions src/apps/members/apps/member/apps/contribution/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContributionType } from "@beabee/beabee-common";
import { ContributionType, PaymentMethod } from "@beabee/beabee-common";
import express from "express";

import { wrapAsync } from "@core/utils";
Expand All @@ -17,7 +17,12 @@ app.get(
"/",
wrapAsync(async (req, res) => {
const contact = req.model as Contact;
if (contact.contributionType === ContributionType.Automatic) {
if (
contact.contribution.method === PaymentMethod.Manual ||
contact.contribution.method === PaymentMethod.None
) {
res.render("manual", { member: contact });
} else {
const payments = await PaymentService.getPayments(contact);

const successfulPayments = payments
Expand All @@ -34,13 +39,6 @@ app.get(
payments,
total
});
} else if (
contact.contributionType === ContributionType.Manual ||
contact.contributionType === ContributionType.None
) {
res.render("manual", { member: contact });
} else {
res.render("none", { member: contact });
}
})
);
Expand Down Expand Up @@ -68,17 +66,17 @@ app.post(
);
break;

case "force-update":
await ContactsService.forceUpdateContactContribution(contact, {
type: req.body.type,
amount: req.body.amount,
period: req.body.period,
source: req.body.source,
reference: req.body.reference
});

req.flash("success", "contribution-updated");
break;
// case "force-update":
// await ContactsService.forceUpdateContactContribution(contact, {
// type: req.body.type,
// amount: req.body.amount,
// period: req.body.period,
// source: req.body.source,
// reference: req.body.reference
// });

// req.flash("success", "contribution-updated");
// break;
}

res.redirect(req.originalUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ block contents
value: member.contributionMonthlyAmount
})
if !!contribution.subscriptionId
input(type='hidden' name='period' value=member.contributionPeriod)
input(type='hidden' name='period' value=contribution.period)
.form-group
label.col-md-3.control-label Period
.col-md-4.form-control-static= member.contributionPeriod
.col-md-4.form-control-static= contribution.period
else
+input( 'radio', 'Period', 'period', {
left: 3, right: 4,
options: {'monthly': 'Monthly', 'annually': 'Annually'},
value: member.contributionPeriod
value: contribution.period
})
+input( 'checkbox', 'Paying fee', 'payFee', {
left: 3, right: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
.js-reveal-type(data-type='Manual')
+input( 'number', 'Amount', 'amount', {
left: 3, right: 4, before: currencySymbol,
value: member.contributionAmount
value: contribution.amount
})
+input( 'radio', 'Period', 'period', {
left: 3, right: 4,
options: {'monthly': 'Monthly', 'annually': 'Annually'},
value: member.contributionPeriod
value: contribution.period
})

.form-group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dl.dl-horizontal
if member.contributionType
dt Amount
dd
= member.contributionDescription
= contribution.description
case member.contributionType
when 'Automatic'
include automatic.pug
Expand Down
4 changes: 2 additions & 2 deletions src/apps/members/views/partials/table.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mixin contactsTable
+membersTableBasicInfo(contact)
span(style='flex: 0 1 120px')
= currencySymbol
= contact.contributionAmount
= contact.contribution.amount
| /
= contact.contributionPeriod
= contact.contribution.period

if addToProject
form(method='POST' action='/projects/' + addToProject.id)
Expand Down
17 changes: 10 additions & 7 deletions src/apps/tools/apps/exports/exports/ActiveMembersExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default class ActiveMembersExport extends BaseExport<Contact> {
const query = super
.getNewItemsQuery()
.innerJoin("m.roles", "mp")
.innerJoinAndSelect(
ContactContribution,
"contribution",
"contribution.contactId = m.id AND contribution.status = 'current'"
)
.andWhere("mp.type = 'member' AND mp.dateAdded <= :now")
.andWhere(
new Brackets((qb) => {
Expand All @@ -44,9 +49,7 @@ export default class ActiveMembersExport extends BaseExport<Contact> {
.setParameters({ now: new Date() });

if (this.ex!.params?.hasActiveSubscription) {
query
.innerJoin(ContactContribution, "cc", "cc.contactId = m.id")
.andWhere("cc.subscriptionId IS NOT NULL");
query.andWhere("contribution.subscriptionId IS NOT NULL");
}

return query;
Expand All @@ -60,10 +63,10 @@ export default class ActiveMembersExport extends BaseExport<Contact> {
LastName: contact.lastname,
ReferralCode: contact.referralCode,
PollsCode: contact.pollsCode,
ContributionType: contact.contributionType,
ContributionMonthlyAmount: contact.contributionMonthlyAmount,
ContributionPeriod: contact.contributionPeriod,
ContributionDescription: contact.contributionDescription
ContributionType: contact.contribution.method,
ContributionMonthlyAmount: contact.contribution.monthlyAmount,
ContributionPeriod: contact.contribution.period,
ContributionDescription: contact.contribution.description
}));
}
}
Loading
Loading