박권수

db. update medicine data

......@@ -4,6 +4,7 @@ const bodyparser = require('koa-bodyparser');
const Mongoose = require('mongoose');
const api = require('./src/api');
const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo');
require('dotenv').config();
const { SERVER_PORT, MONGO_URL } = process.env;
......@@ -12,6 +13,8 @@ const app = new Koa();
const router = new Router();
updateMedicineInfo.updateMedicineInfo();
Mongoose.connect(MONGO_URL, {
useNewUrlParser : true,
useUnifiedTopology: true,
......
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const MedicineSchema = new Schema ({
medicineId : { type : Number, required : true, unique : true },
name : { type : String, required : true },
company : String,
target : { type : String, required : true },
dosage : { type : String, required : true },
warn : { type : String, required : true },
antiEffect : String
})
MedicineSchema.statics.findByName = async function(name) {
const all = await this.find().exec();
const result = all.filter(item => {
return item.name.includes(name)
});
return result;
};
MedicineSchema.statics.findByCompany = async function(company) {
const all = await this.find().exec();
const result = all.filter(item => {
return item.company.includes(company)
});
return result;
};
MedicineSchema.statics.findByTarget = async function(target) {
const all = await this.find().exec();
const result = all.filter(item => {
return item.target.includes(target)
});
return result;
};
MedicineSchema.statics.findById = async function(medicineId) {
return this.findOne({ medicineId })
}
module.exports = mongoose.model('Medicine', MedicineSchema);
\ No newline at end of file
......