박권수

db. update medicine data

...@@ -4,6 +4,7 @@ const bodyparser = require('koa-bodyparser'); ...@@ -4,6 +4,7 @@ const bodyparser = require('koa-bodyparser');
4 4
5 const Mongoose = require('mongoose'); 5 const Mongoose = require('mongoose');
6 const api = require('./src/api'); 6 const api = require('./src/api');
7 +const updateMedicineInfo = require('./src/lib/UpdatingMedicineInfo');
7 8
8 require('dotenv').config(); 9 require('dotenv').config();
9 const { SERVER_PORT, MONGO_URL } = process.env; 10 const { SERVER_PORT, MONGO_URL } = process.env;
...@@ -12,6 +13,8 @@ const app = new Koa(); ...@@ -12,6 +13,8 @@ const app = new Koa();
12 const router = new Router(); 13 const router = new Router();
13 14
14 15
16 +updateMedicineInfo.updateMedicineInfo();
17 +
15 Mongoose.connect(MONGO_URL, { 18 Mongoose.connect(MONGO_URL, {
16 useNewUrlParser : true, 19 useNewUrlParser : true,
17 useUnifiedTopology: true, 20 useUnifiedTopology: true,
......
1 +const mongoose = require('mongoose');
2 +
3 +const Schema = mongoose.Schema;
4 +
5 +const MedicineSchema = new Schema ({
6 + medicineId : { type : Number, required : true, unique : true },
7 + name : { type : String, required : true },
8 + company : String,
9 + target : { type : String, required : true },
10 + dosage : { type : String, required : true },
11 + warn : { type : String, required : true },
12 + antiEffect : String
13 +})
14 +
15 +MedicineSchema.statics.findByName = async function(name) {
16 + const all = await this.find().exec();
17 + const result = all.filter(item => {
18 + return item.name.includes(name)
19 + });
20 +
21 + return result;
22 +};
23 +
24 +MedicineSchema.statics.findByCompany = async function(company) {
25 + const all = await this.find().exec();
26 + const result = all.filter(item => {
27 + return item.company.includes(company)
28 + });
29 +
30 + return result;
31 +};
32 +
33 +MedicineSchema.statics.findByTarget = async function(target) {
34 + const all = await this.find().exec();
35 + const result = all.filter(item => {
36 + return item.target.includes(target)
37 + });
38 +
39 + return result;
40 +};
41 +
42 +MedicineSchema.statics.findById = async function(medicineId) {
43 + return this.findOne({ medicineId })
44 +}
45 +
46 +
47 +module.exports = mongoose.model('Medicine', MedicineSchema);
...\ No newline at end of file ...\ No newline at end of file
......