/* global Venue */
'use strict';

const _ = require('lodash'); 
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const { locationComposer } = require('../../helpers/composes.helper');
const models = require('../../core/models');

const extraMethods = {

    afterFetchAll: (result, params, context) => {

        if (!result.count) {
            return result;
        }

        let rows = result.rows.map(row => row.toJSON());

        if (context.scopes.includes('includeMultimedias'))
            rows = rows.map(row => locationComposer(row, context));

        return {
            count: result.count,
            rows: rows
        }
    },

    afterFetchOne: (result, params, context) => {

        if (result)
            result = result.toJSON();
        return locationComposer(result, context);
    },
    

};

module.exports = generateService(models.Location, extraMethods);