-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcreate-expense.dto.ts
More file actions
42 lines (33 loc) · 1.1 KB
/
Copy pathcreate-expense.dto.ts
File metadata and controls
42 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { IsArray, IsIn, IsOptional, IsString, MinLength, ValidateNested } from 'class-validator';
import { Transform, Type } from 'class-transformer';
import { CreateExpenseRequestDto, CreateExpenseSplitDto, EXPENSE_CATEGORIES } from '@fairshare/shared-types';
import { sanitizeText } from '../../common/utils/sanitize.util';
export class CreateExpenseSplitInputDto implements CreateExpenseSplitDto {
@IsString()
userId!: string;
@IsString()
owedAmountCents!: string;
@IsString()
paidAmountCents!: string;
}
export class CreateExpenseDto implements CreateExpenseRequestDto {
@IsString()
payerId!: string;
@IsString()
@MinLength(2)
@Transform(({ value }: { value: unknown }) => sanitizeText(value))
description!: string;
@IsString()
totalAmountCents!: string;
@IsString()
@IsIn(['USD', 'EUR', 'INR'])
currency!: 'USD' | 'EUR' | 'INR';
@IsOptional()
@IsString()
@IsIn([...EXPENSE_CATEGORIES])
category?: (typeof EXPENSE_CATEGORIES)[number];
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateExpenseSplitInputDto)
splits!: CreateExpenseSplitInputDto[];
}