1 | import MerlinDB, {Schema} from "@chrisaxxwell/merlin-db"; |
2 | |
3 | |
4 | var merlin = new MerlinDB(); |
5 | |
6 | const ClientSchema = merlin.Schema({ |
7 | name: { |
8 | type: [ String ], |
9 | unique: true, |
10 | required: [ true, 'name is required!' ], |
11 | maxLength: 100, |
12 | minLength: [ 3, '{VALUE} must have at least three characters!' ], |
13 | }, |
14 | age: { |
15 | type: [ Number ], |
16 | min: [ 3, 'The minimum for age is 3' ], |
17 | max: [ 65, '{VALUE} needs to be less than 65 year old!' ] |
18 | }, |
19 | streets: Object, |
20 | email: { |
21 | type: String, |
22 | unique: [ true, "'{VALUE}' email, already exists man!" ], |
23 | required: true, |
24 | validateEmail: [ true, "Invalid email!", ] |
25 | }, |
26 | drink: { |
27 | type: String, |
28 | required: true, |
29 | enum: { |
30 | values: [ 'whiskey', 'vodka' ], |
31 | message: 'We dont have a {VALUE} in this bar!' |
32 | } |
33 | }, |
34 | cardNumber: { |
35 | type: [ Array ], |
36 | encrypt: { |
37 | |
38 | strength: "medium" |
39 | } |
40 | }, |
41 | hobbies: { |
42 | type: [ Array ], |
43 | minList: [ 4, 'Min 4 hobbies!' ], |
44 | maxList: 10, |
45 | } |
46 | city: [ String, Array ], |
47 | birth: { |
48 | type: [ [ Date ], 'Invalid BirthDate man' ], |
49 | required: function () { |
50 | this.$message = "Too young, your birth is required!" |
51 | return this.age < 18; |
52 | }, |
53 | }, |
54 | phone: { |
55 | type: String, |
56 | validate: { |
57 | validator: function (v) { |
58 | return /\d{3}-\d{3}-\d{4}$/.test(v); |
59 | }, |
60 | |
61 | |
62 | } |
63 | }, |
64 | }) |