forked from afadil/wealthfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.ts
84 lines (80 loc) · 2.4 KB
/
schemas.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as z from 'zod';
export const newAccountSchema = z.object({
id: z.string().uuid().optional(),
name: z
.string()
.min(2, {
message: 'Name must be at least 2 characters.',
})
.max(50, {
message: 'Name must not be longer than 50 characters.',
}),
group: z.string().optional(),
isDefault: z.boolean().optional(),
isActive: z.boolean().optional(),
accountType: z.enum(['SECURITIES', 'CASH', 'CRYPTOCURRENCY']),
currency: z.string({ required_error: 'Please select a currency.' }),
});
export const newGoalSchema = z.object({
id: z.string().uuid().optional(),
title: z.string(),
description: z.string().optional(),
targetAmount: z.coerce
.number({
required_error: 'Please enter a valid target amount.',
invalid_type_error: 'Target amount must be a positive number.',
})
.min(0, { message: 'Target amount must be a positive number.' }),
yearlyContribution: z.number().optional(),
deadline: z.date().optional(),
isAchieved: z.boolean().optional(),
});
export const newActivitySchema = z.object({
id: z.string().uuid().optional(),
accountId: z.string().min(1, { message: 'Please select an account.' }),
activityDate: z.date(),
currency: z.string().min(1, { message: 'Currency is required' }),
fee: z.coerce
.number({
required_error: 'Please enter a valid fee.',
invalid_type_error: 'Fee must be a positive number.',
})
.min(0, { message: 'Fee must be a non-negative number.' }),
isDraft: z.boolean(),
quantity: z.coerce
.number({
required_error: 'Please enter a valid quantity.',
invalid_type_error: 'Quantity must be a number.',
})
.min(0, { message: 'Quantity must be a non-negative number.' }),
assetId: z.string().min(1, { message: 'Asset ID is required' }),
activityType: z.enum(
[
'BUY',
'SELL',
'DIVIDEND',
'INTEREST',
'DEPOSIT',
'WITHDRAWAL',
'TRANSFER_IN',
'TRANSFER_OUT',
'CONVERSION_IN',
'CONVERSION_OUT',
'FEE',
'TAX',
'SPLIT',
],
{
errorMap: () => {
return { message: 'Please select an activity type.' };
},
},
),
unitPrice: z.coerce
.number({
required_error: 'Please enter a valid price.',
invalid_type_error: 'Price must be a positive number.',
})
.positive({ message: 'Price must be a positive number.' }),
comment: z.string().optional(),
});