Skip to content
Merged
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
24 changes: 24 additions & 0 deletions apps/backend/src/donations/dtos/create-donation.domain.ts
Copy link
Collaborator

@thaninbew thaninbew Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job on all the files! this looks good. I wrote it in really fine print but I think it would be nice to also have a minimal "amount parser" normalization helper. It'd turn a string/number into a valid number. For invalid cases like a string input, it'd turn that into a 0. This might sound bad but it's to avoid crashes and we will rely on other validations before this to ensure we're not experiencing silent failures.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
DonationType,
NormalizedInterval,
} from '../../util/donations/donations.util';

export class CreateDonationDTO {
firstName: string;

lastName: string;

email: string;

amount: number;

isAnonymous: boolean = false;

donationType: DonationType;

recurringInterval?: NormalizedInterval | null;

dedicationMessage?: string | null;

showDedicationPublicly?: boolean = false;
}
11 changes: 11 additions & 0 deletions apps/backend/src/donations/dtos/donation-response.domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { CreateDonationDTO } from './create-donation.domain';

export class DonationResponseDTO {
id: number;

stored: CreateDonationDTO;

createdAt: string;

updatedAt: string;
}
3 changes: 3 additions & 0 deletions apps/backend/src/donations/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './create-donation.domain';
export * from './donation-response.domain';
export * from './public-donation.domain';
17 changes: 17 additions & 0 deletions apps/backend/src/donations/dtos/public-donation.domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { DonationType } from '../../util/donations/donations.util';

export class PublicDonationDTO {
id: number;

amount: number;

donationType: DonationType;

dedicationMessage?: string | null;

isAnonymous: boolean;

donorName?: string | null;

createdAt: string;
}
37 changes: 37 additions & 0 deletions apps/backend/src/util/donations/donations.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export const donationTypes = ['one_time', 'recurring'] as const;
export type DonationType = (typeof donationTypes)[number];
export const recurringIntervals = [
'monthly',
'bimonthly',
'quarterly',
'annually',
'weekly',
] as const;
export type NormalizedInterval = (typeof recurringIntervals)[number];

export function normalizeInterval(
input: string | null,
): NormalizedInterval | null {
if (!input) {
return null;
}

const normalized = input.toLowerCase().trim();

return (recurringIntervals as readonly string[]).includes(normalized)
? (normalized as NormalizedInterval)
: null;
}

export function normalizeDonorName(
input: string | null,
anonymous: boolean,
): string | null {
return anonymous ? null : input;
}

export function normalizeDonationAmount(amount: string | number): number {
const num = Number(amount);

return isFinite(num) ? num : 0;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"nodemon": "^3.0.1",
"nx": "^16.8.1",
"nx-cloud": "^16.4.0",
"prettier": "^2.6.2",
"prettier": "^3.6.2",
"ts-jest": "^29.1.0",
"typescript": "^5.1.3",
"vite": "^4.3.9",
Expand Down
18 changes: 5 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6126,14 +6126,7 @@ debug@^3.1.0, debug@^3.2.6, debug@^3.2.7:
dependencies:
ms "^2.1.1"

debug@^4.3.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.1.tgz#e5a8bc6cbc4c6cd3e64308b0693a3d4fa550189b"
integrity sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==
dependencies:
ms "^2.1.3"

debug@^4:
debug@^4, debug@^4.3.1:
version "4.4.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.4.1.tgz#e5a8bc6cbc4c6cd3e64308b0693a3d4fa550189b"
integrity sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ==
Expand Down Expand Up @@ -9966,7 +9959,6 @@ ms@2.1.2:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@2.1.3, ms@^2.1.1, ms@^2.1.3:
ms@2.1.3, ms@^2.1.1, ms@^2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
Expand Down Expand Up @@ -11083,10 +11075,10 @@ prelude-ls@^1.2.1:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==

prettier@^2.6.2:
version "2.8.8"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
prettier@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.6.2.tgz#ccda02a1003ebbb2bfda6f83a074978f608b9393"
integrity sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==

pretty-bytes@^5.6.0:
version "5.6.0"
Expand Down