박권수

db. models implemented

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const BottleSchema = new Schema ({
bottleId : { type : String, required : true, unique : true },
balance : Number,
recentOpen : Date,
medicineId : Number,
hubId : Number
})
module.exports = mongoose.model('Bottle', BottleSchema);
\ No newline at end of file
......
......@@ -3,24 +3,28 @@ const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const HubSchema = new Schema ({
hubId : { type : Number, required : true },
hubId : { type : Number, required : true, unique : true },
hosting : Object,
userId : { type : String, default : null },
hosting : Object
});
HubSchema.methods.setHubHost = async(hosting) => {
HubSchema.statics.findByHubId = function(hubId) {
return this.findOne({ hubId })
}
HubSchema.methods.setHubHost = function(hosting) {
this.hosting = hosting;
}
HubSchema.methods.getHubHost = async() => {
HubSchema.methods.getHubHost = function() {
return this.hosting;
}
HubSchema.methods.setHub_UserId = async(userId) => {
HubSchema.methods.setHub_UserId = function(userId) {
this.userId = userId;
}
HubSchema.methods.getHub_UserId = async() => {
HubSchema.methods.getHub_UserId = function() {
return this.userId;
}
......
......@@ -5,25 +5,25 @@ const jwt = require('jsonwebtoken');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
userId : { type: String, require : true },
userId : { type: String, require : true, unique : true },
hashedPassword : { type : String, default : null }
})
UserSchema.methods.setPassword = async(password) => {
UserSchema.methods.setPassword = async function(password) {
const hash = await bycrypt(password, 10);
this.hashedPassword = hash;
}
UserSchema.methods.checkPassword = async(password) => {
UserSchema.methods.checkPassword = async function(password) {
const result = await bycrypt.compare(password, this.hashedPassword)
return result;
}
UserSchema.statics.findByUserId = async(userId) => {
UserSchema.statics.findByUserId = async function(userId) {
return this.findOne({userId});
}
UserSchema.methods.generateToken = () => {
UserSchema.methods.generateToken = function() {
const token = jwt.sign (
{
_id : this._id,
......