'use strict';

const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
const generateControllers = require('../../core/controllers');
const models = require('../../core/models');
const blogService = require('./blog.service');
const generateCommentService = require('../comments/comment.service');

// Module Name
const MODULE_NAME = '[blog.controller]';
const controllerOptions = { MODULE_NAME };

const extraControllers = {
    getPostComments: async (req, res, next) => {
        const params = extractParamsFromRequest(req, res, controllerOptions.params.find);

        try {
            const result = await blogCommentsService.fetchAll(params, {});
            return handleResultResponse(result.rows, result.count, params, res);
        } catch (error) {
            handleErrorResponse(controllerOptions.MODULE_NAME, 'find', error, res)
        }
    },        
};

module.exports = generateControllers(blogService, extraControllers, controllerOptions);

