{"size": 1399, "ext": "js", "max_stars_repo_path": "src/services/probe-results/probe-results.hooks.js", "max_stars_repo_name": "weacast/weacast-probe", "max_stars_repo_stars_event_min_datetime": "2018-05-11T15:11:36.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-20T01:10:50.000Z", "max_issues_repo_path": "src/services/probe-results/probe-results.hooks.js", "max_issues_repo_name": "weacast/weacast-probe", "max_issues_repo_issues_event_min_datetime": "2017-11-24T14:58:48.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-17T09:44:28.000Z", "max_forks_repo_path": "src/services/probe-results/probe-results.hooks.js", "max_forks_repo_name": "weacast/weacast-probe", "max_forks_repo_forks_event_min_datetime": "2017-11-21T13:59:43.000Z", "max_forks_repo_forks_event_max_datetime": "2017-11-21T13:59:43.000Z"}
{"max_stars_count": 4, "max_issues_count": 33, "max_forks_count": 1, "avg_line_length": 34.1219512195, "max_line_length": 118, "alphanum_fraction": 0.6511794139}
import { disallow, when } from 'feathers-hooks-common'
import _ from 'lodash'
import { hooks } from 'weacast-core'
import { marshallResultsQuery, aggregateResultsQuery } from '../../hooks'

// Used internally by bulk write to ensure hooks are still run as usual service call
const skipDbCallOnBulk = when(hook => _.get(hook, 'params.bulk'), (hook) => { hook.result = hook.data })

// Marshall/Unmarshall should be always first so that we have a consistent data format in other hooks
module.exports = {
  before: {
    all: [ hooks.marshallQuery ],
    find: [ hooks.marshallComparisonQuery, hooks.marshallSpatialQuery, marshallResultsQuery, aggregateResultsQuery ],
    get: [],
    create: [ skipDbCallOnBulk, disallow('external'), hooks.marshall ],
    update: [ skipDbCallOnBulk, disallow('external'), hooks.marshall ],
    patch: [ skipDbCallOnBulk, disallow('external'), hooks.marshall ],
    remove: [ disallow('external'), hooks.marshallComparisonQuery, hooks.marshallSpatialQuery ]
  },

  after: {
    all: [ hooks.unmarshall ],
    find: [],
    get: [],
    create: [hooks.skipEvents], // Avoid emitting events on result edition
    update: [hooks.skipEvents],
    patch: [hooks.skipEvents],
    remove: [hooks.skipEvents]
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
}
