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 1b57d3a
Show file tree
Hide file tree
Showing 36 changed files with 392 additions and 318 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
24 changes: 12 additions & 12 deletions lib/api/controllers/records.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {clone} = require('lodash')

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

const am = require('../middlewares/async')
const proxyThumbnail = require('../middlewares/thumbnail-proxy')

const ConsolidatedRecord = mongoose.model('ConsolidatedRecord')
Expand Down Expand Up @@ -62,26 +63,25 @@ exports.showBestRevision = (req, res, next) => {
})
}

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) {
Expand Down
62 changes: 30 additions & 32 deletions lib/api/controllers/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,36 @@ exports.sync = function (req, res, next, id) {
/*
** Actions
*/
exports.list = function (req, res, next) {
exports.list = am(async (req, res) => {
const query = Service.find()
if (req.params.protocol) {
query.where('protocol').equals(req.params.protocol)
}
query
.exec((err, services) => {
if (err) {
return next(err)
}
res.json(services)
})
}

exports.create = function (req, res, next) {
const services = await query.exec()

res.send(services)
})

exports.create = am(async (req, res) => {
const service = new Service()
service.set(pick(req.body, 'name', 'location', 'protocol'))
service.addedBy = req.user

service.save(err => {
if (err) {
return next(err)
}
res.json(service)
})
}
await service.save()

res.send(service)
})

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

exports.handleSync = function (req, res, next) {
req.service.doSync(0)
.then(() => res.send(req.service))
.catch(next)
}
exports.handleSync = am(async (req, res) => {
await req.service.doSync(0)

res.send(req.service)
})

exports.listSyncs = am(async (req, res) => {
const syncs = await ServiceSync.collection.find({
Expand All @@ -102,18 +96,22 @@ exports.listSyncs = am(async (req, res) => {
res.send(syncs)
})

exports.showSync = function (req, res) {
exports.showSync = (req, res) => {
res.send(req.serviceSync)
}

exports.syncAllByProtocol = function (req, res, next) {
Service
exports.syncAllByProtocol = am(async (req, res) => {
const services = await Service
.find()
.where('protocol').equals(req.params.protocol)
.exec()
.then(services => {
return Promise.each(services, service => service.doSync(0))
.then(() => res.send({status: 'ok', services: services.length}))
})
.catch(next)
}

await Promise.all(
services.map(service => service.doSync(0))
)

res.send({
status: 'ok',
services: services.length
})
})
4 changes: 2 additions & 2 deletions lib/api/middlewares/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const isMaintenance = (req, res, next) => {
const authenticateClient = (req, res, next) => {
let clients
try {
clients = require('../../../clients.json')
} catch (err) {
clients = require('../../../clients.json') // eslint-disable-line import/no-unresolved
} catch (error) {
clients = []
}

Expand Down
2 changes: 1 addition & 1 deletion lib/extract/ogr2ogr.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function downloadDataset(req, res) {
const ogr2ogrTask = ogr2ogr(req.method === 'HEAD' ? 'fake' : req.ogr2ogr.src)
.timeout(60 * 60 * 1000)

// Projection
// Projection
if (req.query.projection === 'WGS84') {
ogr2ogrTask.project('EPSG:4326')
} else if (req.query.projection === 'Lambert93') {
Expand Down
6 changes: 2 additions & 4 deletions lib/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
'use strict'

require('./config/mongoose')
require('./config/jobs')
require('./config/mongoose') // eslint-disable-line import/no-unassigned-import
require('./config/jobs') // eslint-disable-line import/no-unassigned-import
2 changes: 1 addition & 1 deletion lib/jobs/consolidate-record/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getResourceType(type) {
return 'other'
}

async function resolveLinks(rawLinks = [], cachedLinks = []) {
function resolveLinks(rawLinks = [], cachedLinks = []) {
return Promise.all(
rawLinks.map(async link => {
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/common/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.normalizeContacts = function (contacts) {
...contact,
organizationName: normalizeName(contact.organizationName)
}
} catch (err) {
} catch (error) {
return null
}
}))
Expand Down
4 changes: 2 additions & 2 deletions lib/metadata/common/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ function castLink({name, href, protocol, description}) {
throw new Error('WMS layers are not supported yet')
}
return {name, href, description}
} catch (err) {
} catch (error) {
return {
valid: false,
reason: err.message
reason: error.message
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/common/services.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const {parse} = require('querystring')
const {pick} = require('lodash')
const URI = require('urijs')
const {parse} = require('querystring')

function getNormalizedWfsServiceLocation(location) {
location = new URI(location)
Expand Down
4 changes: 3 additions & 1 deletion lib/metadata/iso/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const TOPIC_CATEGORIES = [

const TOPIC_CATEGORIES_MAPPING = {}

TOPIC_CATEGORIES.forEach(value => TOPIC_CATEGORIES_MAPPING[value.toLowerCase()] = value)
TOPIC_CATEGORIES.forEach(value => {
TOPIC_CATEGORIES_MAPPING[value.toLowerCase()] = value
})

exports.getTopicCategory = function (record) {
const candidateValue = (get(record, 'identificationInfo.topicCategory') || '')
Expand Down
4 changes: 2 additions & 2 deletions lib/metadata/iso/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function validateEmail(email) {
if (!email) {
return false
}
const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ // eslint-disable-line
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return re.test(email)
}

Expand All @@ -48,7 +48,7 @@ exports.getAllContacts = function (metadata) {
country: get(originalContact, 'contactInfo.address.country'),
phoneNumber: get(originalContact, 'contactInfo.phone.voice')
}
contacts.push(Object.assign({relatedTo: type}, pickBy(contact)))
contacts.push({relatedTo: type, ...pickBy(contact)})
}

if (metadata.contact) {
Expand Down
36 changes: 18 additions & 18 deletions lib/metadata/iso/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ function convert(originalRecord) {

record.contacts = normalizeContacts(getAllContacts(originalRecord))

if (record.type !== 'service') {
if (record.type === 'service') {
record.serviceType = get(originalRecord, 'identificationInfo.serviceType')

if (isWFSService(originalRecord)) {
record.serviceProtocol = 'wfs'
record.serviceURL = getWFSServiceLocation(originalRecord)

const coupledResources = getCoupledResources(originalRecord)

if (record.serviceURL && coupledResources.length > 0) {
record.featureTypes = coupledResources.map(coupledResource => ({
relatedTo: hasha(coupledResource.identifier, {algorithm: 'sha1'}),
typeName: coupledResource.scopedName,
serviceURL: record.serviceURL
}))
}
}
} else {
record.spatialRepresentationType = get(originalRecord, 'identificationInfo.spatialRepresentationType')
record.lineage = get(originalRecord, 'dataQualityInfo.lineage.statement')
record.purpose = get(originalRecord, 'identificationInfo.purpose')
Expand Down Expand Up @@ -69,23 +86,6 @@ function convert(originalRecord) {
record.spatialResolution = getSpatialResolution(originalRecord)

Object.assign(record, getDates(originalRecord))
} else {
record.serviceType = get(originalRecord, 'identificationInfo.serviceType')

if (isWFSService(originalRecord)) {
record.serviceProtocol = 'wfs'
record.serviceURL = getWFSServiceLocation(originalRecord)

const coupledResources = getCoupledResources(originalRecord)

if (record.serviceURL && coupledResources.length > 0) {
record.featureTypes = coupledResources.map(coupledResource => ({
relatedTo: hasha(coupledResource.identifier, {algorithm: 'sha1'}),
typeName: coupledResource.scopedName,
serviceURL: record.serviceURL
}))
}
}
}

return record
Expand Down
6 changes: 5 additions & 1 deletion lib/metadata/iso/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ function getLicenseFromConstraints(constraints) {
const candidateLicenses = constraints
.map(constraintsPart => {
const {useConstraints, useLimitation} = constraintsPart

if (!useConstraints || !useLimitation) {
return
return null
}

if (useConstraints.includes('license') && useLimitation.join(' ').toLowerCase().includes('odbl')) {
return 'odc-odbl'
}

return null
})
.filter(license => Boolean(license))

Expand Down
4 changes: 3 additions & 1 deletion lib/metadata/iso/statuses.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const STATUSES = [

const STATUSES_MAPPING = {}

STATUSES.forEach(value => STATUSES_MAPPING[value.toLowerCase()] = value)
STATUSES.forEach(value => {
STATUSES_MAPPING[value.toLowerCase()] = value
})

exports.getStatus = function (record) {
const candidateValue = (get(record, 'identificationInfo.status') || '')
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/iso/themes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const themes = require('./themes.json')
const {makeStringComparable} = require('../common/util')
const themes = require('./themes.json')

// Prepare themes registry
const themesPatterns = {}
Expand Down
4 changes: 3 additions & 1 deletion lib/metadata/iso/update-frequencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const UPDATE_FREQUENCIES = [

const UPDATE_FREQUENCIES_MAPPING = {}

UPDATE_FREQUENCIES.forEach(uf => UPDATE_FREQUENCIES_MAPPING[uf.toLowerCase()] = uf)
UPDATE_FREQUENCIES.forEach(uf => {
UPDATE_FREQUENCIES_MAPPING[uf.toLowerCase()] = uf
})

exports.getUpdateFrequency = function (metadata) {
const candidateValue = (get(metadata, 'identificationInfo.resourceMaintenance.maintenanceAndUpdateFrequency') || '')
Expand Down
2 changes: 1 addition & 1 deletion lib/models/Publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const mongoose = require('mongoose')

const Schema = mongoose.Schema
const {Schema} = mongoose

const schema = new Schema({
recordId: {type: String, required: true},
Expand Down
6 changes: 2 additions & 4 deletions lib/models/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ const schema = new Schema({
schema.statics = {

setAsPending(uniqueQuery) {
const query = Object.assign({
'sync.pending': false,
'sync.processing': false
}, uniqueQuery)
const query = {'sync.pending': false,
'sync.processing': false, ...uniqueQuery}

const changes = {
$set: {'sync.pending': true}
Expand Down
2 changes: 1 addition & 1 deletion lib/search/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function computeFacets(record, {catalogs, publications}) {
.value()
.forEach(catalogName => facets.push({name: 'catalog', value: catalogName}))

/* Dataset marked as open */
/* Dataset marked as open */
const openDataLicense = record.metadata.license === 'fr-lo' || record.metadata.license === 'odc-odbl'
facets.push({name: 'opendata', value: openDataLicense ? 'yes' : 'not-determined'})

Expand Down
Loading

0 comments on commit 1b57d3a

Please sign in to comment.