This commit is contained in:
Moritz Utcke
2025-04-09 11:46:27 -04:00
parent 7665141a5a
commit 8daee69576
35 changed files with 307 additions and 194 deletions

View File

@@ -20,7 +20,11 @@ import { PutObjectCommand } from "@aws-sdk/client-s3";
import { s3Client } from "#lib/s3.js";
import { createInvoice } from "#lib/server/invoice.js";
import { tryCatch } from "#lib/tryCatch.js";
import { getBedarfsausweisWohnenKomplett, getVerbrauchsausweisGewerbeKomplett, getVerbrauchsausweisWohnenKomplett } from "#lib/server/db.js";
import {
getBedarfsausweisWohnenKomplett,
getVerbrauchsausweisGewerbeKomplett,
getVerbrauchsausweisWohnenKomplett,
} from "#lib/server/db.js";
export const GET = defineApiRoute({
input: z.object({
@@ -40,18 +44,18 @@ export const GET = defineApiRoute({
aufnahme: Aufnahme & {
bilder: Bild[];
objekt: Objekt & {
benutzer: Benutzer;
benutzer: Benutzer | null;
};
};
})
| null = null;
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
ausweis = await getVerbrauchsausweisWohnenKomplett(id_ausweis)
ausweis = await getVerbrauchsausweisWohnenKomplett(id_ausweis);
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
ausweis = await getVerbrauchsausweisGewerbeKomplett(id_ausweis)
ausweis = await getVerbrauchsausweisGewerbeKomplett(id_ausweis);
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) {
ausweis = await getBedarfsausweisWohnenKomplett(id_ausweis)
ausweis = await getBedarfsausweisWohnenKomplett(id_ausweis);
}
if (!ausweis) {
@@ -81,22 +85,24 @@ export const GET = defineApiRoute({
}
if (!rechnung.lex_office_id) {
const [result, error] = await tryCatch(createInvoice(ausweis, rechnung));
const [result, error] = await tryCatch(
createInvoice(ausweis, rechnung)
);
if (error) {
return
return;
}
const { id, voucherNumber } = result;
await prisma.rechnung.update({
where: {
id: rechnung.id
id: rechnung.id,
},
data: {
lex_office_id: id
}
})
lex_office_id: id,
},
});
}
const pdfAusweis = await getAnsichtsausweis(
@@ -123,7 +129,7 @@ export const GET = defineApiRoute({
ACL: "private",
});
const response = await s3Client.send(command);
await s3Client.send(command);
}
if (pdfDatenblatt) {
@@ -134,7 +140,7 @@ export const GET = defineApiRoute({
ACL: "private",
});
const response = await s3Client.send(command);
await s3Client.send(command);
}
let text: string;
@@ -230,30 +236,30 @@ fax 040 · 209339859
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
await prisma.verbrauchsausweisWohnen.update({
where: {
id: ausweis.id
},
data: {
ausgestellt: true
}
})
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
await prisma.verbrauchsausweisGewerbe.update({
where: {
id: ausweis.id
},
data: {
ausgestellt: true
}
})
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) {
await prisma.bedarfsausweisWohnen.update({
where: {
id: ausweis.id
id: ausweis.id,
},
data: {
ausgestellt: true,
}
})
},
});
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
await prisma.verbrauchsausweisGewerbe.update({
where: {
id: ausweis.id,
},
data: {
ausgestellt: true,
},
});
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) {
await prisma.bedarfsausweisWohnen.update({
where: {
id: ausweis.id,
},
data: {
ausgestellt: true,
},
});
}
},
});

View File

@@ -1,4 +1,4 @@
import { GEGNachweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
import { UUidWithPrefix } from "#components/Ausweis/types.js";
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
import { generatePrefixedId } from "#lib/db.js";
import { exclude } from "#lib/exclude.js";
@@ -19,7 +19,8 @@ export const PATCH = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
output: z.void(),
headers: {

View File

@@ -25,7 +25,8 @@ export const PUT = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
aufnahme_id: UUidWithPrefix
}),

View File

@@ -1,9 +1,9 @@
import { BedarfsausweisWohnenClient, OptionalNullable, UUidWithPrefix, VerbrauchsausweisWohnenClient, ZodOverlap } from "#components/Ausweis/types.js";
import { BedarfsausweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
import { generatePrefixedId } from "#lib/db.js";
import { exclude } from "#lib/exclude.js";
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
import { BedarfsausweisWohnen, prisma } from "#lib/server/prisma.js";
import { prisma } from "#lib/server/prisma.js";
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
import { BedarfsausweisWohnenSchema } from "src/generated/zod/bedarfsausweiswohnen.js";
import { z } from "zod";
@@ -19,7 +19,8 @@ export const PATCH = defineApiRoute({
zurueckgestellt: true,
created_at: true,
updated_at: true,
storniert: true
storniert: true,
ausweisart: true
}),
output: z.void(),
headers: {

View File

@@ -29,6 +29,7 @@ export const PUT = defineApiRoute({
created_at: true,
updated_at: true,
storniert: true,
ausweisart: true
}),
aufnahme_id: UUidWithPrefix,
}),

View File

@@ -1,4 +1,4 @@
import { GEGNachweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
import { UUidWithPrefix } from "#components/Ausweis/types.js";
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
import { generatePrefixedId } from "#lib/db.js";
import { exclude } from "#lib/exclude.js";
@@ -19,7 +19,8 @@ export const PATCH = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
output: z.void(),
headers: {

View File

@@ -25,7 +25,8 @@ export const PUT = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
aufnahme_id: UUidWithPrefix
}),

View File

@@ -19,7 +19,8 @@ export const PATCH = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
output: z.void(),
headers: {

View File

@@ -25,7 +25,8 @@ export const PUT = defineApiRoute({
rechnung_id: true,
storniert: true,
updated_at: true,
zurueckgestellt: true
zurueckgestellt: true,
ausweisart: true
}),
aufnahme_id: UUidWithPrefix
}),

View File

@@ -14,7 +14,8 @@ export const PATCH = defineApiRoute({
benutzer_id: true,
aufnahme_id: true,
updated_at: true,
created_at: true
created_at: true,
ausweisart: true
}).merge(z.object({
startdatum: z.coerce.date().nullable(),
})),

View File

@@ -21,7 +21,8 @@ export const PUT = defineApiRoute({
aufnahme_id: true,
rechnung_id: true,
updated_at: true,
created_at: true
created_at: true,
ausweisart: true
}).merge(z.object({
startdatum: z.coerce.date().nullable()
})),

View File

@@ -15,7 +15,8 @@ export const PATCH = defineApiRoute({
aufnahme_id: true,
rechnung_id: true,
created_at: true,
updated_at: true
updated_at: true,
ausweisart: true
}).merge(z.object({
startdatum: z.coerce.date().nullable()
})),

View File

@@ -26,7 +26,8 @@ export const PUT = defineApiRoute({
aufnahme_id: true,
rechnung_id: true,
created_at: true,
updated_at: true
updated_at: true,
ausweisart: true
}),
aufnahme_id: UUidWithPrefix
}),

View File

@@ -10,7 +10,6 @@ import ImpersonateUserModule from "#modules/ImpersonateUserModule.svelte";
const caller = createCaller(Astro)
const params = Astro.params;
const page = Number(params.page)
const user = await caller.user.self.GET.fetch(undefined, {
headers: {

View File

@@ -22,15 +22,15 @@ if (user.rolle !== Enums.BenutzerRolle.ADMIN) {
return Astro.redirect("/dashboard")
}
const uid = Astro.url.searchParams.get("uid")
const id = Astro.url.searchParams.get("id")
if (!uid) {
if (!id) {
return Astro.redirect("/404")
}
const searchedUser = await prisma.benutzer.findUnique({
where: {
uid
id
}
})
@@ -40,12 +40,12 @@ if (!searchedUser) {
const refreshTokenExpiry = moment().add(30, "days");
const accessToken = encodeToken({
uid: searchedUser.uid,
id: searchedUser.id,
typ: TokenType.Access,
exp: moment().add(30, "minutes").valueOf(),
});
const refreshToken = encodeToken({
uid: searchedUser.uid,
id: searchedUser.id,
typ: TokenType.Refresh,
exp: refreshTokenExpiry.valueOf(),
});
@@ -60,7 +60,6 @@ Astro.cookies.set(API_ACCESS_TOKEN_COOKIE_NAME, accessToken, {
path: "/",
expires: moment().add(30, "minutes").toDate()
})
Astro.cookies.set("uid", searchedUser.uid)
return Astro.redirect("/dashboard")
---