<commit_before>'use strict';

const _ = require('lodash');
const parseMultipartBody = require('../utils/parse-multipart');

module.exports = {
  /**
   * Returns a list of entities of a content-type matching the query parameters
   */
  async find(ctx) {
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    let entities = [];
    if (_.has(ctx.request.query, '_q')) {
      entities = await contentManagerService.search(
        ctx.params,
        ctx.request.query
      );
    } else {
      entities = await contentManagerService.fetchAll(
        ctx.params,
        ctx.request.query
      );
    }
    ctx.body = entities;
  },

  /**
   * Returns an entity of a content type by id
   */
  async findOne(ctx) {
    const { source } = ctx.request.query;
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    const entry = await contentManagerService.fetch(ctx.params, source);

    // Entry not found
    if (!entry) {
      return ctx.notFound('Entry not found');
    }

    ctx.body = entry;
  },

  /**
   * Returns a count of entities of a content type matching query parameters
   */
  async count(ctx) {
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    let count;
    if (_.has(ctx.request.query, '_q')) {
      count = await contentManagerService.countSearch(
        ctx.params,
        ctx.request.query
      );
    } else {
      count = await contentManagerService.count(ctx.params, ctx.request.query);
    }

    ctx.body = {
      count: _.isNumber(count) ? count : _.toNumber(count),
    };
  },

  /**
   * Creates an entity of a content type
   */
  async create(ctx) {
    const { model } = ctx.params;
    const { source } = ctx.request.query;

    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    try {
      if (ctx.is('multipart')) {
        const { data, files } = parseMultipartBody(ctx);
        ctx.body = await contentManagerService.create(data, {
          files,
          model,
          source,
        });
      } else {
        // Create an entry using `queries` system
        ctx.body = await contentManagerService.create(
          ctx.params,
          ctx.request.body,
          { source, model }
        );
      }

      strapi.emit('didCreateFirstContentTypeEntry', ctx.params, source);<commit_msg>Fix content manager invalid arguments passed<commit_after>'use strict';

const _ = require('lodash');
const parseMultipartBody = require('../utils/parse-multipart');

module.exports = {
  /**
   * Returns a list of entities of a content-type matching the query parameters
   */
  async find(ctx) {
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    let entities = [];
    if (_.has(ctx.request.query, '_q')) {
      entities = await contentManagerService.search(
        ctx.params,
        ctx.request.query
      );
    } else {
      entities = await contentManagerService.fetchAll(
        ctx.params,
        ctx.request.query
      );
    }
    ctx.body = entities;
  },

  /**
   * Returns an entity of a content type by id
   */
  async findOne(ctx) {
    const { source } = ctx.request.query;
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    const entry = await contentManagerService.fetch(ctx.params, source);

    // Entry not found
    if (!entry) {
      return ctx.notFound('Entry not found');
    }

    ctx.body = entry;
  },

  /**
   * Returns a count of entities of a content type matching query parameters
   */
  async count(ctx) {
    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    let count;
    if (_.has(ctx.request.query, '_q')) {
      count = await contentManagerService.countSearch(
        ctx.params,
        ctx.request.query
      );
    } else {
      count = await contentManagerService.count(ctx.params, ctx.request.query);
    }

    ctx.body = {
      count: _.isNumber(count) ? count : _.toNumber(count),
    };
  },

  /**
   * Creates an entity of a content type
   */
  async create(ctx) {
    const { model } = ctx.params;
    const { source } = ctx.request.query;

    const contentManagerService =
      strapi.plugins['content-manager'].services['contentmanager'];

    try {
      if (ctx.is('multipart')) {
        const { data, files } = parseMultipartBody(ctx);
        ctx.body = await contentManagerService.create(data, {
          files,
          model,
          source,
        });
      } else {
        // Create an entry using `queries` system
        ctx.body = await contentManagerService.create(ctx.request.body, {
          source,
          model,
        });
      }

      strapi.emit('didCreateFirstContentTypeEntry', ctx.params, source);
{'fraction_non_alphanumeric': 0.12363415621205989, 'fraction_numerical': 0.0, 'mean_word_length': 2.3995873452544703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3020931', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1383, 'n_words': 324}