drinkingvideogames/mixer

View on GitHub
api/services/game/hooks.js

Summary

Maintainability
A
3 hrs
Test Coverage
const commonHooks = require('../lib/hooks')
 
function prepareAssetEntry (assetServiceName, tags) {
return (hook) => {
const baseUrl = hook.app.service(assetServiceName).baseUrl
const asset = { url: baseUrl + hook.result.id, tags }
return new Promise((resolve, reject) => {
hook.app.service('assets').create(asset, hook.params).then((data) => {
hook.data.asset = data
return hook
}).then(resolve).catch(reject)
})
}
}
 
const gameHooks = {
Identical blocks of code found in 2 locations. Consider refactoring.
before: {
create:
[ commonHooks.requireAuth(),
commonHooks.embellishUser(),
commonHooks.setCurrentDateHook('createdAt'),
commonHooks.setCurrentDateHook('updatedAt')
],
update: [ commonHooks.setCurrentDateHook('updatedAt') ],
patch: [ commonHooks.setCurrentDateHook('updatedAt') ]
}
}
 
Similar blocks of code found in 2 locations. Consider refactoring.
const imageHooks = {
before: {
create: [
commonHooks.requireAuth()
]
},
after: {
create: [ prepareAssetEntry('gameimages', [ 'game', 'image' ]) ]
}
}
 
Similar blocks of code found in 2 locations. Consider refactoring.
const iconHooks = {
before: {
create: [
commonHooks.requireAuth()
]
},
after: {
create: [ prepareAssetEntry('gameicons', [ 'game', 'icon' ]) ]
}
}
 
module.exports = {
gameHooks,
imageHooks,
iconHooks
}