Commit 1c07b640 authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Limpia código y revisa config de RestManager

parent f446bc8d
Loading
Loading
Loading
Loading
+6 −16
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@ define([
	, 'dojo/_base/declare'
	, 'dojo/_base/lang'
	, 'src/component/base/_Module'
	, './_RestManagerItfc'
	, 'src/component/store/_RestManagerItfc'
], function(
	redmicConfig
	, declare
@@ -18,9 +18,9 @@ define([
		//	description:
		//		Permite manejar las peticiones de datos y su respuesta, así como las operaciones de escritura y borrado.

		constructor: function(args) {
		postMixInProperties: function() {

			this.config = {
			const defaultConfig = {
				ownChannel: 'data',
				events: {
					GET: 'get',
@@ -54,7 +54,9 @@ define([
				defaultErrorDescription: 'Error'
			};

			lang.mixin(this, this.config, args);
			this._mergeOwnAttributes(defaultConfig);

			this.inherited(arguments);
		},

		_defineSubscriptions: function () {
@@ -137,12 +139,6 @@ define([

			this._emitLoading(req);

			/*var target = this._getResolvedTarget(req.target);

			this._getRequest(target, req).then(
				lang.hitch(this, this._handleGetSuccess, req),
				lang.hitch(this, this._handleGetError, req));*/

			const requesterChannel = this._getRequesterChannel(componentInfo);

			this._manageRequestParams(req, requesterChannel);
@@ -180,12 +176,6 @@ define([

			this._emitLoading(req);

			/*var target = this._getResolvedTarget(req.target);

			this._requestRequest(target, req).then(
				lang.hitch(this, this._handleRequestSuccess, req),
				lang.hitch(this, this._handleRequestError, req));*/

			const requesterChannel = this._getRequesterChannel(componentInfo);

			this._manageRequestParams(req, requesterChannel);
+10 −86
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ define([
		//	_filteredAuthPaths: Array
		//		Define las rutas de URLs a las que no hay que añadirle cabeceras de autenticación.

		constructor: function(args) {
		postMixInProperties: function() {

			this.config = {
			const defaultConfig = {
				idProperty: 'id',
				limitDefault: 100,
				sortParamName: 'sort',
@@ -62,7 +62,14 @@ define([
				]
			};

			lang.mixin(this, this.config, args);
			this._mergeOwnAttributes(defaultConfig);

			this.inherited(arguments);
		},

		postCreate: function() {

			this.inherited(arguments);

			this._prepareRequestHandlers();
		},
@@ -145,14 +152,6 @@ define([
			return accessToken ? `Bearer ${accessToken}` : null;
		},

		_getRequest: function(target, req) {

			var url = this._getGetRequestTarget(target, req),
				options = this._getGetRequestOptions(req);

			return this._launchRequest(url, options);
		},

		_performGet: function(req, requesterChannel) {

			const url = this._getTargetForGet(req, requesterChannel),
@@ -161,18 +160,6 @@ define([
			return this._launchRequest(url, options);
		},

		_getGetRequestTarget: function(target, req) {

			const id = req.id,
				idType = typeof id;

			if (idType === 'string' || idType === 'number') {
				return this._getTargetWithEndingSlash(target) + id;
			}

			return target;
		},

		_getTargetForGet: function(req, requesterChannel) {

			let target = this._getTargetWithPathParamsReplaced(req.target, requesterChannel);
@@ -187,23 +174,6 @@ define([
			return target;
		},

		_getGetRequestOptions: function(req) {

			var headers = lang.mixin({}, this.headers, req.headers || {}),
				query = lang.mixin({}, req.query || {}),
				options = req.options || {};

			return lang.mixin({
				method: 'GET',
				headers: headers,
				query: query,
				sync: this.sync,
				preventCache: this.preventCache,
				timeout: this.timeout,
				handleAs: this.handleAs
			}, options);
		},

		_getOptionsForGet: function(req, requesterChannel) {

			const method = 'GET',
@@ -223,14 +193,6 @@ define([
			return this._merge([options, req.options || {}]);
		},

		_requestRequest: function(target, req) {

			var url = this._getRequestRequestTarget(target, req),
				options = this._getRequestRequestOptions(req);

			return this._launchRequest(url, options);
		},

		_performRequest: function(req, requesterChannel) {

			const url = this._getTargetForRequest(req, requesterChannel),
@@ -239,17 +201,6 @@ define([
			return this._launchRequest(url, options);
		},

		_getRequestRequestTarget: function(target, req) {

			const action = req.action;

			if (action?.length) {
				return this._getTargetWithEndingSlash(target) + action;
			}

			return target;
		},

		_getTargetForRequest: function(req, requesterChannel) {

			let target = this._getTargetWithPathParamsReplaced(req.target, requesterChannel);
@@ -262,33 +213,6 @@ define([
			return target;
		},

		_getRequestRequestOptions: function(req) {

			var requestHeaders = this._getRequestRequestHeaders(req),
				headers = lang.mixin({}, this.headers, requestHeaders, req.headers || {}),
				requestQuery = this._getRequestRequestQuery(req),
				query = lang.mixin({}, requestQuery, req.query || {}),
				reqOptions = req.options || {},
				method = req.method || 'GET';

			var options = {
				method: method,
				headers: headers,
				sync: this.sync,
				preventCache: this.preventCache,
				timeout: this.timeout,
				handleAs: this.handleAs
			};

			if (method === 'POST') {
				options.data = JSON.stringify(query);
			} else {
				options.query = query;
			}

			return lang.mixin(options, reqOptions);
		},

		_getOptionsForRequest: function(req, requesterChannel) {

			const method = req.method || 'GET';