From bac9aebbc39f7418541ec9eefcac31ee78ea1f96 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 19 Sep 2025 09:59:57 +0200 Subject: [PATCH] refactor(api): replace arrow functions with function declarations and simplify defaults - Removed unused Content class - Converted async arrow functions to standard function declarations - Added default 'application/json' for createRequest and createPost - Improved readability and consistency across API helpers --- .../wwwroot/js/api-service.js | 44 +++++++++++-------- .../wwwroot/js/api-service.min.js | 4 +- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.js index 1fa8d35a..1912443c 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.js @@ -1,9 +1,3 @@ -class Content { - static get JSON() { - return 'application/json'; - } -} - class API { static get REJECT_URL() { return `/api/annotation/reject`; @@ -28,15 +22,17 @@ class API { } } -const submitForm = async form => await fetch(form.action, { - method: form.method, - body: new FormData(form), - headers: { - "X-Requested-With": "XMLHttpRequest" - } -}) +function submitForm(form) { + fetch(form.action, { + method: form.method, + body: new FormData(form), + headers: { + "X-Requested-With": "XMLHttpRequest" + } + }) +} -const createRequest = async (method, url, body, contentType) => { +function createRequest(method, url, body, contentType = 'application/json') { return fetch(url, { credentials: 'include', method: method, @@ -48,12 +44,22 @@ const createRequest = async (method, url, body, contentType) => { }) } -const createPost = (url, body, contentType) => createRequest('POST', url, body, contentType); +function createPost(url, body, contentType = 'application/json') { + return createRequest('POST', url, body, contentType); +} -const rejectEnvelope = (reason) => createPost(API.REJECT_URL, reason, Content.JSON); +function rejectEnvelope(reason) { + return createPost(API.REJECT_URL, reason, Content.JSON); +} -const redirect = (url) => window.location.href = url; +function redirect(url) { + return window.location.href = url; +} -const redirRejected = () => redirect(API.REJECT_REDIR_URL); +function redirRejected() { + return redirect(API.REJECT_REDIR_URL); +} -const shareEnvelope = (receiverMail, dateValid) => createPost(API.SHARE_URL, { receiverMail: receiverMail, dateValid: dateValid }, Content.JSON); \ No newline at end of file +function shareEnvelope(receiverMail, dateValid) { + return createPost(API.SHARE_URL, { receiverMail: receiverMail, dateValid: dateValid }, Content.JSON); +} \ No newline at end of file diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js index e2e2e281..85b9854f 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.min.js @@ -1,2 +1,2 @@ -class Content{static get JSON(){return"application/json"}}class API{static get REJECT_URL(){return`/api/annotation/reject`}static get REJECT_REDIR_URL(){return`/envelope/${API.ENV_KEY}`}static get SHARE_URL(){return`/api/readonly`}static __XSRF_TOKEN - static get XSRF_TOKEN(){return API.__XSRF_TOKEN??=document.getElementsByName("__RequestVerificationToken")[0].value,API.__XSRF_TOKEN}static get ENV_KEY(){return ENV_KEY??document.querySelector('meta[name="env-key"]').getAttribute("content")}}const submitForm=async n=>await fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}}),createRequest=async(n,t,i,r)=>fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":API.XSRF_TOKEN},body:JSON.stringify(i)}),createPost=(n,t,i)=>createRequest("POST",n,t,i),rejectEnvelope=n=>createPost(API.REJECT_URL,n,Content.JSON),redirect=n=>window.location.href=n,redirRejected=()=>redirect(API.REJECT_REDIR_URL),shareEnvelope=(n,t)=>createPost(API.SHARE_URL,{receiverMail:n,dateValid:t},Content.JSON); \ No newline at end of file +function submitForm(n){fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}})}function createRequest(n,t,i,r="application/json"){return fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":API.XSRF_TOKEN},body:JSON.stringify(i)})}function createPost(n,t,i="application/json"){return createRequest("POST",n,t,i)}function rejectEnvelope(n){return createPost(API.REJECT_URL,n,Content.JSON)}function redirect(n){return window.location.href=n}function redirRejected(){return redirect(API.REJECT_REDIR_URL)}function shareEnvelope(n,t){return createPost(API.SHARE_URL,{receiverMail:n,dateValid:t},Content.JSON)}class API{static get REJECT_URL(){return`/api/annotation/reject`}static get REJECT_REDIR_URL(){return`/envelope/${API.ENV_KEY}`}static get SHARE_URL(){return`/api/readonly`}static __XSRF_TOKEN + static get XSRF_TOKEN(){return API.__XSRF_TOKEN??=document.getElementsByName("__RequestVerificationToken")[0].value,API.__XSRF_TOKEN}static get ENV_KEY(){return ENV_KEY??document.querySelector('meta[name="env-key"]').getAttribute("content")}} \ No newline at end of file