-
Notifications
You must be signed in to change notification settings - Fork 1
/
database.js
51 lines (48 loc) · 1.35 KB
/
database.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//mongoose
const { rejects } = require('assert');
const mongoose = require('mongoose')
let todotable;
exports.Conn = () => {
return new Promise((resolve, rejects) => {
console.log("connected")
mongoose.connect('mongodb://localhost:27017/sanosh');
const TODO_SCHMEA = new mongoose.Schema({
list: {
type: String,
required: true
},
from_who: {
type: String,
required: true
}
})
todotable = new mongoose.model('todo', TODO_SCHMEA);
console.log(todotable)
resolve(todotable);
})
}
exports.items = (data) => {
return new Promise((resolve, reject) => {
todotable.find({ from_who: data }, (err, data) => {
if (err) {
reject(new Error("cannot find data"))
} else {
// console.log(data)
resolve(data)
}
})
})
}
exports.delete = (data, from) => {
return new Promise((resolve, rejects) => {
console.log("on delete data", data)
todotable.deleteOne({ list: data, from_who: from }, (err, data) => {
if (err) {
console.log("error on deleting", err)
rejects(err);
} else {
resolve(data)
}
})
})
}