-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.js
63 lines (59 loc) · 1.8 KB
/
models.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
function getAllArticlesforSitemap(callback) {
global.db.collection('posts').find({}).sort({
date: -1
}).toArray((err, result) => {
if (err) {
return callback(true, 'error retrieving posts.');
}
callback(false, result);
});
}
function getAllCoursesforSitemap(callback) {
global.db.collection('courses').find({isPublished: true}).sort({
date: -1
}).toArray((err, result) => {
if (err) {
return callback(true, 'error retrieving courses.');
}
let courseIds = [];
result.forEach((singleCourse) => {
courseIds.push(singleCourse.id);
});
global.db.collection('lessons').find({courseId : { $in: courseIds } } ).toArray((err, lessonData) => {
if (err) {
return callback(true, 'error retrieving courses.');
}
let response = {
course: result,
lessons: lessonData
}
callback(false, response);
});
});
}
function getAllAuthorsforSitemap(callback) {
global.db.collection('authors').find({}).sort({
id: -1
}).toArray((err, result) => {
if (err) {
return callback(true, 'error retrieving users.');
}
callback(false, result);
});
}
function getAllBitsforSitemap(callback) {
global.db.collection('bits').find({}).sort({
date: -1
}).toArray((err, result) => {
if (err) {
return callback(true, 'error retrieving bits.');
}
callback(false, result);
});
}
module.exports = {
getAllArticlesforSitemap: getAllArticlesforSitemap,
getAllCoursesforSitemap: getAllCoursesforSitemap,
getAllAuthorsforSitemap: getAllAuthorsforSitemap,
getAllBitsforSitemap: getAllBitsforSitemap,
}