-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.js
More file actions
62 lines (52 loc) · 1.26 KB
/
structs.js
File metadata and controls
62 lines (52 loc) · 1.26 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import * as s from 'superstruct';
import isEmail from 'is-email';
import isUuid from 'is-uuid';
const CATEGORIES = [
'FASHION',
'BEAUTY',
'SPORTS',
'ELECTRONICS',
'HOME_INTERIOR',
'HOUSEHOLD_SUPPLIES',
'KITCHENWARE',
];
const STATUSES = ['PENDING', 'COMPLETE'];
const Uuid = s.define('Uuid', (value) => isUuid.v4(value));
export const CreateUser = s.object({
email: s.define('Email', isEmail),
firstName: s.size(s.string(), 1, 30),
lastName: s.size(s.string(), 1, 30),
address: s.string(),
userPreference: s.object({
receiveEmail: s.boolean(),
}),
});
export const PatchUser = s.partial(CreateUser);
export const CreateProduct = s.object({
name: s.size(s.string(), 1, 60),
description: s.string(),
category: s.enums(CATEGORIES),
price: s.min(s.number(), 0),
stock: s.min(s.integer(), 0),
});
export const PatchProduct = s.partial(CreateProduct);
export const CreateOrder = s.object({
userId: Uuid,
orderItems: s.size(
s.array(
s.object({
productId: Uuid,
unitPrice: s.min(s.number(), 0),
quantity: s.min(s.integer(), 1),
})
),
1,
Infinity
),
});
export const PatchOrder = s.object({
status: s.enums(STATUSES),
});
export const PostSavedProduct = s.object({
productId: Uuid,
});