Skip to content

Commit

Permalink
refactor: Message/MailAccount inherit from BaseProxy
Browse files Browse the repository at this point in the history
sendRequests() serves as an override for injecting additional information
into the request

refs #255
  • Loading branch information
ThorstenSuckow committed Nov 25, 2022
1 parent f6b3b8d commit 484023a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
61 changes: 61 additions & 0 deletions src/data/mail/BaseProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* conjoon
* extjs-app-webmail
* Copyright (C) 2022 Thorsten Suckow-Homberg https://github.com/conjoon/extjs-app-webmail
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
*
*/
Ext.define("conjoon.cn_mail.data.mail.BaseProxy", {

extend: "Ext.data.proxy.Rest",

requires: [
"conjoon.cn_mail.data.mail.message.proxy.UtilityMixin"
],

mixins: {
utilityMixin: "conjoon.cn_mail.data.mail.message.proxy.UtilityMixin"
},

/**
* The entity being used with this Proxy.
* @cfg {string}
*/
entityName: null,

appendId: false,


/**
* @param request
* @returns {*}
*/
sendRequest (request) {

const me = this;

return me.callParent(arguments);
}

});
5 changes: 2 additions & 3 deletions src/data/mail/account/proxy/MailAccountProxy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* conjoon
* extjs-app-webmail
* Copyright (C) 2017-2021 Thorsten Suckow-Homberg https://github.com/conjoon/extjs-app-webmail
* Copyright (C) 2017-2022 Thorsten Suckow-Homberg https://github.com/conjoon/extjs-app-webmail
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
Expand Down Expand Up @@ -37,7 +37,7 @@
*/
Ext.define("conjoon.cn_mail.data.mail.account.proxy.MailAccountProxy", {

extend: "Ext.data.proxy.Rest",
extend: "conjoon.cn_mail.data.mail.BaseProxy",

requires: [
"conjoon.cn_mail.data.mail.account.reader.MailAccountJsonReader"
Expand All @@ -51,7 +51,6 @@ Ext.define("conjoon.cn_mail.data.mail.account.proxy.MailAccountProxy", {

idParam: "id",

appendId: false,

/**
* @private
Expand Down
21 changes: 4 additions & 17 deletions src/data/mail/message/proxy/MessageEntityProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@
*/
Ext.define("conjoon.cn_mail.data.mail.message.proxy.MessageEntityProxy", {

extend: "Ext.data.proxy.Rest",
extend: "conjoon.cn_mail.data.mail.BaseProxy",

requires: [
// @define
"l8",
"conjoon.cn_mail.data.mail.message.reader.MessageEntityJsonReader",
"conjoon.cn_mail.data.mail.message.proxy.UtilityMixin",
"conjoon.cn_mail.data.mail.message.writer.MessageEntityWriter"
],

mixins: {
utilityMixin: "conjoon.cn_mail.data.mail.message.proxy.UtilityMixin"
},

alias: "proxy.cn_mail-mailmessageentityproxy",

Expand All @@ -56,21 +52,12 @@ Ext.define("conjoon.cn_mail.data.mail.message.proxy.MessageEntityProxy", {

idParam: "localId",

appendId: false,

validEntityNames: [
"MessageDraft",
"MessageItem",
"MessageBody"
],

/**
* The entity being used with this Proxy. Can be any of MessageItem,
* MessageDraft or MessageBody.
* @cfg {string}
*/
entityName: null,


/**
* Assembles the url in preparation for #buildUrl.
Expand Down Expand Up @@ -150,12 +137,12 @@ Ext.define("conjoon.cn_mail.data.mail.message.proxy.MessageEntityProxy", {
case "update":
delete finalParams.target;
appendUrl = me.entityName;
break;
break;
case "read":
if (["MessageBody", "MessageItem", "MessageDraft"].includes(target)) {
appendUrl = (target === "MessageBody" ? "MessageBody" : "");
finalParams = Object.assign({}, me.getDefaultParameters(target));
}
}
break;
}

Expand All @@ -164,7 +151,7 @@ Ext.define("conjoon.cn_mail.data.mail.message.proxy.MessageEntityProxy", {
finalParams.action = "move";
}

request.setParams(Ext.apply(request.getParams() || {}, finalParams));
request.setParams(Object.assign(request.getParams() || {}, finalParams));

if (action !== "create") {
if (Object.prototype.hasOwnProperty.call(source, "id")) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/data/mail/account/proxy/MailAccountProxyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ StartTest(t => {

let proxy = Ext.create("conjoon.cn_mail.data.mail.account.proxy.MailAccountProxy");

t.isInstanceOf(proxy, "Ext.data.proxy.Rest");
t.isInstanceOf(proxy, "conjoon.cn_mail.data.mail.BaseProxy");

t.expect(proxy.getIdParam()).toBe("id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ StartTest(t => {

let proxy = Ext.create("conjoon.cn_mail.data.mail.message.proxy.MessageEntityProxy");

t.isInstanceOf(proxy, "Ext.data.proxy.Rest");
t.isInstanceOf(proxy, "conjoon.cn_mail.data.mail.BaseProxy");

t.expect(proxy.getIdParam()).toBe("localId");

Expand Down

0 comments on commit 484023a

Please sign in to comment.