Datenblatt und Verbrauchsausweis verbessert
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Aufnahme, BedarfsausweisGewerbe, Bild, Objekt, prisma, Unterlage, VerbrauchsausweisWohnen } from "./prisma.js";
|
import { Aufnahme, BedarfsausweisGewerbe, BedarfsausweisWohnen, Bild, Objekt, prisma, Unterlage, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "./prisma.js";
|
||||||
|
|
||||||
export async function getVerbrauchsausweisWohnen(id: string): Promise<VerbrauchsausweisWohnen | null> {
|
export async function getVerbrauchsausweisWohnen(id: string): Promise<VerbrauchsausweisWohnen | null> {
|
||||||
return await prisma.verbrauchsausweisWohnen.findUnique({
|
return await prisma.verbrauchsausweisWohnen.findUnique({
|
||||||
@@ -8,6 +8,22 @@ export async function getVerbrauchsausweisWohnen(id: string): Promise<Verbrauchs
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getVerbrauchsausweisGewerbe(id: string): Promise<VerbrauchsausweisGewerbe | null> {
|
||||||
|
return await prisma.verbrauchsausweisGewerbe.findUnique({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getBedarfsausweisWohnen(id: string): Promise<BedarfsausweisWohnen | null> {
|
||||||
|
return await prisma.bedarfsausweisWohnen.findUnique({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export async function getBedarfsausweisGewerbe(id: string): Promise<BedarfsausweisGewerbe | null> {
|
export async function getBedarfsausweisGewerbe(id: string): Promise<BedarfsausweisGewerbe | null> {
|
||||||
return await prisma.bedarfsausweisGewerbe.findUnique({
|
return await prisma.bedarfsausweisGewerbe.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -6,9 +6,11 @@ import { Enums } from "#lib/client/prisma.js";
|
|||||||
import { APIRoute } from "astro";
|
import { APIRoute } from "astro";
|
||||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||||
import { getS3File } from "#lib/s3.js";
|
import { getS3File } from "#lib/s3.js";
|
||||||
|
import { getVerbrauchsausweisWohnen, getVerbrauchsausweisGewerbe, getAufnahme, getObjekt, getBilder } from "#lib/server/db.js";
|
||||||
|
import { getCurrentUser } from "#lib/server/user.js";
|
||||||
|
|
||||||
export const GET: APIRoute = async (Astro) => {
|
export const GET: APIRoute = async (Astro) => {
|
||||||
const ausweis_id = Astro.url.searchParams.get("uid");
|
const ausweis_id = Astro.url.searchParams.get("id");
|
||||||
|
|
||||||
if (!ausweis_id) {
|
if (!ausweis_id) {
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
@@ -16,8 +18,6 @@ export const GET: APIRoute = async (Astro) => {
|
|||||||
|
|
||||||
const ausweisart = getAusweisartFromId(ausweis_id)
|
const ausweisart = getAusweisartFromId(ausweis_id)
|
||||||
|
|
||||||
const caller = createCaller(Astro);
|
|
||||||
|
|
||||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||||
let objekt: ObjektClient = {} as ObjektClient;
|
let objekt: ObjektClient = {} as ObjektClient;
|
||||||
@@ -25,23 +25,9 @@ export const GET: APIRoute = async (Astro) => {
|
|||||||
let bilder: UploadedGebaeudeBild[] = []
|
let bilder: UploadedGebaeudeBild[] = []
|
||||||
|
|
||||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||||
ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, {
|
ausweis = await getVerbrauchsausweisWohnen(ausweis_id)
|
||||||
params: {
|
|
||||||
id: ausweis_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||||
ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, {
|
ausweis = await getVerbrauchsausweisGewerbe(ausweis_id)
|
||||||
params: {
|
|
||||||
id: ausweis_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -49,29 +35,13 @@ export const GET: APIRoute = async (Astro) => {
|
|||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
aufnahme = await caller.aufnahme._id.GET.fetch(undefined, {
|
aufnahme = await getAufnahme(ausweis.aufnahme_id)
|
||||||
params: {
|
|
||||||
id: ausweis.aufnahme_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
objekt = await caller.objekt._id.GET.fetch(undefined, {
|
objekt = await getObjekt(aufnahme.objekt_id)
|
||||||
params: {
|
|
||||||
id: ausweis.objekt_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
user = await caller.user.self.GET.fetch(undefined, {
|
bilder = await getBilder(ausweis.aufnahme_id)
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
user = await getCurrentUser(Astro)
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
||||||
if (ausweis.alte_ausweis_id) {
|
if (ausweis.alte_ausweis_id) {
|
||||||
|
|||||||
@@ -8,17 +8,17 @@ import { Enums } from "#lib/client/prisma.js";
|
|||||||
import { APIRoute } from "astro";
|
import { APIRoute } from "astro";
|
||||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||||
import { getS3File } from "#lib/s3.js";
|
import { getS3File } from "#lib/s3.js";
|
||||||
|
import { getAufnahme, getBilder, getObjekt, getVerbrauchsausweisGewerbe, getVerbrauchsausweisWohnen } from "#lib/server/db.js";
|
||||||
|
import { getCurrentUser } from "#lib/server/user.js";
|
||||||
|
|
||||||
export const GET: APIRoute = async (Astro) => {
|
export const GET: APIRoute = async (Astro) => {
|
||||||
const uidAusweis = Astro.url.searchParams.get("uid");
|
const ausweis_id = Astro.url.searchParams.get("id");
|
||||||
|
|
||||||
if (!uidAusweis) {
|
if (!ausweis_id) {
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const ausweisart = getAusweisartFromId(uidAusweis)
|
const ausweisart = getAusweisartFromId(ausweis_id)
|
||||||
|
|
||||||
const caller = createCaller(Astro);
|
|
||||||
|
|
||||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||||
@@ -27,23 +27,9 @@ export const GET: APIRoute = async (Astro) => {
|
|||||||
let bilder: UploadedGebaeudeBild[] = []
|
let bilder: UploadedGebaeudeBild[] = []
|
||||||
|
|
||||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||||
ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, {
|
ausweis = await getVerbrauchsausweisWohnen(ausweis_id)
|
||||||
params: {
|
|
||||||
id: uidAusweis
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||||
ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, {
|
ausweis = await getVerbrauchsausweisGewerbe(ausweis_id)
|
||||||
params: {
|
|
||||||
id: uidAusweis
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -51,29 +37,13 @@ export const GET: APIRoute = async (Astro) => {
|
|||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
aufnahme = await caller.aufnahme._id.GET.fetch(undefined, {
|
aufnahme = await getAufnahme(ausweis.aufnahme_id)
|
||||||
params: {
|
|
||||||
id: ausweis.aufnahme_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
objekt = await caller.objekt._id.GET.fetch(undefined, {
|
objekt = await getObjekt(aufnahme.objekt_id)
|
||||||
params: {
|
|
||||||
id: ausweis.objekt_id
|
|
||||||
},
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
user = await caller.user.self.GET.fetch(undefined, {
|
bilder = await getBilder(ausweis.aufnahme_id)
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
user = await getCurrentUser(Astro)
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
||||||
if (ausweis.alte_ausweis_id) {
|
if (ausweis.alte_ausweis_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user