Fix jobs list and refetching

This commit is contained in:
Berkeley Martinez
2016-02-29 17:04:45 -08:00
parent a173ddf375
commit 5dab7fddbc
3 changed files with 10 additions and 7 deletions

View File

@ -32,7 +32,7 @@ const bindableActions = {
const fetchOptions = {
fetchAction: 'fetchJobs',
isPrimed({ jobs }) {
return !!jobs.length;
return jobs.length > 1;
}
};

View File

@ -16,7 +16,7 @@ export default ({ services }) => ({ dispatch }) => next => {
const { payload: id } = action;
const data = { service: 'jobs' };
if (id) {
data.id = id;
data.params = { id };
}
return services.readService$(data)

View File

@ -23,17 +23,20 @@ export default function getJobServices(app) {
});
Job.create(job, (err, savedJob) => {
cb(err, savedJob);
cb(err, savedJob.toJSON());
});
},
read(req, resource, params, config, cb) {
const id = params ? params.id : null;
console.log('params', params);
if (id) {
return Job.findById(id, cb);
return Job.findById(id)
.then(job => cb(null, job.toJSON()))
.catch(cb);
}
Job.find(whereFilt, (err, jobs) => {
cb(err, jobs.map(job => job.toJSON()));
});
Job.find(whereFilt)
.then(jobs => cb(null, jobs.map(job => job.toJSON())))
.catch(cb);
}
};
}