<commit_before>/**
 * Sprint
 *
 * @module      ::  Model
 * @description ::  This model represents project sprint.
 */
module.exports = {
    schema: true,
    attributes: {
        // Relation to Project model
        projectId: {
            type:       'integer',
            required:   true
        },
        title: {
            type:       'string',
            required:   true
        },
        description: {
            type:       'text',
            defaultsTo: ''
        },
        dateStart: {
            type:       'date',
            required:   true
        },
        dateEnd: {
            type:       'date',
            required:   true
        },

        objectTitle: function() {
            return this.title;
        },
        durationDays: function() {
            return this.dateEndObject().diff(this.dateStartObject(), "days") + 1;
        },
        dateStartObject: function() {
            return (this.dateStart && this.dateStart != '0000-00-00')
                ? DateService.convertDateObjectToUtc(this.dateStart, true) : null;
        },
        dateEndObject: function() {
            return (this.dateEnd && this.dateEnd != '0000-00-00')
                ? DateService.convertDateObjectToUtc(this.dateEnd, true) : null;
        },
        createdAtObject: function () {
            return (this.createdAt && this.createdAt != '0000-00-00')
                ? DateService.convertDateObjectToUtc(this.createdAt) : null;
        },
        updatedAtObject: function () {
            return (this.updatedAt && this.updatedAt != '0000-00-00')
                ? DateService.convertDateObjectToUtc(this.updatedAt) : null;
        }
    },

    // Life cycle callbacks

    /**
     * After create callback.
     *
     * @param   {sails.model.sprint}    values
     * @param   {Function}              cb
     */
    afterCreate: function(values, cb) {
        HistoryService.write('Sprint', values);

        cb();
    },

    /**
     * After update callback.
     *
     * @param   {sails.model.sprint}    values
     * @param   {Function}              cb
     */
    afterUpdate: function(values, cb) {
        HistoryService.write('Sprint', values);

        cb();
    },

    /**
     * Before destroy callback.
     *
     * @param   {Object}    terms
     * @param   {Function}  cb
     */
    beforeDestroy: function(terms, cb) {
        // Remove history data
        Sprint
            .findOne(terms)
            .done(function(error, sprint) {
                HistoryService.remove('Sprint', sprint.id);

                // Update all stories sprint id to 0 which belongs to delete sprint
                Story
                    .update(
                        {sprintId: sprint.id},
                        {sprintId: 0},
                        function(error, stories) {
                            cb();
                        }
                    );
            });
    }
};<commit_msg>Refactored model and added createdUserId and updatedUserId attributes.<commit_after>/**
 * Sprint
 *
 * @module      ::  Model
 * @description ::  This model represents project sprint.
 * @docs        ::  http://sailsjs.org/#!documentation/models
 */
"use strict";

module.exports = {
    schema: true,
    attributes: {
        // Relation to Project model
        projectId: {
            type:       "integer",
            required:   true
        },
        title: {
            type:       "string",
            required:   true
        },
        description: {
            type:       "text",
            defaultsTo: ""
        },
        dateStart: {
            type:       "date",
            required:   true
        },
        dateEnd: {
            type:       "date",
            required:   true
        },
        createdUserId: {
            type:       "integer",
            required:   true
        },
        updatedUserId: {
            type:       "integer",
            required:   true
        },

        // Dynamic data attributes

        objectTitle: function() {
            return this.title;
        },
        durationDays: function() {
            return this.dateEndObject().diff(this.dateStartObject(), "days") + 1;
        },
        dateStartObject: function() {
            return (this.dateStart && this.dateStart != "0000-00-00")
                ? DateService.convertDateObjectToUtc(this.dateStart, true) : null;
        },
        dateEndObject: function() {
            return (this.dateEnd && this.dateEnd != "0000-00-00")
                ? DateService.convertDateObjectToUtc(this.dateEnd, true) : null;
        },
        createdAtObject: function () {
            return (this.createdAt && this.createdAt != "0000-00-00 00:00:00")
                ? DateService.convertDateObjectToUtc(this.createdAt) : null;
        },
        updatedAtObject: function () {
            return (this.updatedAt && this.updatedAt != "0000-00-00 00:00:00")
                ? DateService.convertDateObjectToUtc(this.updatedAt) : null;
        }
    },

    // Life cycle callbacks

    /**
     * After create callback.
     *
     * @param   {sails.model.sprint}    values
     * @param   {Function}              cb
     */
    afterCreate: function(values, cb) {
        HistoryService.write("Sprint", values);

        cb();
    },

    /**
     * After update callback.
     *
     * @param   {sails.model.sprint}    values
     * @param   {Function}              cb
     */
    afterUpdate: function(values, cb) {
        HistoryService.write("Sprint", values);

        cb();
    },

    /**
     * Before destroy callback.
     *
     * @param   {Object}    terms
     * @param   {Function}  cb
     */
    beforeDestroy: function(terms, cb) {
        // Remove history data
        Sprint
            .findOne(terms)
            .exec(function(error, sprint) {
                if (error) {
                    sails.log.error(error);

                    cb();
                } else {
                    HistoryService.remove("Sprint", sprint.id);

                    // Update all stories sprint id to 0 which belongs to delete sprint
                    Story
                        .update(
                            {sprintId: sprint.id},
                            {sprintId: 0},
                            function(error, stories) {
                                if (error) {
                                    sails.log.error(error);
                                }

                                cb();
                            }
                        );
                }
            });
    }
};
{'fraction_non_alphanumeric': 0.11464485839769802, 'fraction_numerical': 0.012418597607148266, 'mean_word_length': 1.2318350794187225, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4078252', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1703, 'n_words': 356}