freeCodeCamp/server/services/job.js

42 lines
922 B
JavaScript
Raw Normal View History

const whereFilt = {
where: {
isFilled: false,
isPaid: true,
isApproved: true
},
order: 'postedOn DESC'
};
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
});
2016-03-03 04:54:14 +00:00
return Job.create(job, (err, savedJob) => {
2016-03-01 01:04:45 +00:00
cb(err, savedJob.toJSON());
});
},
read(req, resource, params, config, cb) {
const id = params ? params.id : null;
if (id) {
2016-03-01 01:04:45 +00:00
return Job.findById(id)
.then(job => cb(null, job.toJSON()))
.catch(cb);
}
2016-03-03 04:54:14 +00:00
return Job.find(whereFilt)
2016-03-01 01:04:45 +00:00
.then(jobs => cb(null, jobs.map(job => job.toJSON())))
.catch(cb);
2015-07-25 22:42:03 +00:00
}
};
}