박권수

feat. lib and models is featured

1 +exports.processing = async(data) => {
2 +
3 +}
...\ No newline at end of file ...\ No newline at end of file
1 +const mqtt = require('mqtt');
2 +
3 +exports.mqttOn = async(hosting, topic) => {
4 + const client = mqtt.connect(hosting);
5 + client.subscribe(topic);
6 +}
...\ No newline at end of file ...\ No newline at end of file
1 +const axios = require('axios');
2 +
3 +const SERVICE_KEY = "tNd%2FZ0MMJA5NZrU9nA5IVTKkhpz6N3j1OGpFT0PmbcCOVEZbpR9PYiNHuD9rLuSsyMWkTXPqHsHLWoxlW%2BVVrg%3D%3D"
4 +const url = "http://apis.data.go.kr/1471000/DrbEasyDrugInfoService/getDrbEasyDrugList";
5 +
6 +const updateMedicineInfo = async() => {
7 + const queryParams = '?' + encodeURIComponent('ServiceKey') + '=' + SERVICE_KEY;
8 + const pageNum36 = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(1)
9 + const pageNum37 = '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent(2);
10 + const numOfItem = '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent(2);
11 + const output = '&' + encodeURIComponent('type') + '=' + encodeURIComponent('json');
12 +
13 + const result36 = await axios.get(url + queryParams + pageNum36 + numOfItem + output);
14 + const result37 = await axios.get(url + queryParams + pageNum37 + numOfItem + output);
15 +
16 + console.log(result36.data.body.items);
17 + console.log(result37.data.body.items);
18 +}
19 +
20 +updateMedicineInfo();
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const HubSchema = new Schema ({
6 + hubId : { type : Number, required : true },
7 + userId : { type : String, default : null },
8 + hosting : Object
9 +});
10 +
11 +HubSchema.methods.setHubHost = async(hosting) => {
12 + this.hosting = hosting;
13 +}
14 +
15 +HubSchema.methods.getHubHost = async() => {
16 + return this.hosting;
17 +}
18 +
19 +HubSchema.methods.setHub_UserId = async(userId) => {
20 + this.userId = userId;
21 +}
22 +
23 +HubSchema.methods.getHub_UserId = async() => {
24 + return this.userId;
25 +}
26 +
27 +module.exports = mongoose.model('Hub', HubSchema);
...\ No newline at end of file ...\ No newline at end of file
1 +const mongoose = require('mongoose');
2 +const bycrypt = require('bcrypt');
3 +const jwt = require('jsonwebtoken');
4 +
5 +const Schema = mongoose.Schema;
6 +
7 +const UserSchema = new Schema({
8 + userId : { type: String, require : true },
9 + hashedPassword : { type : String, default : null }
10 +})
11 +
12 +UserSchema.methods.setPassword = async(password) => {
13 + const hash = await bycrypt(password, 10);
14 + this.hashedPassword = hash;
15 +}
16 +
17 +UserSchema.methods.checkPassword = async(password) => {
18 + const result = await bycrypt.compare(password, this.hashedPassword)
19 + return result;
20 +}
21 +
22 +UserSchema.statics.findByUserId = async(userId) => {
23 + return this.findOne({userId});
24 +}
25 +
26 +UserSchema.methods.generateToken = () => {
27 + const token = jwt.sign (
28 + {
29 + _id : this._id,
30 + userId : this.userId
31 + },
32 + process.env.JWT_SECRET,
33 + { expiresIn : '30d' }
34 + );
35 + return token;
36 +}
37 +
38 +module.exports = mongoose.model("User", UserSchema);
...\ No newline at end of file ...\ No newline at end of file