박권수

db. models implemented

1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const BottleSchema = new Schema ({
6 + bottleId : { type : String, required : true, unique : true },
7 + balance : Number,
8 + recentOpen : Date,
9 + medicineId : Number,
10 + hubId : Number
11 +})
12 +
13 +module.exports = mongoose.model('Bottle', BottleSchema);
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,24 +3,28 @@ const mongoose = require('mongoose'); ...@@ -3,24 +3,28 @@ const mongoose = require('mongoose');
3 const Schema = mongoose.Schema; 3 const Schema = mongoose.Schema;
4 4
5 const HubSchema = new Schema ({ 5 const HubSchema = new Schema ({
6 - hubId : { type : Number, required : true }, 6 + hubId : { type : Number, required : true, unique : true },
7 + hosting : Object,
7 userId : { type : String, default : null }, 8 userId : { type : String, default : null },
8 - hosting : Object
9 }); 9 });
10 10
11 -HubSchema.methods.setHubHost = async(hosting) => { 11 +HubSchema.statics.findByHubId = function(hubId) {
12 + return this.findOne({ hubId })
13 +}
14 +
15 +HubSchema.methods.setHubHost = function(hosting) {
12 this.hosting = hosting; 16 this.hosting = hosting;
13 } 17 }
14 18
15 -HubSchema.methods.getHubHost = async() => { 19 +HubSchema.methods.getHubHost = function() {
16 return this.hosting; 20 return this.hosting;
17 } 21 }
18 22
19 -HubSchema.methods.setHub_UserId = async(userId) => { 23 +HubSchema.methods.setHub_UserId = function(userId) {
20 this.userId = userId; 24 this.userId = userId;
21 } 25 }
22 26
23 -HubSchema.methods.getHub_UserId = async() => { 27 +HubSchema.methods.getHub_UserId = function() {
24 return this.userId; 28 return this.userId;
25 } 29 }
26 30
......
...@@ -5,25 +5,25 @@ const jwt = require('jsonwebtoken'); ...@@ -5,25 +5,25 @@ const jwt = require('jsonwebtoken');
5 const Schema = mongoose.Schema; 5 const Schema = mongoose.Schema;
6 6
7 const UserSchema = new Schema({ 7 const UserSchema = new Schema({
8 - userId : { type: String, require : true }, 8 + userId : { type: String, require : true, unique : true },
9 hashedPassword : { type : String, default : null } 9 hashedPassword : { type : String, default : null }
10 }) 10 })
11 11
12 -UserSchema.methods.setPassword = async(password) => { 12 +UserSchema.methods.setPassword = async function(password) {
13 const hash = await bycrypt(password, 10); 13 const hash = await bycrypt(password, 10);
14 this.hashedPassword = hash; 14 this.hashedPassword = hash;
15 } 15 }
16 16
17 -UserSchema.methods.checkPassword = async(password) => { 17 +UserSchema.methods.checkPassword = async function(password) {
18 const result = await bycrypt.compare(password, this.hashedPassword) 18 const result = await bycrypt.compare(password, this.hashedPassword)
19 return result; 19 return result;
20 } 20 }
21 21
22 -UserSchema.statics.findByUserId = async(userId) => { 22 +UserSchema.statics.findByUserId = async function(userId) {
23 return this.findOne({userId}); 23 return this.findOne({userId});
24 } 24 }
25 25
26 -UserSchema.methods.generateToken = () => { 26 +UserSchema.methods.generateToken = function() {
27 const token = jwt.sign ( 27 const token = jwt.sign (
28 { 28 {
29 _id : this._id, 29 _id : this._id,
......