<commit_before>var injector    = require( 'injector' )
  , Class       = injector.getInstance( 'Class' )
  , Promise     = require( 'bluebird' )
  , path        = require( 'path' )
  , util        = require( 'util' )
  , debug       = require( 'debug' )( 'Services' )
  , Model       = injector.getInstance( 'Model' )
  , services    = {}
  , Service;

Service = exports.Class = Class.extend(
/** @Static **/
{
    model: null,

    db: null
},
/** @Prototype */
{
    db: false,

    model: false,

    // Currently only supports Sequelize
    query: function( query ) {
        this.db.query( sql, null, { raw: true } );
    },

    // Create a new model
    create: function( data ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !!data.id ) {
                resolve( { statuscode: 400, message: 'Unable to create a new ' + service.model._name + ', identity already exists.' }  );
            }

            service.model
                .create( data )
                .then( resolve )
                .catch( reject );
        });
    },

    // Find one record using either id or a where {}
    find: function( idOrWhere ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( typeof idOrWhere === 'object' && service.model.type === 'ORM' ) {
                Object.keys( idOrWhere.where ).forEach( function( name ) {
                    if ( idOrWhere.where[ name ] === 'null' ) { 
                        idOrWhere.where[ name ] = null;
                    }
                });
            }

            service.model
                .find( idOrWhere )

                .then( function( model ) {
                    if ( !!model && !!model.id ) {
                        resolve( model );
                    } else {
                        resolve( { statuscode: 403, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    },

    // Find more than one record using using a where {}
    findAll: function( where ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( typeof where === 'object' && service.model.type === 'ORM' ) {
                Object.keys( where.where ).forEach( function( name ) {
                    if ( where.where[ name ] === 'null' ) { 
                        where.where[ name ] = null;
                    }
                });
            }

            service.model
                .findAll( where )
                .then( function( models ) {
                    resolve( models );
                })
                .catch( reject );

        });
    },

    // Find one record and update it using either id or a where {}
    update: function( idOrWhere, data ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !idOrWhere || idOrWhere === null ) {
                resolve( { statuscode: 400, message: 'Unable to update ' + service.model._name + ', unable to determine identity.' }  );
            }

            if ( !data ) {
                resolve( { statuscode: 400, message: 'Unable to update ' + service.model._name + ', you did not provide any data.' }  );
            }

            service.model
                .find( idOrWhere )
                .then( function( user ) {
                    if ( !!user && !!user.id ) {

                        Object.keys( data ).forEach(function( i ) {
                            user[ i ] = data[ i ];
                        });

                        user.save()
                            .then( resolve )
                            .catch( reject );

                    } else {
                        resolve( { statuscode: 403, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    },

    // Find one record and delete it using either id or a where {}
    destroy: function( idOrWhere ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !idOrWhere || idOrWhere === null ) {
                resolve( { statuscode: 400, message: 'Unable to delete ' + service.model._name + ', unable to determine identity.' }  );
            }

            service.model
                .find( idOrWhere )
                .then( function( user ) {
                    if ( !!user && !!user.id ) {
                        user.destroy()
                            .then( resolve )
                            .catch( reject )
                    } else {
                        resolve( { statuscode: 403, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    }
});

exports.extend = function() {
    var extendingArgs = [].slice.call( arguments )
      , serviceName = ( typeof extendingArgs[ 0 ] === 'string' )
            ? extendingArgs.shift()
            : false
      , Static = ( extendingArgs.length === 2 )
            ? extendingArgs.shift()
            : {}
      , Proto = extendingArgs.shift();
    
    if ( !serviceName ) {
        var Reg   = new RegExp( '.*\\(([^\\)]+)\\:.*\\:.*\\)', 'ig' )
          , stack = new Error().stack.split( '\n' )
          , file  = stack.splice( 2, 1 );
<commit_msg>fix(service): Standardise statusCode<commit_after>var injector    = require( 'injector' )
  , Class       = injector.getInstance( 'Class' )
  , Promise     = require( 'bluebird' )
  , path        = require( 'path' )
  , util        = require( 'util' )
  , debug       = require( 'debug' )( 'Services' )
  , Model       = injector.getInstance( 'Model' )
  , services    = {}
  , Service;

Service = exports.Class = Class.extend(
/** @Static **/
{
    model: null,

    db: null
},
/** @Prototype */
{
    db: false,

    model: false,

    // Currently only supports Sequelize
    query: function( query ) {
        this.db.query( sql, null, { raw: true } );
    },

    // Create a new model
    create: function( data ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !!data.id ) {
                resolve( { statusCode: 400, message: 'Unable to create a new ' + service.model._name + ', identity already exists.' }  );
            }

            service.model
                .create( data )
                .then( resolve )
                .catch( reject );
        });
    },

    // Find one record using either id or a where {}
    find: function( idOrWhere ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( typeof idOrWhere === 'object' && service.model.type === 'ORM' ) {
                Object.keys( idOrWhere.where ).forEach( function( name ) {
                    if ( idOrWhere.where[ name ] === 'null' ) { 
                        idOrWhere.where[ name ] = null;
                    }
                });
            }

            service.model
                .find( idOrWhere )
                .then( function( model ) {
                    if ( model !== null && !!model && !!model.id ) {
                        resolve( model );
                    } else {
                        resolve( { statusCode: 404, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    },

    // Find more than one record using using a where {}
    findAll: function( where ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( typeof where === 'object' && service.model.type === 'ORM' ) {
                Object.keys( where.where ).forEach( function( name ) {
                    if ( where.where[ name ] === 'null' ) { 
                        where.where[ name ] = null;
                    }
                });
            }

            service.model
                .findAll( where )
                .then( function( models ) {
                    resolve( models );
                })
                .catch( reject );

        });
    },

    // Find one record and update it using either id or a where {}
    update: function( idOrWhere, data ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !idOrWhere || idOrWhere === null ) {
                resolve( { statusCode: 400, message: 'Unable to update ' + service.model._name + ', unable to determine identity.' }  );
            }

            if ( !data ) {
                resolve( { statusCode: 400, message: 'Unable to update ' + service.model._name + ', you did not provide any data.' }  );
            }

            service.model
                .find( idOrWhere )
                .then( function( user ) {
                    if ( !!user && !!user.id ) {

                        Object.keys( data ).forEach(function( i ) {
                            user[ i ] = data[ i ];
                        });

                        user.save()
                            .then( resolve )
                            .catch( reject );

                    } else {
                        resolve( { statusCode: 404, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    },

    // Find one record and delete it using either id or a where {}
    destroy: function( idOrWhere ) {
        var service = this;

        return new Promise( function( resolve, reject ) {
            if ( !service.model ) {
                reject( 'Model not found, either set ' + service._name + '.model or implement ' + service._name + '.find()' );
                return;
            }

            if ( !idOrWhere || idOrWhere === null ) {
                resolve( { statusCode: 400, message: 'Unable to delete ' + service.model._name + ', unable to determine identity.' }  );
            }

            service.model
                .find( idOrWhere )
                .then( function( user ) {
                    if ( !!user && !!user.id ) {
                        user.destroy()
                            .then( resolve )
                            .catch( reject )
                    } else {
                        resolve( { statusCode: 404, message: service.model._name + " doesn't exist." }  );
                    }
                })
                .catch( reject );

        });
    }
});

exports.extend = function() {
    var extendingArgs = [].slice.call( arguments )
      , serviceName = ( typeof extendingArgs[ 0 ] === 'string' )
            ? extendingArgs.shift()
            : false
      , Static = ( extendingArgs.length === 2 )
            ? extendingArgs.shift()
            : {}
      , Proto = extendingArgs.shift();
    
    if ( !serviceName ) {
        var Reg   = new RegExp( '.*\\(([^\\)]+)\\:.*\\:.*\\)', 'ig' )
          , stack = new Error().stack.split( '\n' )
          , file  = stack.splice( 2, 1 );

{'fraction_non_alphanumeric': 0.1300261901093822, 'fraction_numerical': 0.0038514866738561084, 'mean_word_length': 1.2132628707807704, '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': '5734417', 'n_tokens_mistral': 3477, 'n_tokens_neox': 3231, 'n_words': 922}