freeCodeCamp/server/services/job.js

39 lines
776 B
JavaScript
Raw Normal View History

const whereFilt = {
where: {
isFilled: false,
isPaid: true,
isApproved: true
}
};
2015-07-25 22:42:03 +00:00
export default function getJobServices(app) {
const { Job } = app.models;
return {
name: 'jobs',
create(req, resource, { job } = {}, body, config, cb) {
if (!job) {
return cb(new Error('job creation should get a job object'));
}
2015-10-29 23:46:26 +00:00
Object.assign(job, {
isPaid: false,
isApproved: false
});
Job.create(job, (err, savedJob) => {
cb(err, savedJob);
});
},
read(req, resource, params, config, cb) {
const id = params ? params.id : null;
if (id) {
return Job.findById(id, cb);
}
Job.find(whereFilt, (err, jobs) => {
2015-07-25 22:42:03 +00:00
cb(err, jobs);
});
}
};
}