-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
74 lines (55 loc) · 1.55 KB
/
Copy pathdb.js
File metadata and controls
74 lines (55 loc) · 1.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var mongoose = require( 'mongoose');
var Schema = mongoose.Schema;
module.exports = function(connection){
var User = new Schema({
name: String,
A: {type : String, required : true, index: {unique: true, dropDups: true}},
hash: String,
courses: Array
})
var theModel = connection.model('User', User);
var tagsToReplace = {
'&': '&',
'<': '<',
'>': '>'
};
// Escapes HTML so that evil people can't inject mean things into the page
function escapeHtml(str) {
return str.replace(/[&<>]/g, function (tag) {
return tagsToReplace[tag] || tag;
});
}
function Store() {
// Constructor
}
// Returns a Todo by it's id
Store.prototype.find = function (params, callback) {
theModel.find(params.query, function (err, data) {
callback(err, data);
})
}
Store.prototype.get = function (id, params, callback) {
theModel.find({ _id: id },function (err, data) {
callback(err, data);
});
}
Store.prototype.create = function (data, params, callback) {
// Create our actual Todo object so that we only get what we really want
var data = new theModel(data);
data.save(function (err, data) {
//console.log(err, data);
callback(err, data);
});
}
Store.prototype.update = function (id, data, params, callback) {
theModel.update({_id: id}, data, { upsert: true }, function(err, data) {
return callback(err, data);
});
}
Store.prototype.remove = function (id, params, callback) {
theModel.findByIdAndRemove(id, function(err, data) {
return callback(err, data);
});
}
return Store;
}