-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
54 lines (48 loc) · 865 Bytes
/
db.js
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
const mongoose = require("mongoose");
const { string } = require("zod");
mongoose.connect("Your_Connection_String");
const userSchema = new mongoose.Schema({
username: {
type: String,
required: true,
unique: true,
trim: true,
lowercase: true,
minLength: 3,
maxLength: 30,
},
password: {
type: String,
required: true,
minLength: 6,
},
firstName: {
type: String,
required: true,
trim: true,
maxLength: 50,
},
lastName: {
type: String,
required: true,
trim: true,
maxLength: 50,
},
});
const User = mongoose.model("User", userSchema);
const accountSchema = new mongoose.Schema({
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
balance: {
type: Number,
required: true,
},
});
const Account = mongoose.model("Account", accountSchema);
module.exports = {
User,
Account,
};