feat(api-service): Methode für Share-Request erstellt.

This commit is contained in:
Developer 02
2024-10-09 11:00:21 +02:00
parent f2cd34a79e
commit 3ce11f4cc7
2 changed files with 23 additions and 17 deletions

View File

@@ -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);
const redirRejected = () => redirect(API.REJECT_REDIR_URL);
const shareEnvelope = (receiverMail, dateValid) => createPost(API.SHARE_URL, { receiverMail: receiverMail, dateValid: dateValid });