<commit_before>// import mongoose from 'mongoose';
import Photo from './model';

export const getPublicID = (req, res) => {
  const data = req.body.result; // this should be an array of object(s)
  console.log('REQUEST FROM FRONT-END');
  console.log('-----------------------');
  console.log(data);
  console.log('-----------------------');
  if (data === undefined) res.status(422).json({ success: false, message: 'Upload Failed!' });
  console.time('ARRAY');
  const insertStuff = data.reduce((array, item) => {
    array.push({
      public_id: item.public_id,
      url: item.url,
      thumbnail_url: item.thumbnail_url
    });

    return array;
  }, []);
  console.timeEnd('ARRAY');

  Photo.insertMany(insertStuff)
    .then(
      img => res.status(201).json({
        success: true,
        message: 'Successfully added to database.',
        cloudinary: img
      }),
      err => res.status(422).json({ success: false, message: err })
    );
};

export const sendToFrontEnd = (req, res) => {
  /* TODO: request from front-end should ask for:
      1) All images.
      2) Active images.
      3) Images in order:
        a) Newest to Oldest
        b) Oldest to Newest
  */
  console.time('ARRAY');
  Photo.find()
    .then(
      img => res.status(201).json({ success: true, payload: img }),
      err => res.status(500).json({ message: err })
    );
    console.timeEnd('ARRAY');
};<commit_msg>Updated GET method in controller.<commit_after>// import mongoose from 'mongoose';
import Photo from './model';

export const getPublicID = (req, res) => {
  const data = req.body.result; // this should be an array of object(s)
  console.log('REQUEST FROM FRONT-END');
  console.log('-----------------------');
  console.log(data);
  console.log('-----------------------');
  if (data === undefined) res.status(422).json({ success: false, message: 'Upload Failed!' });
  console.time('ARRAY');
  const insertStuff = data.reduce((array, item) => {
    array.push({
      public_id: item.public_id,
      url: item.url,
      thumbnail_url: item.thumbnail_url
    });

    return array;
  }, []);
  console.timeEnd('ARRAY');

  Photo.insertMany(insertStuff)
    .then(
      img => res.status(201).json({
        success: true,
        message: 'Successfully added to database.',
        cloudinary: img
      }),
      err => res.status(422).json({ success: false, message: err })
    );
};

export const sendToFrontEnd = (req, res) => {
  /* TODO: request from front-end should ask for:
      1) All images.
      2) Active images. TODO: Set up prop in Redux/Model for active state.
      3) Images in order:
        a) Newest to Oldest
        b) Oldest to Newest
  */
  console.time('ARRAY');
  Photo.find()
    .then(
      img => res.status(201).json({ success: true, payload: img }),
      err => res.status(500).json({ success: false, message: err })
    );
    console.timeEnd('ARRAY');
};
{'fraction_non_alphanumeric': 0.1865748709122203, 'fraction_numerical': 0.012392426850258176, 'mean_word_length': 2.496991576413959, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5807662', 'n_tokens_mistral': 913, 'n_tokens_neox': 892, 'n_words': 249}