-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs-data.js
46 lines (35 loc) · 1004 Bytes
/
jobs-data.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
var mongoose = require("mongoose");
var Promise = require("bluebird");
var jobModel = require("./models/Job.js");
var Job = mongoose.model('Job');
var findJobs = function(query) {
return Promise.cast(Job.find(query).exec());
};
var createJob = Promise.promisify(Job.create, Job);
var jobs = [{
title: 'Waiter',
description: 'You will be putting food on peoples tables'
}, {
title: 'Cook',
description: 'You will be making bagels'
}, {
title: 'Programmer',
description: 'You will be making web apps'
}, {
title: 'Axe Maker',
description: 'Axes'
}];
// exports
exports.findJobs = findJobs;
exports.jobs = jobs;
exports.seedJobs = function() {
return findJobs({}).then(function(collection) {
if (collection.length === 0) {
return Promise.map(jobs, function(job) {
return createJob(job);
});
}
});
};
exports.connectDB = Promise.promisify(mongoose.connect, mongoose);
exports.saveJob = createJob;