2015-10-16 06:43:24 +00:00
|
|
|
const whereFilt = {
|
|
|
|
where: {
|
|
|
|
isFilled: false,
|
|
|
|
isPaid: true,
|
|
|
|
isApproved: true
|
2015-11-20 01:31:00 +00:00
|
|
|
},
|
|
|
|
order: 'postedOn DESC'
|
2015-10-16 06:43:24 +00:00
|
|
|
};
|
|
|
|
|
2015-07-25 22:42:03 +00:00
|
|
|
export default function getJobServices(app) {
|
|
|
|
const { Job } = app.models;
|
|
|
|
|
|
|
|
return {
|
2015-09-10 23:26:41 +00:00
|
|
|
name: 'jobs',
|
2015-10-14 06:05:31 +00:00
|
|
|
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());
|
2015-10-14 06:05:31 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
read(req, resource, params, config, cb) {
|
2015-09-10 23:26:41 +00:00
|
|
|
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);
|
2015-09-10 23:26:41 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|