2015-07-14 21:38:19 -07:00
|
|
|
import debugFactory from 'debug';
|
|
|
|
import assign from 'object.assign';
|
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
const debug = debugFactory('fcc:services:hikes');
|
2015-07-14 21:38:19 -07:00
|
|
|
|
2015-07-13 00:25:01 -07:00
|
|
|
export default function hikesService(app) {
|
|
|
|
const Challenge = app.models.Challenge;
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: 'hikes',
|
2016-01-27 11:34:44 -08:00
|
|
|
read: (req, resource, { dashedName } = {}, config, cb) => {
|
2015-07-13 18:42:14 -07:00
|
|
|
const query = {
|
2016-04-14 21:19:37 -07:00
|
|
|
where: {
|
|
|
|
challengeType: '6',
|
|
|
|
isComingSoon: false
|
|
|
|
},
|
2015-12-22 19:28:40 -08:00
|
|
|
order: ['order ASC', 'suborder ASC' ]
|
2015-07-13 18:42:14 -07:00
|
|
|
};
|
2015-07-14 21:38:19 -07:00
|
|
|
|
2016-01-27 11:34:44 -08:00
|
|
|
debug('dashedName', dashedName);
|
|
|
|
if (dashedName) {
|
2015-07-14 21:38:19 -07:00
|
|
|
assign(query.where, {
|
2016-01-27 11:34:44 -08:00
|
|
|
dashedName: { like: dashedName, options: 'i' }
|
2015-07-14 21:38:19 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
debug('query', query);
|
2015-07-13 18:42:14 -07:00
|
|
|
Challenge.find(query, (err, hikes) => {
|
2015-07-13 00:25:01 -07:00
|
|
|
if (err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
2016-03-02 20:54:14 -08:00
|
|
|
return cb(null, hikes.map(hike => hike.toJSON()));
|
2015-07-13 00:25:01 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|