-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_api.js
More file actions
59 lines (51 loc) · 1.11 KB
/
db_api.js
File metadata and controls
59 lines (51 loc) · 1.11 KB
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
const Promise = require('bluebird');
let Code = require('./models/Code.js');
let Lesson = require('./models/Lesson.js');
class DatabaseApi{
get_code(id){
return new Promise((resolve, reject) => {
Code.findOne({ where: {id: id} }).then(code => {
resolve(code);
});
});
}
add_code(code){
return new Promise((resolve, reject) => {
Code.create({code: code}).then(newcode => {
resolve(newcode.id);
});
});
}
get_lessons(){
return new Promise((resolve, reject) => {
Lesson.findAll().then(lessons => {
resolve(lessons);
});
});
}
get_lesson_by_id(id){
return new Promise((resolve, reject) => {
Lesson.findOne({ where: {id: id}}).then(lesson => {
resolve(lesson);
});
});
}
get_lesson_by_title(title){
return new Promise((resolve, reject) => {
Lesson.findOne({ where: {title: title}}).then(lesson => {
resolve(lesson);
});
});
}
add_lesson(title, content){
return new Promise((resolve, reject) => {
Lesson.create({
title: title,
content: content
}).then((newlesson)=>{
resolve(newlesson.id);
});
});
}
}
module.exports = DatabaseApi;