<commit_before>'use strict';

let photo = require('../photo_model');
const formidable = require('formidable');

const Action = {
		create: function(req, res) {
		debug('Action Create');

		formParse(req, (err, result) => {
			let promise = photo.create(result);
			promise.then(succesHandler , errorHandler)

			function succesHandler (photo){
				debug('Action Create secces');
				res.status(201).json(photo);
			}

			function errorHandler (err) {
				debug('Action Create error');
				res.status(400).json(err);
			}	
		});
  }
}

function formParse(req , cb) {
	let form = new formidable.IncomingForm();
	form.uploadDir = "../server/public/image";
	form.parse(req, (err, fields, files) => {
		if(!err) { 
			return cb(null, {
					path : files.image.path
				,	legend : fields.legend
				});
		}
		return cb(err);
	});
} <commit_msg>identation repair and user_id added<commit_after>'use strict';

let photo = require('../photo_model');
const formidable = require('formidable')
    , imagesDir = __dirname.replace('/modules/photos/actions/', '/public/images/')
    ;

const Action = {
    create: function(req, res) {
    debug('Action Create');
      formParse(req, (err, result) => {
        let promise = photo.create(result);
        promise.then(succesHandler , errorHandler)

        function succesHandler (photo){
          debug('Action Create secces');
          res.status(201).json(photo);
        }

        function errorHandler (err) {
          debug('Action Create error');
          res.status(400).json(err);
        }
      });
    }
}

function formParse(req , cb) {
  let form = new formidable.IncomingForm();
  form.uploadDir = imagesDir;
  form.parse(req, (err, fields, files) => {
    if(!err) {
      return cb(null, {
          user_id : fields.user_id
        , path : files.image.path
        , legend : fields.legend
        });
    }
    return cb(err);
  });
}
{'fraction_non_alphanumeric': 0.15453586497890295, 'fraction_numerical': 0.006329113924050633, 'mean_word_length': 2.8016032064128256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3637949', 'n_tokens_mistral': 663, 'n_tokens_neox': 591, 'n_words': 127}