-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationProvider.js
More file actions
65 lines (48 loc) · 1.69 KB
/
ApplicationProvider.js
File metadata and controls
65 lines (48 loc) · 1.69 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
var db = require('./config/db');
var mongoose = require('mongoose');
var json = require('jsonify');
var Schema = mongoose.Schema, ObjectID = Schema.ObjectId;
var Application = new Schema({
type : String,
name : {type: String, required: true},
email : {type: String, required: true},
about : {type: String, required: true},
req : {type: String, required: true},
egg : String, // set this to any value you want for extra credit
geeklist : String,
stackoverflow : String,
github : String,
coderwall : String,
urls : [String],
rawdata : String
});
mongoose.connect('mongodb://' + db.user + ':' + db.pass + '@' + db.host + ':' + db.port + '/' + db.name);
mongoose.model('Application', Application);
var Application = mongoose.model('Application');
ApplicationProvider = function(){};
ApplicationProvider.prototype.getApplications = function (callback){
Application.find({}, function (error, apps) {
callback(null, apps);
});
};
ApplicationProvider.prototype.saveApp = function (rawdata, type, callback) {
console.log('raw data ' + rawdata);
var data = json.parse(rawdata);
var app = new Application();
app.rawdata = rawdata;
app.name = data.name;
app.email = data.email;
app.about = data.about;
app.req = data.req;
app.type = type;
app.egg = data.egg;
app.geeklist = data.geeklist;
app.stackoverflow = data.stackoverflow;
app.github = data.github;
app.coderwall = data.coderwall;
app.save(function (err) {
console.log('saved!');
callback(err);
});
};
exports.ApplicationProvider = ApplicationProvider;