/* global Comment */
'use strict';

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

const extraMethods = {

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

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

        let rows = result.rows.map(row => row.toJSON());
        rows = rows.map(comment => commentComposer(comment, context));
        
        return {
            count: result.count,
            rows: rows
        }
    },
/*
    afterFetchOne: (result, params, context) => {
        if (result) 
            result = result.toJSON();
        return eventComposer(result, context);
    },
*/
}

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

