<commit_before>import DS from 'ember-data';

import OsfModel from './osf-model';

import { serializeHasMany } from '../utils/serialize-relationship';

/**
 * Model for OSF APIv2 nodes. This model may be used with one of several API endpoints. It may be queried directly,
 *  or accessed via relationship fields.
 * For field and usage information, see:
 *    https://api.osf.io/v2/docs/#!/v2/Node_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Detail_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Children_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Linked_Nodes_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Forks_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/User_Nodes_GET
 */
export default OsfModel.extend({
    title: DS.attr('string'),
    description: DS.attr('string'),
    category: DS.attr('string'),

    currentUserPermissions: DS.attr('string'),

    fork: DS.attr('boolean'),
    collection: DS.attr('boolean'),
    registration: DS.attr('boolean'),
    public: DS.attr('boolean'),

    dateCreated: DS.attr('date'),
    dateModified: DS.attr('date'),

    tags: DS.attr(),

    templateFrom: DS.attr('string'),

    parent: DS.belongsTo('node', {
        inverse: 'children'
    }),
    children: DS.hasMany('nodes', {
        inverse: 'parent',
        updateRequest: {
            requestType: () => 'POST'
        }
    }),
    affiliatedInstitutions: DS.hasMany('institutions', {
        inverse: 'nodes',
        serializer: serializeHasMany.bind(null, 'affiliatedInstitutions', 'institution')
    }),
    comments: DS.hasMany('comments'),
    contributors: DS.hasMany('contributors', {
        updateRequest: {
            requestType: (snapshot, relationship) => snapshot.hasMany(relationship).filter(each => Object.keys(each.changedAttributes()).indexOf('userId') !== -1).length > 0 ? 'POST' : 'PATCH',
            isBulk: () => true,
            serialized(serialized) {
                return {
                    data: serialized.map(function(record) {
                        var data = record.data;
                        return data;
                    })
                };
            }
        },
        inverse: null
    }),

    files: DS.hasMany('file-provider'),
    //forkedFrom: DS.belongsTo('node'),
    nodeLinks: DS.hasMany('node-links', {
        updateRequest: {
            requestType: () => 'POST',
            isBulk: () => true,
            serialized(serialized) {
                return {
                    data: serialized.map(function(record) {
                        var data = record.data;
                        return data;<commit_msg>Always POST for new records<commit_after>import DS from 'ember-data';

import OsfModel from './osf-model';

import { serializeHasMany } from '../utils/serialize-relationship';

/**
 * Model for OSF APIv2 nodes. This model may be used with one of several API endpoints. It may be queried directly,
 *  or accessed via relationship fields.
 * For field and usage information, see:
 *    https://api.osf.io/v2/docs/#!/v2/Node_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Detail_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Children_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Linked_Nodes_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/Node_Forks_List_GET
 *    https://api.osf.io/v2/docs/#!/v2/User_Nodes_GET
 */
export default OsfModel.extend({
    title: DS.attr('string'),
    description: DS.attr('string'),
    category: DS.attr('string'),

    currentUserPermissions: DS.attr('string'),

    fork: DS.attr('boolean'),
    collection: DS.attr('boolean'),
    registration: DS.attr('boolean'),
    public: DS.attr('boolean'),

    dateCreated: DS.attr('date'),
    dateModified: DS.attr('date'),

    tags: DS.attr(),

    templateFrom: DS.attr('string'),

    parent: DS.belongsTo('node', {
        inverse: 'children'
    }),
    children: DS.hasMany('nodes', {
        inverse: 'parent',
        updateRequest: {
            requestType: () => 'POST'
        }
    }),
    affiliatedInstitutions: DS.hasMany('institutions', {
        inverse: 'nodes',
        serializer: serializeHasMany.bind(null, 'affiliatedInstitutions', 'institution')
    }),
    comments: DS.hasMany('comments'),
    contributors: DS.hasMany('contributors', {
        updateRequest: {
            requestType: (snapshot, relationship) => {
		if (snapshot.hasMany(relationship).filter(each => each.record.get('isNew')).length) {
		    return 'POST';		    
		}
		return 'PATCH';
	    },
            isBulk: () => true,
            serialized(serialized) {
                return {
                    data: serialized.map(function(record) {
                        var data = record.data;
                        return data;
                    })
                };
            }
        },
        inverse: null
    }),

    files: DS.hasMany('file-provider'),
    //forkedFrom: DS.belongsTo('node'),
    nodeLinks: DS.hasMany('node-links', {
        updateRequest: {
            requestType: () => 'POST',
            isBulk: () => true,
            serialized(serialized) {
                return {
                    data: serialized.map(function(record) {
                        var data = record.data;
                        return data;
{'fraction_non_alphanumeric': 0.1516533637400228, 'fraction_numerical': 0.005321170657544659, 'mean_word_length': 2.180060422960725, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 12, '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': '7278757', 'n_tokens_mistral': 1624, 'n_tokens_neox': 1565, 'n_words': 290}