Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: contact contribution history #42

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c4604d
Update watch scripts
wpf500 Aug 2, 2024
9e40455
Move PaymentFlowParams to common
wpf500 Aug 2, 2024
5b4f9a1
Update some references to contribution* fields on Contact
wpf500 Aug 2, 2024
1af4924
Start to unify contribution updating logic
wpf500 Aug 2, 2024
d3d71fc
Migration for new ContactContribution schema
wpf500 Aug 2, 2024
218929a
Remove reference to nextAmount
wpf500 Aug 6, 2024
8d5f184
Temporarily comment out webhook problems
wpf500 Aug 6, 2024
2ff3ec2
Make expiryDate optional instead of nullable
wpf500 Aug 6, 2024
5fdaafb
Load current contribution for export
wpf500 Aug 6, 2024
02bcf11
Use transaction for contribution update
wpf500 Aug 6, 2024
927cf5d
Add manual payment type
wpf500 Aug 6, 2024
7202cd2
Add NoneProviders for payment
wpf500 Aug 6, 2024
f8bee54
Store contribution for later use
wpf500 Aug 6, 2024
8e09e0e
Clear cancelledAt on payment update
wpf500 Aug 6, 2024
5687fae
No payment fees for none or manual types
wpf500 Aug 6, 2024
75ffcfc
Use barrelsby instead of custom script
wpf500 Aug 6, 2024
e3e8527
Add CancelContributionResult
wpf500 Aug 6, 2024
109464b
Merge branch 'main' into refactor/contribution-info
wpf500 Aug 7, 2024
d607ebe
Merge branch 'main' into refactor/contribution-info
wpf500 Aug 7, 2024
3ee9b4d
Merge branch 'main' into refactor/contribution-info
wpf500 Aug 8, 2024
6f7652a
Remove this.method
wpf500 Aug 8, 2024
6384849
Remove this. state from payment providers
wpf500 Aug 8, 2024
6a43338
Remove unused method
wpf500 Aug 8, 2024
925efc7
Use stricter return for getContributionInfo, remove duplicate type
wpf500 Aug 8, 2024
dacd1f1
Better documentation and simplfied code
wpf500 Aug 8, 2024
1d84597
Move grace period calculation out of PaymentService
wpf500 Aug 8, 2024
573a694
Remove getMembershipStatus
wpf500 Aug 8, 2024
0dbd51c
Ensure contribution state isn't used stale
wpf500 Aug 8, 2024
d2fea1a
Fix prettier error
wpf500 Aug 9, 2024
29fe0bf
Fix invalid import
wpf500 Aug 9, 2024
3b11b06
Merge branch 'main' into refactor/contribution-info
wpf500 Sep 30, 2024
c7db4b1
Simplify update GC contribution
wpf500 Oct 10, 2024
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
16 changes: 16 additions & 0 deletions apps/backend/barrelsby.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"delete": true,
"local": true,
"directory": [
"./src/api/controllers",
"./src/api/decorators",
"./src/api/dto",
"./src/api/interceptors",
"./src/api/middlewares",
"./src/api/params",
"./src/api/transformers",
"./src/api/utils",
"./src/api/validators",
"./src/type"
]
}
6 changes: 3 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"dev:api:watch": "tsc-watch -p tsconfig.build.json --noClear --onSuccess 'docker compose restart api_app router'",
"dev:api:logs": "yarn exec bash -c 'while true; do docker compose logs -f --tail=0 api_app; sleep 1; done'",
"build": "rimraf built/ && gulp build && tsc -p ./tsconfig.build.json",
"generate:index": "ts-node scripts/generate-index.ts",
"watch": "tsc-watch -p tsconfig.build.json --noClear",
"generate:index": "barrelsby -c barrelsby.json",
"watch": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
"check": "concurrently 'yarn:check:*'",
"check:tsc": "tsc --noEmit",
"check:prettier": "prettier -c .",
Expand Down Expand Up @@ -108,6 +108,7 @@
"@types/pug": "^2.0.10",
"@types/uuid": "^9.0.8",
"autoprefixer": "^10.4.19",
"barrelsby": "^2.8.1",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
"dpdm": "^3.14.0",
Expand All @@ -121,7 +122,6 @@
"rimraf": "^5.0.7",
"sass": "^1.77.4",
"ts-jest": "^29.1.4",
"ts-node": "^10.9.2",
"tsc-watch": "^6.2.0",
"tsconfig": "^7.0.0",
"typescript": "^5.4.5"
Expand Down
41 changes: 0 additions & 41 deletions apps/backend/scripts/generate-index.ts

This file was deleted.

38 changes: 21 additions & 17 deletions apps/backend/src/api/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
export * from "./ApiKeyController.js";
export * from "./AuthController.js";
export * from "./CalloutController.js";
export * from "./CalloutResponseCommentController.js";
export * from "./CalloutResponseController.js";
export * from "./ContactController.js";
export * from "./ContentController.js";
export * from "./EmailController.js";
export * from "./NoticeController.js";
export * from "./PaymentController.js";
export * from "./ResetDeviceController.js";
export * from "./ResetPasswordController.js";
export * from "./RootController.js";
export * from "./SegmentController.js";
export * from "./SignupController.js";
export * from "./StatsController.js";
export * from "./UploadController.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./ApiKeyController";
export * from "./AuthController";
export * from "./CalloutController";
export * from "./CalloutResponseCommentController";
export * from "./CalloutResponseController";
export * from "./ContactController";
export * from "./ContentController";
export * from "./EmailController";
export * from "./NoticeController";
export * from "./PaymentController";
export * from "./ResetDeviceController";
export * from "./ResetPasswordController";
export * from "./RootController";
export * from "./SegmentController";
export * from "./SignupController";
export * from "./StatsController";
export * from "./UploadController";
12 changes: 8 additions & 4 deletions apps/backend/src/api/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export * from "./CalloutId.js";
export * from "./CurrentAuth.js";
export * from "./PartialBody.js";
export * from "./TargetUser.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./CalloutId";
export * from "./CurrentAuth";
export * from "./PartialBody";
export * from "./TargetUser";
3 changes: 1 addition & 2 deletions apps/backend/src/api/dto/ContactDto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ContributionInfo,
ContributionPeriod,
ContributionType,
GetContactWith,
Expand Down Expand Up @@ -37,8 +38,6 @@ import { ForceUpdateContributionDto } from "@api/dto/ContributionDto";

import IsPassword from "@api/validators/IsPassword";

import { ContributionInfo } from "@beabee/core/type";

const contactSortFields = [
"firstname",
"lastname",
Expand Down
3 changes: 1 addition & 2 deletions apps/backend/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 "@beabee/core/type";

export class GetPaymentFlowDto implements PaymentFlowParams {
@IsOptional()
@IsString()
Expand Down
64 changes: 34 additions & 30 deletions apps/backend/src/api/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
export * from "./AddressDto.js";
export * from "./ApiKeyDto.js";
export * from "./BaseDto.js";
export * from "./CalloutDto.js";
export * from "./CalloutFormDto.js";
export * from "./CalloutResponseCommentDto.js";
export * from "./CalloutResponseDto.js";
export * from "./CalloutTagDto.js";
export * from "./CalloutVariantDto.js";
export * from "./ContactDto.js";
export * from "./ContactMfaDto.js";
export * from "./ContactProfileDto.js";
export * from "./ContactRoleDto.js";
export * from "./ContentDto.js";
export * from "./ContentTelegramDto.js";
export * from "./ContributionDto.js";
export * from "./EmailDto.js";
export * from "./JoinFlowDto.js";
export * from "./LinkDto.js";
export * from "./LoginDto.js";
export * from "./NoticeDto.js";
export * from "./PaginatedDto.js";
export * from "./PaymentDto.js";
export * from "./PaymentFlowDto.js";
export * from "./ResetDeviceDto.js";
export * from "./ResetPasswordDto.js";
export * from "./SegmentDto.js";
export * from "./SignupFlowDto.js";
export * from "./StatsDto.js";
export * from "./UploadFlowDto.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./AddressDto";
export * from "./ApiKeyDto";
export * from "./BaseDto";
export * from "./CalloutDto";
export * from "./CalloutFormDto";
export * from "./CalloutResponseCommentDto";
export * from "./CalloutResponseDto";
export * from "./CalloutTagDto";
export * from "./CalloutVariantDto";
export * from "./ContactDto";
export * from "./ContactMfaDto";
export * from "./ContactProfileDto";
export * from "./ContactRoleDto";
export * from "./ContentDto";
export * from "./ContentTelegramDto";
export * from "./ContributionDto";
export * from "./EmailDto";
export * from "./JoinFlowDto";
export * from "./LinkDto";
export * from "./LoginDto";
export * from "./NoticeDto";
export * from "./PaginatedDto";
export * from "./PaymentDto";
export * from "./PaymentFlowDto";
export * from "./ResetDeviceDto";
export * from "./ResetPasswordDto";
export * from "./SegmentDto";
export * from "./SignupFlowDto";
export * from "./StatsDto";
export * from "./UploadFlowDto";
6 changes: 5 additions & 1 deletion apps/backend/src/api/interceptors/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from "./ValidateResponseInterceptor.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./ValidateResponseInterceptor";
6 changes: 5 additions & 1 deletion apps/backend/src/api/middlewares/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from "./AuthMiddleware.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./AuthMiddleware";
12 changes: 8 additions & 4 deletions apps/backend/src/api/params/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export * from "./ContactRoleParams.js";
export * from "./ContentParams.js";
export * from "./SignupConfirmEmailParams.js";
export * from "./UUIDParams.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./ContactRoleParams";
export * from "./ContentParams";
export * from "./SignupConfirmEmailParams";
export * from "./UUIDParams";
14 changes: 8 additions & 6 deletions apps/backend/src/api/transformers/ContactExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { RoleType } from "@beabee/beabee-common";
import { stringify } from "csv-stringify/sync";
import { SelectQueryBuilder } from "typeorm";

import { getMembershipStatus } from "@beabee/core/services/PaymentService";

import { GetExportQuery } from "@api/dto/BaseDto";
import { ExportContactDto } from "@api/dto/ContactDto";

Expand All @@ -27,14 +25,14 @@ class ContactExporter extends BaseContactTransformer<
Joined: contact.joined.toISOString(),
Tags: contact.profile.tags.join(", "),
ContributionType: contact.contributionType,
ContributionMonthlyAmount: contact.contributionMonthlyAmount,
ContributionPeriod: contact.contributionPeriod,
ContributionMonthlyAmount: contact.contribution.monthlyAmount,
ContributionPeriod: contact.contribution.period,
ContributionDescription: contact.contributionDescription,
ContributionCancelled:
contact.contribution.cancelledAt?.toISOString() || "",
MembershipStarts: contact.membership?.dateAdded.toISOString() || "",
MembershipExpires: contact.membership?.dateExpires?.toISOString() || "",
MembershipStatus: getMembershipStatus(contact),
MembershipStatus: contact.membershipStatus,
NewsletterStatus: contact.profile.newsletterStatus,
DeliveryOptIn: contact.profile.deliveryOptIn,
DeliveryAddressLine1: contact.profile.deliveryAddress?.line1 || "",
Expand All @@ -51,7 +49,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}contributions`,
"contributions",
"contributions.status = 'current'"
);
}

async export(
Expand Down
15 changes: 11 additions & 4 deletions apps/backend/src/api/transformers/ContactTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class ContactTransformer extends BaseContactTransformer<
...(contact.lastSeen && {
lastSeen: contact.lastSeen
}),
...(contact.contributionAmount && {
contributionAmount: contact.contributionAmount
...(contact.contribution.amount && {
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 @@ -84,6 +84,13 @@ class ContactTransformer extends BaseContactTransformer<
query: ListContactsDto
): void {
{
// Will only ever return one contribution
qb.innerJoinAndSelect(
`${fieldPrefix}contributions`,
"contributions",
"contributions.status = 'current'"
);

if (query.with?.includes(GetContactWith.Profile)) {
qb.innerJoinAndSelect(`${fieldPrefix}profile`, "profile");
}
Expand Down
44 changes: 24 additions & 20 deletions apps/backend/src/api/transformers/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
export * from "./AddressTransformer.js";
export * from "./ApiKeyTransformer.js";
export * from "./BaseCalloutResponseTransformer.js";
export * from "./BaseContactTransformer.js";
export * from "./BaseTransformer.js";
export * from "./CalloutResponseCommentTransformer.js";
export * from "./CalloutResponseExporter.js";
export * from "./CalloutResponseMapTransformer.js";
export * from "./CalloutResponseTransformer.js";
export * from "./CalloutTagTransformer.js";
export * from "./CalloutTransformer.js";
export * from "./CalloutVariantTransformer.js";
export * from "./ContactExporter.js";
export * from "./ContactProfileTransformer.js";
export * from "./ContactRoleTransformer.js";
export * from "./ContactTransformer.js";
export * from "./ContentTransformer.js";
export * from "./NoticeTransformer.js";
export * from "./PaymentTransformer.js";
export * from "./SegmentTransformer.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./AddressTransformer";
export * from "./ApiKeyTransformer";
export * from "./BaseCalloutResponseTransformer";
export * from "./BaseContactTransformer";
export * from "./BaseTransformer";
export * from "./CalloutResponseCommentTransformer";
export * from "./CalloutResponseExporter";
export * from "./CalloutResponseMapTransformer";
export * from "./CalloutResponseTransformer";
export * from "./CalloutTagTransformer";
export * from "./CalloutTransformer";
export * from "./CalloutVariantTransformer";
export * from "./ContactExporter";
export * from "./ContactProfileTransformer";
export * from "./ContactRoleTransformer";
export * from "./ContactTransformer";
export * from "./ContentTransformer";
export * from "./NoticeTransformer";
export * from "./PaymentTransformer";
export * from "./SegmentTransformer";
12 changes: 8 additions & 4 deletions apps/backend/src/api/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export * from "./auth.js";
export * from "./objects.js";
export * from "./rules.js";
export * from "./validation.js";
/**
* @file Automatically generated by barrelsby.
*/

export * from "./auth";
export * from "./objects";
export * from "./rules";
export * from "./validation";
Loading
Loading