-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
189 lines (151 loc) · 3.5 KB
/
types.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import FormidableLib from 'formidable';
import { ValidationError } from 'joi';
export type Product = {
_id: string;
name: string;
category_id: string;
src: string;
price: number;
quantity: number;
total_quantity: number;
description: string;
recommend: boolean;
};
export type ProductWithCategory = Product & {
category_id: { name: string };
};
export type ErrorDetail = {
message: string;
name?: string;
};
export type ProductName = {
name: string;
};
export type ProductNameErrorDetail = ErrorDetail & {
name?: keyof ProductName;
};
export type ProductFields = ProductName & {
src?: string;
price: number;
quantity: number;
total_quantity: number;
description: string;
recommend: boolean;
category_id: string;
};
export type Category = {
_id: string;
name: string;
};
export type ProductErrorDetail = ErrorDetail & {
name?: keyof ProductFields;
};
export type ApiResponse = {
success: boolean;
message: string;
errors?: ErrorDetail[];
};
export type User = {
_id: string;
name: string;
email: string;
isManager: boolean;
};
export type UserEmail = {
email: string;
};
export type UserEmailErrorDetail = ErrorDetail & {
name?: keyof UserEmail;
};
export type UserLogin = UserEmail & { password: string };
export type UserSignup = UserEmail & {
name: string;
password: string;
repeat_password: string;
};
export type UserPermissions = { isManager: boolean };
export type LabelMessage = { success: boolean; message: string };
export type UserAuth = {
_id: string;
name: string;
isAdmin: boolean;
isManager: boolean;
};
export type UserSession = {
isAuth: boolean;
user: UserAuth | null;
needRefresh?: boolean;
};
type dataType = 'data' | 'error' | 'field' | 'fileBegin' | 'file' | 'progress';
// fixing dataType
export declare class Formidable extends FormidableLib {
emit(name: dataType, data: FormidableLib.EmitData | ValidationError): void;
}
export type CategoryName = {
name: string;
};
export type CategoryNameErrorDetail = ErrorDetail & {
name?: keyof CategoryName;
};
export type OrderSubmit = {
tel: string;
address: string;
};
export type OrderItem = {
product_id: string;
count: number;
};
export type OrderStatus = {
status: 'processing' | 'inDelivery' | 'canceled' | 'completed';
};
export type OrderStatusErrorDetail = ErrorDetail & {
name?: keyof OrderStatus;
};
export type OrderNumber = {
number: string;
};
export type OrderNumberErrorDetail = ErrorDetail & {
name?: keyof OrderNumber;
};
export type OrderFields = {
info: OrderSubmit;
items: OrderItem[];
};
export type Order = {
_id: string;
user: {
name: string;
email: string;
};
number: string;
total_price: number;
status: 'processing' | 'inDelivery' | 'canceled' | 'completed';
items: {
count: number;
product: { name: string; price: number; quantity: number };
}[];
address: string;
tel: string;
orderedAt: Date;
completedAt?: Date;
};
export type UserOrders = { orders: Order[]; count: number };
export type ManagementOrders = { orders: Order[]; count: number };
export type OrderMatchFilter = {
status: ('processing' | 'inDelivery' | 'canceled' | 'completed')[];
};
export type OrderSortFilter = {
orderedAt?: -1 | 1;
};
export type ProductMatchFilter = {
recommend?: boolean;
};
export type ProductSortFilter = { price?: 1 | -1; total_quantity?: 1 | -1 };
export type SessionAuth = {
isAuth: boolean;
user: UserAuth | null;
};
export type RefreshClaims = {
user_id: string;
refresh_token: string;
};