<commit_before>app.factory('SetItem', function (DS, $q, ParseData) {
	// vars
	var definition = {
		name: 'setItem',
		defaultAdapter: 'setItemAdapter',
		beforeInject: _beforeInject,
		afterInject: _afterInject,
		afterDestroy: _afterDestroy,
		computed: {
			ownerId: ['owner', _updateOwnerId],
			cardId: ['card', _updateCardId]
		},
		methods: {
			// Instance methods
			updateLinks: _updateLinks
		}
	}

	// Adapter
	DS.adapters.setItemAdapter = {
		destroy: _destroy,
		findAll: _findAll,
		create: _create
	};

	// constants
	var RELATIONS = ['set', 'suggestion'];

	// init
	var SetItem = DS.defineResource(definition);

	return SetItem;

	// methods

	function _beforeInject(resourceName, parseObject){
		if(parseObject.attributes) {
			ParseData.flattenAttrsBeforeInject(resourceName, parseObject);
		}
		ParseData.linkProperty(parseObject, 'set', 'owner');
		ParseData.linkProperty(parseObject, 'suggestion', 'card');
	}

	function _afterInject(resourceName, parseObject) {
		// parseObject.updateLinks();
		parseObject.owner.addSetItem(parseObject);
		parseObject.card.addSetItem(parseObject);
	}

	function _afterDestroy(resourceName, attrs, cb) {
		var setItem = attrs;
		setItem.card.removeSetItem(setItem);
		setItem.owner.removeSetItem(setItem);
		cb(null, attrs);
	}

	function _updateLinks() {
		ParseData.linkRelationsAfterInject(SetItem, RELATIONS, this);
		// SetItem.linkInverse(this.id);
	}

	function _updateOwnerId(owner) {
		return this.owner.id;
	}

	function _updateCardId(card) {
		return this.card.id;
	}

	function _findAll(definition, params, options) {
		if(params) {
			if(params.setId) {
				return _getSetItemsForSet(params.setId);
			} else if(params.suggestionId) {
				return _getSetItemsForSuggestion(params.suggestionId);
			}
		}
		return $q.reject('unhandled SetItem findAll');
	}

	function _getSetItemsForSet(setId) {
		console.log('setItem getSetItemsForSet');
		var deferred = $q.defer();
		// save promise if needed
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'getCardsForSet',
			{
				id: setId,
				includeOwner: true
			},
			{
				success: function(setItems) {
					setItems = SetItem.inject(setItems);
					deferred.resolve(setItems);
				},
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

	function _getSetItemsForSuggestion(suggestionId) {
		console.log('setItem getSetItemsForSet');
		var deferred = $q.defer();
		// save promise if needed
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'getCardsForSuggestion',
			{
				id: suggestionId,
				includeOwner: true
			},
			{
				success: function(setItems) {
					setItems = SetItem.inject(setItems);
					deferred.resolve(setItems);
				},
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

	function _create(resourceConfig, attrs, options) {
		var deferred = $q.defer();
		var set = this;
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'addCardToSet',
			{
				card: attrs.card.id,
				set: attrs.set.id
			},
			{
				success: function(setItem) {
					setItem = SetItem.inject(setItem);
					deferred.resolve(setItem);
				},
				error: function(err) {
					deferred.reject(err);
				}
			}
		);
		return deferred.promise;
	}

	function _destroy(resource, id) {
		var deferred = $q.defer();
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'removeSetItem',
			{
				id: id
			},
			{
				success: deferred.resolve,
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

});<commit_msg>removed extra inject<commit_after>app.factory('SetItem', function (DS, $q, ParseData) {
	// vars
	var definition = {
		name: 'setItem',
		defaultAdapter: 'setItemAdapter',
		beforeInject: _beforeInject,
		afterInject: _afterInject,
		afterDestroy: _afterDestroy,
		computed: {
			ownerId: ['owner', _updateOwnerId],
			cardId: ['card', _updateCardId]
		},
		methods: {
			// Instance methods
			updateLinks: _updateLinks
		}
	}

	// Adapter
	DS.adapters.setItemAdapter = {
		destroy: _destroy,
		findAll: _findAll,
		create: _create
	};

	// constants
	var RELATIONS = ['set', 'suggestion'];

	// init
	var SetItem = DS.defineResource(definition);

	return SetItem;

	// methods

	function _beforeInject(resourceName, parseObject){
		if(parseObject.attributes) {
			ParseData.flattenAttrsBeforeInject(resourceName, parseObject);
		}
		ParseData.linkProperty(parseObject, 'set', 'owner');
		ParseData.linkProperty(parseObject, 'suggestion', 'card');
	}

	function _afterInject(resourceName, parseObject) {
		// parseObject.updateLinks();
		parseObject.owner.addSetItem(parseObject);
		parseObject.card.addSetItem(parseObject);
	}

	function _afterDestroy(resourceName, attrs, cb) {
		var setItem = attrs;
		setItem.card.removeSetItem(setItem);
		setItem.owner.removeSetItem(setItem);
		cb(null, attrs);
	}

	function _updateLinks() {
		ParseData.linkRelationsAfterInject(SetItem, RELATIONS, this);
		// SetItem.linkInverse(this.id);
	}

	function _updateOwnerId(owner) {
		return this.owner.id;
	}

	function _updateCardId(card) {
		return this.card.id;
	}

	function _findAll(definition, params, options) {
		if(params) {
			if(params.setId) {
				return _getSetItemsForSet(params.setId);
			} else if(params.suggestionId) {
				return _getSetItemsForSuggestion(params.suggestionId);
			}
		}
		return $q.reject('unhandled SetItem findAll');
	}

	function _getSetItemsForSet(setId) {
		console.log('setItem getSetItemsForSet');
		var deferred = $q.defer();
		// save promise if needed
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'getCardsForSet',
			{
				id: setId,
				includeOwner: true
			},
			{
				success: deferred.resolve,
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

	function _getSetItemsForSuggestion(suggestionId) {
		console.log('setItem getSetItemsForSet');
		var deferred = $q.defer();
		// save promise if needed
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'getCardsForSuggestion',
			{
				id: suggestionId,
				includeOwner: true
			},
			{
				success: function(setItems) {
					setItems = SetItem.inject(setItems);
					deferred.resolve(setItems);
				},
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

	function _create(resourceConfig, attrs, options) {
		var deferred = $q.defer();
		var set = this;
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'addCardToSet',
			{
				card: attrs.card.id,
				set: attrs.set.id
			},
			{
				success: function(setItem) {
					setItem = SetItem.inject(setItem);
					deferred.resolve(setItem);
				},
				error: function(err) {
					deferred.reject(err);
				}
			}
		);
		return deferred.promise;
	}

	function _destroy(resource, id) {
		var deferred = $q.defer();
		Parse.Cloud.run(
			CONFIG.PARSE_VERSION + 'removeSetItem',
			{
				id: id
			},
			{
				success: deferred.resolve,
				error: deferred.reject
			}
		);
		return deferred.promise;
	}

});
{'fraction_non_alphanumeric': 0.1285672256546043, 'fraction_numerical': 0.0, 'mean_word_length': 3.6377899045020463, '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': '7544738', 'n_tokens_mistral': 2775, 'n_tokens_neox': 2339, 'n_words': 413}