Bezahlabschluss (Mollie)
This commit is contained in:
149
src/client/lib/ausweisSpeichern.ts
Normal file
149
src/client/lib/ausweisSpeichern.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
|
||||
import { api } from "astro-typesafe-api/client"
|
||||
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import Cookies from "js-cookie";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { AufnahmeClient, BedarfsausweisWohnenClient, getAusweisartFromUUID, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js";
|
||||
import { Enums } from "@ibcornelsen/database/client";
|
||||
|
||||
export async function ausweisSpeichern(
|
||||
ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient,
|
||||
objekt: ObjektClient,
|
||||
aufnahme: AufnahmeClient,
|
||||
bilder: (UploadedGebaeudeBild & { base64?: string })[],
|
||||
ausweisart: Enums.Ausweisart
|
||||
) {
|
||||
if (objekt.uid) {
|
||||
await api.objekt._uid.PATCH.fetch({
|
||||
...exclude(objekt, ["uid"])
|
||||
}, {
|
||||
params: {
|
||||
uid: objekt.uid
|
||||
},
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const { uid } = await api.objekt.PUT.fetch({
|
||||
...exclude(objekt, ["uid"])
|
||||
}, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
|
||||
objekt.uid = uid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (aufnahme.uid) {
|
||||
await api.aufnahme._uid.PATCH.fetch({
|
||||
...exclude(aufnahme, ["uid"])
|
||||
}, {
|
||||
params: {
|
||||
uid: aufnahme.uid
|
||||
},
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const { uid } = await api.aufnahme.PUT.fetch({
|
||||
aufnahme,
|
||||
uid_objekt: objekt.uid
|
||||
}, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
|
||||
aufnahme.uid = uid
|
||||
}
|
||||
|
||||
let patchRoute: any;
|
||||
let putRoute: any;
|
||||
if (ausweisart = Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
patchRoute = api["verbrauchsausweis-wohnen"]._uid.PATCH
|
||||
putRoute = api["verbrauchsausweis-wohnen"].PUT
|
||||
} else if (ausweisart = Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
patchRoute = api["verbrauchsausweis-gewerbe"]._uid.PATCH
|
||||
putRoute = api["verbrauchsausweis-gewerbe"].PUT
|
||||
} else if (ausweisart = Enums.Ausweisart.BedarfsausweisWohnen) {
|
||||
patchRoute = api["bedarfsausweis-wohnen"]._uid.PATCH
|
||||
putRoute = api["bedarfsausweis-wohnen"].PUT
|
||||
}
|
||||
|
||||
if (ausweis.uid) {
|
||||
await patchRoute.fetch({
|
||||
...exclude(ausweis, ["uid"])
|
||||
}, {
|
||||
params: {
|
||||
uid: ausweis.uid
|
||||
},
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
} else {
|
||||
const { uid } = await putRoute.fetch({
|
||||
ausweis,
|
||||
uid_aufnahme: aufnahme.uid
|
||||
}, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
|
||||
ausweis.uid = uid;
|
||||
}
|
||||
|
||||
for (const bild of bilder) {
|
||||
if (bild.uid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const response = await api.objekt._uid.bilder.PUT.fetch({
|
||||
base64: bild.base64,
|
||||
kategorie: bild.kategorie
|
||||
}, {
|
||||
params: {
|
||||
uid: objekt.uid
|
||||
},
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}`
|
||||
}
|
||||
})
|
||||
|
||||
bild.uid = response.uid
|
||||
}
|
||||
|
||||
return {
|
||||
uid_ausweis: ausweis.uid,
|
||||
uid_aufnahme: aufnahme.uid,
|
||||
uid_objekt: objekt.uid
|
||||
}
|
||||
|
||||
|
||||
// await client.v1.tickets.erstellen.mutate({
|
||||
// titel: "Ausweis konnte nicht gespeichert werden",
|
||||
// beschreibung: e.stack,
|
||||
// email: user.email ?? "",
|
||||
// metadata: JSON.stringify({
|
||||
// ausweis,
|
||||
// }),
|
||||
// });
|
||||
|
||||
// addNotification({
|
||||
// dismissable: false,
|
||||
// message:
|
||||
// "Ausweis konnte nicht gespeichert werden, bitte versuchen sie es erneut.",
|
||||
// subtext:
|
||||
// "Sollte das Problem weiterhin bestehen, kontaktieren sie bitte den Support.",
|
||||
// timeout: 6000,
|
||||
// type: "error",
|
||||
// });
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user