-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.js
96 lines (90 loc) · 2.02 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const moment = require('moment')
const path = require("path");
const PounchDB = require("pouchdb");
const db = new PounchDB(
path.join(__dirname.replace("\\resources\\app.asar", ""), "eventDB")
);
class DatabaseOps {
async getAllData() {
try {
const res = await db.allDocs({
include_docs: true
});
return res
} catch (err) {
console.log(err)
return { ok: false }
}
}
async add(doc_id) {
try {
const res = await db.post(doc_id);
return res;
} catch (err) {
console.log(err);
return { ok: false }
}
}
async delete(doc_id) {
try {
const doc = await db.get(doc_id);
const res = await db.remove(doc);
return res
} catch (err) {
console.log(err);
return { ok: false }
}
}
async updateDoneTask(doc_id) {
try {
const doc = await db.get(doc_id);
const res = await db.put({
_id: doc_id,
_rev: doc._rev,
title: doc.title,
detail: doc.detail,
start: doc.start,
time: doc.time,
status: "done",
done: moment().format("YYYY-MM-DD hh:mm")
});
return res
} catch (err) {
console.log(err);
return { ok: false }
}
}
async deleteBulk(data) {
var docs = data.map((t) => { return { _id: t._id, _rev: t._rev, _deleted: true } })
// console.log(docs)
try {
const res = await db.bulkDocs(docs);
return res
} catch (err) {
console.log(err);
return { ok: false }
}
}
async updateDateTask(data) {
const doc_id = data.id
const doc_start = data.start
try {
const doc = await db.get(doc_id);
const res = await db.put({
_id: doc_id,
_rev: doc._rev,
title: doc.title,
detail: doc.detail,
status: doc.status,
start: doc_start,
time: doc.time,
color: doc.color
});
return res
} catch (err) {
console.log(err);
return { ok: false }
}
}
}
module.exports = DatabaseOps;