Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangoacher committed Feb 13, 2020
1 parent 595ad4e commit ab8d9d5
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 184 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict'

module.exports = {
'collectCoverageFrom': [
collectCoverageFrom: [
'lib/*.js',
'lib/**/*.js'
],
'coverageReporters': [
coverageReporters: [
'text',
'html'
],
'testMatch': [
testMatch: [
'**/*.test.js'
]
}
2 changes: 1 addition & 1 deletion packages/trail-core/database/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ module.exports = function () {
const password = argv.password || config.get('db.password')
const idleTimeoutMillis = argv.idleTimeoutMillis || config.get('db.idleTimeoutMillis')

return {config, version, host, port, database, username, password, idleTimeoutMillis}
return { config, version, host, port, database, username, password, idleTimeoutMillis }
}
6 changes: 3 additions & 3 deletions packages/trail-core/database/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

'use strict'

const {Client} = require('pg')
const { Client } = require('pg')
const config = require('./config')

// Gather arguments

async function run () {
const {host, port, database, username: user, password, idleTimeoutMillis} = config()
const client = new Client({host, port, database: 'postgres', user, password, idleTimeoutMillis})
const { host, port, database, username: user, password, idleTimeoutMillis } = config()
const client = new Client({ host, port, database: 'postgres', user, password, idleTimeoutMillis })

await client.connect()
await client.query(`DROP DATABASE IF EXISTS ${database}`)
Expand Down
4 changes: 2 additions & 2 deletions packages/trail-core/database/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const Postgrator = require('postgrator')
const path = require('path')

async function run () {
const {version, host, port, database, username, password} = config()
const { version, host, port, database, username, password } = config()
const migrationDirectory = path.join(__dirname, '/migrations')
if (!version) throw new Error('Please provide the version to migrate to')

const postgrator = new Postgrator({driver: 'pg', migrationDirectory, schemaTable: 'schemaversion', host, port, database, username, password})
const postgrator = new Postgrator({ driver: 'pg', migrationDirectory, schemaTable: 'schemaversion', host, port, database, username, password })

await postgrator.migrate(version)
console.log(`\x1b[32m\u2714 Database \x1b[1m${database}\x1b[22m migrated successfully to version ${version}!\x1b[0m`)
Expand Down
20 changes: 10 additions & 10 deletions packages/trail-core/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

const SQL = require('@nearform/sql')
const pino = require('pino')
const {Pool} = require('pg')
const { Pool } = require('pg')

const defaultPageSize = 25
const {parseDate, convertToTrail} = require('./trail')
const { parseDate, convertToTrail } = require('./trail')

class TrailsManager {
constructor (logger, pool) {
Expand Down Expand Up @@ -60,7 +60,7 @@ class TrailsManager {
}
}

async search ({from, to, who, what, subject, page, pageSize, sort, exactMatch = false, caseInsensitive = false} = {}) {
async search ({ from, to, who, what, subject, page, pageSize, sort, exactMatch = false, caseInsensitive = false } = {}) {
// Validate parameters
if (!from) throw new Error('You must specify a starting date ("from" attribute) when querying trails.')
if (!to) throw new Error('You must specify a ending date ("to" attribute) when querying trails.')
Expand All @@ -72,10 +72,10 @@ class TrailsManager {
to = parseDate(to)

// Sanitize pagination parameters
;({page, pageSize} = this._sanitizePagination(page, pageSize))
;({ page, pageSize } = this._sanitizePagination(page, pageSize))

// Sanitize ordering
const {sortKey, sortAsc} = this._sanitizeSorting(sort)
const { sortKey, sortAsc } = this._sanitizeSorting(sort)

// Perform the query
const sql = SQL`
Expand All @@ -101,7 +101,7 @@ class TrailsManager {
return res.rows.map(convertToTrail)
}

async enumerate ({from, to, type, page, pageSize, desc} = {}) {
async enumerate ({ from, to, type, page, pageSize, desc } = {}) {
// Validate parameters
if (!from) throw new Error('You must specify a starting date ("from" attribute) when enumerating.')
if (!to) throw new Error('You must specify a ending date ("to" attribute) when enumerating.')
Expand All @@ -119,7 +119,7 @@ class TrailsManager {
if (!['who', 'what', 'subject'].includes(type)) throw new TypeError('You must select between "who", "what" or "subject" type ("type" attribute) when enumerating.')

// Sanitize pagination parameters
;({page, pageSize} = this._sanitizePagination(page, pageSize))
;({ page, pageSize } = this._sanitizePagination(page, pageSize))

// Perform the query
const sql = SQL`
Expand Down Expand Up @@ -222,7 +222,7 @@ class TrailsManager {
_sanitizeSorting (sortKey) {
let sortAsc = true

if (!sortKey) return {sortKey: '"when"', sortAsc: false} // Default is -when
if (!sortKey) return { sortKey: '"when"', sortAsc: false } // Default is -when

if (sortKey.startsWith('-')) {
sortAsc = false
Expand All @@ -237,7 +237,7 @@ class TrailsManager {
if (sortKey === 'when') sortKey = '"when"'
else if (sortKey !== 'id') sortKey += '_id'

return {sortKey: `${sortKey}`, sortAsc}
return { sortKey: `${sortKey}`, sortAsc }
}

_sanitizePagination (page, pageSize) {
Expand All @@ -251,4 +251,4 @@ class TrailsManager {
}
}

module.exports = {TrailsManager}
module.exports = { TrailsManager }
10 changes: 5 additions & 5 deletions packages/trail-core/lib/trail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const {DateTime} = require('luxon')
const { DateTime } = require('luxon')

const parseComponent = function (attributes, id, label) {
// Copy an overriden id
Expand All @@ -12,7 +12,7 @@ const parseComponent = function (attributes, id, label) {
throw new Error(`The "${label}" field when passed as a string must be non empty.`)
}

return {id: attributes, attributes: {}}
return { id: attributes, attributes: {} }
}

// Valid the value format
Expand All @@ -30,12 +30,12 @@ const parseComponent = function (attributes, id, label) {
attributes = Object.assign({}, attributes)
Reflect.deleteProperty(attributes, 'id')

return {id, attributes}
return { id, attributes }
}

const parseDate = function (original) {
if (original instanceof DateTime) return original.setZone('utc')
else if (original instanceof Date) return DateTime.fromMillis(original.getTime(), {zone: 'utc'})
else if (original instanceof Date) return DateTime.fromMillis(original.getTime(), { zone: 'utc' })
else if (typeof original !== 'string') throw new Error('Only Luxon DateTime, JavaScript Date or ISO8601 are supported for dates.')

const when = DateTime.fromISO(original)
Expand All @@ -53,7 +53,7 @@ const validateAdditionalFields = function (value, label) {

module.exports = {
parseDate,
convertToTrail ({id, when, who, what, subject, where, why, meta, who_id: whoId, what_id: whatId, subject_id: subjectId}) {
convertToTrail ({ id, when, who, what, subject, where, why, meta, who_id: whoId, what_id: whatId, subject_id: subjectId }) {
// Convert required fields
if (id !== null && typeof id !== 'undefined' && typeof id !== 'number') throw new Error('The trail id must be a number or null.')

Expand Down

0 comments on commit ab8d9d5

Please sign in to comment.