박권수

feat. lib and models is featured

exports.processing = async(data) => {
}
\ No newline at end of file
const mqtt = require('mqtt');
exports.mqttOn = async(hosting, topic) => {
const client = mqtt.connect(hosting);
client.subscribe(topic);
}
\ No newline at end of file
const axios = require('axios');
const SERVICE_KEY = "tNd%2FZ0MMJA5NZrU9nA5IVTKkhpz6N3j1OGpFT0PmbcCOVEZbpR9PYiNHuD9rLuSsyMWkTXPqHsHLWoxlW%2BVVrg%3D%3D"
const url = "http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList";
const updateMedicineInfo = async() => {
const queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + SERVICE_KEY;
const pageNum36 = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(1)
const pageNum37 = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(2);
const numOfItem = '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(2);
const output = '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json');
const result36 = await axios.get(url + queryParams + pageNum36 + numOfItem + output);
const result37 = await axios.get(url + queryParams + pageNum37 + numOfItem + output);
console.log(result36.data.body.items);
console.log(result37.data.body.items);
}
updateMedicineInfo();
\ No newline at end of file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const HubSchema = new Schema ({
hubId : { type : Number, required : true },
userId : { type : String, default : null },
hosting : Object
});
HubSchema.methods.setHubHost = async(hosting) => {
this.hosting = hosting;
}
HubSchema.methods.getHubHost = async() => {
return this.hosting;
}
HubSchema.methods.setHub_UserId = async(userId) => {
this.userId = userId;
}
HubSchema.methods.getHub_UserId = async() => {
return this.userId;
}
module.exports = mongoose.model('Hub', HubSchema);
\ No newline at end of file
const mongoose = require('mongoose');
const bycrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const Schema = mongoose.Schema;
const UserSchema = new Schema({
userId : { type: String, require : true },
hashedPassword : { type : String, default : null }
})
UserSchema.methods.setPassword = async(password) => {
const hash = await bycrypt(password, 10);
this.hashedPassword = hash;
}
UserSchema.methods.checkPassword = async(password) => {
const result = await bycrypt.compare(password, this.hashedPassword)
return result;
}
UserSchema.statics.findByUserId = async(userId) => {
return this.findOne({userId});
}
UserSchema.methods.generateToken = () => {
const token = jwt.sign (
{
_id : this._id,
userId : this.userId
},
process.env.JWT_SECRET,
{ expiresIn : '30d' }
);
return token;
}
module.exports = mongoose.model("User", UserSchema);
\ No newline at end of file