From 3ce11f4cc7e7ec6da4755d2afdba469b01bcc03f Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 9 Oct 2024 11:00:21 +0200 Subject: [PATCH] =?UTF-8?q?feat(api-service):=20Methode=20f=C3=BCr=20Share?= =?UTF-8?q?-Request=20erstellt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wwwroot/js/api-service.js | 36 +++++++++++-------- .../wwwroot/js/api-service.min.js | 4 +-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/EnvelopeGenerator.Web/wwwroot/js/api-service.js b/EnvelopeGenerator.Web/wwwroot/js/api-service.js index 70a05a70..cac4816e 100644 --- a/EnvelopeGenerator.Web/wwwroot/js/api-service.js +++ b/EnvelopeGenerator.Web/wwwroot/js/api-service.js @@ -1,25 +1,29 @@ class Content { - static get JSON () { + static get JSON() { return 'application/json'; } } class API { - static get REJECT_URL () { + static get REJECT_URL() { return `/api/envelope/reject`; } - static get REJECT_REDIR_URL(){ + static get REJECT_REDIR_URL() { return `/envelopekey/${API.ENV_KEY}/rejected`; } + static get SHARE_URL() { + return `/readonly` + } + static __XSRF_TOKEN static get XSRF_TOKEN() { API.__XSRF_TOKEN ??= document.getElementsByName('__RequestVerificationToken')[0].value; return API.__XSRF_TOKEN; } - static get ENV_KEY(){ + static get ENV_KEY() { return ENV_KEY ?? document.querySelector('meta[name="env-key"]').getAttribute('content'); } } @@ -28,20 +32,20 @@ const submitForm = async form => await fetch(form.action, { method: form.method, body: new FormData(form), headers: { - "X-Requested-With": "XMLHttpRequest" + "X-Requested-With": "XMLHttpRequest" } }) const createRequest = async (method, url, body, contentType) => { - return fetch(url, { - credentials: 'include', - method: method, - headers: { - 'Content-Type': contentType, - 'X-XSRF-TOKEN': API.XSRF_TOKEN - }, - body: JSON.stringify(body) - }) + return fetch(url, { + credentials: 'include', + method: method, + headers: { + 'Content-Type': contentType, + 'X-XSRF-TOKEN': API.XSRF_TOKEN + }, + body: JSON.stringify(body) + }) } const createPost = (url, body, contentType) => createRequest('POST', url, body, contentType); @@ -50,4 +54,6 @@ const rejectEnvelope = (reason) => createPost(API.REJECT_URL, reason, Content.JS const redirect = (url) => window.location.href = url; -const redirRejected = () => redirect(API.REJECT_REDIR_URL); \ No newline at end of file +const redirRejected = () => redirect(API.REJECT_REDIR_URL); + +const shareEnvelope = (receiverMail, dateValid) => createPost(API.SHARE_URL, { receiverMail: receiverMail, dateValid: dateValid }); \ 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 3c4ccd64..a5294ecf 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/envelope/reject`}static get REJECT_REDIR_URL(){return`/envelopekey/${API.ENV_KEY}/rejected`}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); \ No newline at end of file +class Content{static get JSON(){return"application/json"}}class API{static get REJECT_URL(){return`/api/envelope/reject`}static get REJECT_REDIR_URL(){return`/envelopekey/${API.ENV_KEY}/rejected`}static get SHARE_URL(){return`/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}); \ No newline at end of file