-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodel.user.js
41 lines (33 loc) · 1.06 KB
/
model.user.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
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// mongoose.plugin(require('mongoose-unique-validator'), {
// type: 'phoneNumber already exists.',
// });
let WalletSchema = new Schema({
address: { type: String, required: true },
currency: { type: String, required: true },
pkey: { type: String, required: true },
});
let UserSchema = new Schema({
phoneNumber: { type: String, required: true, unique: true },
city: { type: String, required: true },
state: { type: String, required: true },
zipCode: { type: String, required: true },
country: { type: String, required: true },
pin: { type: Number, required: false },
wallets: [WalletSchema],
});
//Find account by currency and type
UserSchema.methods.findAccount = function(currency, type) {
const account = this.accounts.filter(a => {
return (
a.currency === currency.toLowerCase() && a.type === type.toLowerCase()
);
});
if (account.length > 0) {
return account[0];
}
return null;
};
// Export the model
module.exports = mongoose.model('User', UserSchema);