Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tusbar committed Oct 18, 2018
1 parent 696a422 commit ee0fe75
Show file tree
Hide file tree
Showing 40 changed files with 482 additions and 395 deletions.
5 changes: 1 addition & 4 deletions kue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
'use strict'
/* eslint no-console: off */

require('./lib/config/jobs')
require('./lib/config/jobs') // eslint-disable-line import/no-unassigned-import

const {getApp} = require('delayed-jobs')

Expand Down
3 changes: 2 additions & 1 deletion lib/api/controllers/catalogs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const mongoose = require('mongoose')

const {Http404} = require('../errors')
const am = require('../middlewares/async')

const Catalog = mongoose.model('Catalog')
Expand All @@ -13,7 +14,7 @@ function fetch(req, res, next, id) {
return next(err)
}
if (!catalog) {
return res.sendStatus(404)
return next(new Http404())
}
req.catalog = catalog
next()
Expand Down
36 changes: 18 additions & 18 deletions lib/api/controllers/featureTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,53 @@
const mongoose = require('mongoose')
const {strRight} = require('underscore.string')

const {Http400, Http404} = require('../errors')
const am = require('../middlewares/async')

const FeatureType = mongoose.model('FeatureType')

/* Middlewares */
exports.featureType = function (req, res, next, id) {
exports.featureType = (req, res, next, id) => {
FeatureType
.findOne({service: req.params.serviceId, name: id})
.exec((err, featureType) => {
if (err) {
return next(err)
}
if (!featureType) {
return res.status(404).end()
return next(new Http404())
}
req.featureType = featureType
next()
})
}

/* Actions */
exports.list = function (req, res, next) {
FeatureType
exports.list = am(async (req, res) => {
const featureTypes = await FeatureType
.find({service: req.service._id})
.select({service: 0})
.exec((err, featureTypes) => {
if (err) {
return next(err)
}
res.send(featureTypes)
})
}
.exec()

res.send(featureTypes)
})

exports.show = function (req, res) {
exports.show = (req, res) => {
res.send(req.featureType)
}

exports.prepateFeatureTypeDownload = function (req, res, next) {
exports.prepateFeatureTypeDownload = (req, res, next) => {
if (req.service.protocol !== 'wfs') {
return next(new Error('Protocol not supported'))
return next(new Http400('The specified protocol is not supported'))
}

if (!req.featureType.available) {
return res.status(404).send({
code: 404,
message: 'FeatureType `' + req.params.typeName + '` no more available on this service'
})
return next(new Http404(`FeatureType '${req.params.typeName}' no more available on this service`))
}

req.ogr2ogr = {}
req.ogr2ogr.layerName = strRight(req.featureType.name, ':')
req.ogr2ogr.src = 'WFS:' + req.service.location + (req.service.location.indexOf('?') >= 0 ? '&' : '?')

next()
}
79 changes: 42 additions & 37 deletions lib/api/controllers/publications.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,78 @@
'use strict'

const mongoose = require('mongoose')
const {pick} = require('lodash')

const {Http404} = require('../errors')
const am = require('../middlewares/async')

const Publication = mongoose.model('Publication')
const {pick} = require('lodash')

/* Params */

exports.publication = function (req, res, next, publicationTarget) {
exports.publication = async (req, res, next, publicationTarget) => {
const {recordId} = req.params

Publication
.findOne({recordId, target: publicationTarget})
.exec()
.then(publication => req.publication = publication)
.thenReturn()
.asCallback(next)
try {
const publication = await Publication.findOne({recordId, target: publicationTarget}).exec()
req.publication = publication

next()
} catch (error) {
next(error)
}
}

/* Actions */

exports.publishOrUpdate = function (req, res, next) {
exports.publishOrUpdate = am(async (req, res) => {
const {recordId, publicationTarget} = req.params
const {remoteId, remoteUrl} = req.body

if (!req.publication) {
req.publication = new Publication({recordId, target: publicationTarget})
}

req.publication
.set({remoteId, remoteUrl})
.save()
.then(publication => res.send(publication))
.catch(next)
}
const publication = await req.publication.set({remoteId, remoteUrl}).save()

exports.show = function (req, res) {
res.send(publication)
})

exports.show = (req, res) => {
const FIELDS = ['updatedAt', 'createdAt', 'remoteId', 'remoteUrl']

if (!req.publication) {
res.sendStatus(404)
} else {
res.send(pick(req.publication, ...FIELDS))
throw new Http404()
}

res.send(pick(req.publication, ...FIELDS))
}

exports.list = function (req, res, next) {
exports.list = am(async (req, res) => {
const {recordId} = req.params
const FIELDS = ['updatedAt', 'createdAt', 'remoteId', 'remoteUrl', 'target']

Publication.find({recordId})
.exec()
.then(publications => res.send(publications.map(p => pick(p, ...FIELDS))))
.catch(next)
}
const publications = await Publication.find({recordId}).exec()

exports.listAll = function (req, res, next) {
Publication.find({target: req.params.target}).select({__v: 0, _id: 0, target: 0}).lean()
res.send(publications.map(p => pick(p, ...FIELDS)))
})

exports.listAll = am(async (req, res) => {
const publications = await Publication
.find({target: req.params.target})
.select({__v: 0, _id: 0, target: 0})
.lean()
.exec()
.then(publications => res.send(publications))
.catch(next)
}

exports.unpublish = function (req, res, next) {
res.send(publications)
})

exports.unpublish = am(async (req, res) => {
if (!req.publication) {
res.sendStatus(404)
} else {
req.publication.remove()
.then(() => res.sendStatus(204))
.catch(next)
throw new Http404()
}
}

await req.publication.remove()

res.status(204).send()
})
53 changes: 26 additions & 27 deletions lib/api/controllers/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const {clone} = require('lodash')

const search = require('../../search')

const {Http404} = require('../errors')
const am = require('../middlewares/async')
const proxyThumbnail = require('../middlewares/thumbnail-proxy')

const ConsolidatedRecord = mongoose.model('ConsolidatedRecord')
Expand All @@ -19,7 +21,7 @@ exports.record = function (req, res, next, id) {
return next(err)
}
if (!record) {
return res.sendStatus(404)
return next(new Http404())
}
req.record = record
next()
Expand All @@ -34,7 +36,7 @@ exports.recordRevision = (req, res, next, id) => {
return next(err)
}
if (!recordRevision) {
return res.sendStatus(404)
return next(new Http404())
}
req.recordRevision = recordRevision
next()
Expand All @@ -48,44 +50,41 @@ exports.show = function (req, res) {
res.send(req.record)
}

exports.showBestRevision = (req, res, next) => {
RecordRevision
exports.showBestRevision = am(async (req, res) => {
const recordRevision = await RecordRevision
.findOne({recordId: req.record.recordId, recordHash: req.record.recordHash})
.exec((err, recordRevision) => {
if (err) {
return next(err)
}
if (!recordRevision) {
return res.sendStatus(404)
}
res.send(recordRevision)
})
}
.exec()

if (!recordRevision) {
throw new Http404()
}

res.send(recordRevision)
})

exports.showRevision = function (req, res) {
exports.showRevision = (req, res) => {
res.send(req.recordRevision)
}

exports.search = function (req, res, next) {
exports.search = am(async (req, res) => {
const query = clone(req.query)
const catalogName = req.service ? req.service.name : undefined

search(query, catalogName)
.then(result => res.send(result))
.catch(next)
}
const result = await search(query, catalogName)

exports.consolidate = function (req, res, next) {
ConsolidatedRecord.triggerUpdated(req.record.recordId, 'manual')
.then(() => res.send({status: 'ok'}))
.catch(next)
}
res.send(result)
})

exports.consolidate = am(async (req, res) => {
await ConsolidatedRecord.triggerUpdated(req.record.recordId, 'manual')
res.send({status: 'ok'})
})

exports.thumbnail = function (req, res) {
exports.thumbnail = (req, res) => {
const thumbnail = req.record.metadata.thumbnails.find(th => th.originalUrlHash === req.params.originalUrlHash)

if (!thumbnail) {
return res.sendStatus(404)
throw new Http404()
}

proxyThumbnail(thumbnail.originalUrl)(req, res)
Expand Down
Loading

0 comments on commit ee0fe75

Please sign in to comment.