This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlessons.js
94 lines (76 loc) · 2.03 KB
/
lessons.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
// Generated by CoffeeScript 1.10.0
(function() {
var Day, Lessons, Schema, closeDB, db, filter_day, filter_object, filter_room, mongoose, my_date, query_find, query_find_one, tress;
mongoose = require('mongoose');
tress = require('tress');
my_date = require('./my_date');
Schema = mongoose.Schema;
mongoose.Promise = global.Promise;
mongoose.connect('mongodb://localhost:27017/MySchedule');
Day = require('./structure.js').Day;
Lessons = require('./structure.js').Lessons;
db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
query_find = function(query, callback) {
return Day.find(query, function(err, data) {
if (err) {
callback(err);
}
return callback(null, data);
});
};
query_find_one = function(query, callback) {
return Day.findOne(query, function(err, data) {
if (err) {
callback(err);
}
return callback(null, data);
});
};
closeDB = function(callback) {
db.close();
return console.log('DB MySchedule close');
};
filter_day = function(day_week_code, callback) {
return query_find_one({
day_week_code: day_week_code
}, function(err, data) {
if (err) {
callback(err);
}
return callback(null, data);
});
};
filter_room = function(string_room, callback) {
string_room = string_room.toString().toUpperCase();
return query_find({
lessons: {
$elemMatch: {
class_room: string_room
}
}
}, function(err, data) {
if (err) {
callback(err);
}
return callback(null, data);
});
};
filter_object = function(obj_query, callback) {
if (typeof obj_query !== object) {
callback('no object');
}
return query_find(obj_query, function(err, data) {
if (err) {
callback(err);
}
return callback(null, data);
});
};
module.exports = {
day: filter_day,
room: filter_room,
object: filter_object,
close: closeDB
};
}).call(this);