Ausweis erstellen
This commit is contained in:
@@ -5,6 +5,7 @@ export const createCaller = createCallerFactory({
|
||||
"klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"),
|
||||
"postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"),
|
||||
"unterlage": await import("../src/pages/api/unterlage.ts"),
|
||||
"ausweise": await import("../src/pages/api/ausweise/index.ts"),
|
||||
"admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"),
|
||||
"admin/bedarfsausweis-ausstellen": await import("../src/pages/api/admin/bedarfsausweis-ausstellen.ts"),
|
||||
"admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"),
|
||||
@@ -12,31 +13,30 @@ export const createCaller = createCallerFactory({
|
||||
"admin/nicht-ausstellen": await import("../src/pages/api/admin/nicht-ausstellen.ts"),
|
||||
"admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"),
|
||||
"admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"),
|
||||
"ausweise": await import("../src/pages/api/ausweise/index.ts"),
|
||||
"aufnahme": await import("../src/pages/api/aufnahme/index.ts"),
|
||||
"auth/access-token": await import("../src/pages/api/auth/access-token.ts"),
|
||||
"auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"),
|
||||
"auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"),
|
||||
"bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].ts"),
|
||||
"bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"),
|
||||
"bedarfsausweis-wohnen/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"),
|
||||
"bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"),
|
||||
"bilder/[id]": await import("../src/pages/api/bilder/[id].ts"),
|
||||
"auth/access-token": await import("../src/pages/api/auth/access-token.ts"),
|
||||
"auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"),
|
||||
"auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"),
|
||||
"geg-nachweis-gewerbe/[id]": await import("../src/pages/api/geg-nachweis-gewerbe/[id].ts"),
|
||||
"geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"),
|
||||
"bilder/[id]": await import("../src/pages/api/bilder/[id].ts"),
|
||||
"geg-nachweis-wohnen/[id]": await import("../src/pages/api/geg-nachweis-wohnen/[id].ts"),
|
||||
"geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"),
|
||||
"objekt": await import("../src/pages/api/objekt/index.ts"),
|
||||
"rechnung/[id]": await import("../src/pages/api/rechnung/[id].ts"),
|
||||
"rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"),
|
||||
"rechnung": await import("../src/pages/api/rechnung/index.ts"),
|
||||
"ticket": await import("../src/pages/api/ticket/index.ts"),
|
||||
"user": await import("../src/pages/api/user/index.ts"),
|
||||
"user/self": await import("../src/pages/api/user/self.ts"),
|
||||
"objekt": await import("../src/pages/api/objekt/index.ts"),
|
||||
"verbrauchsausweis-gewerbe/[id]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[id].ts"),
|
||||
"verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"),
|
||||
"verbrauchsausweis-wohnen/[id]": await import("../src/pages/api/verbrauchsausweis-wohnen/[id].ts"),
|
||||
"verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"),
|
||||
"ticket": await import("../src/pages/api/ticket/index.ts"),
|
||||
"user": await import("../src/pages/api/user/index.ts"),
|
||||
"user/self": await import("../src/pages/api/user/self.ts"),
|
||||
"webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"),
|
||||
"aufnahme/[id]/bilder": await import("../src/pages/api/aufnahme/[id]/bilder.ts"),
|
||||
"aufnahme/[id]": await import("../src/pages/api/aufnahme/[id]/index.ts"),
|
||||
|
||||
@@ -100,7 +100,7 @@ export type OptionalNullable<T> = T extends object ? {
|
||||
[K in keyof PickNotNullable<T>]: OptionalNullable<T[K]>
|
||||
} : T;
|
||||
|
||||
export const UUidWithPrefix = z.string().refine((value) => {
|
||||
export const IDWithPrefix = z.string().refine((value) => {
|
||||
const prefixedUUidRegex = /^([A-Z]{2})[0-9A-Z]{6,9}$/i
|
||||
|
||||
const match = value.match(prefixedUUidRegex)
|
||||
@@ -113,7 +113,7 @@ export const UUidWithPrefix = z.string().refine((value) => {
|
||||
})
|
||||
|
||||
export function getAusweisartFromId(id: string): Enums.Ausweisart | null {
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as crypto from "crypto";
|
||||
* @param prefix Ein Optionales Präfix, welches vor die ID geschrieben wird, damit diese identifizierbar bleibt.
|
||||
* @returns Die generierte ID
|
||||
*/
|
||||
export function generatePrefixedId(length: number, prefix: string = ""): string {
|
||||
export function generateIDWithPrefix(length: number, prefix: string = ""): string {
|
||||
// Generating entropy is faster than complex math operations, so we use the simplest way
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
|
||||
const characterCount = characters.length;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { Enums } from "#lib/client/prisma";
|
||||
import { z } from "zod";
|
||||
|
||||
export const filterAusweise = z.object({
|
||||
uid: UUidWithPrefix.optional(),
|
||||
uid: IDWithPrefix.optional(),
|
||||
ausgestellt: z.boolean().optional(),
|
||||
ausstellgrund: z.nativeEnum(Enums.Ausstellgrund).optional(),
|
||||
bestellt: z.boolean().optional(),
|
||||
|
||||
@@ -97,6 +97,20 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
|
||||
ausweis.id = null;
|
||||
aufnahme.id = null;
|
||||
delete aufnahme.erstellungsdatum;
|
||||
ausweis.created_at = new Date()
|
||||
ausweis.updated_at = new Date();
|
||||
ausweis.alte_ausweis_id = null;
|
||||
ausweis.ausgestellt = false;
|
||||
ausweis.bestellt = false;
|
||||
ausweis.kontrolldatei_angefragt = false;
|
||||
ausweis.energieeffizienzklasse = null;
|
||||
ausweis.ausstellungsdatum = null;
|
||||
ausweis.ausweistyp = Enums.AusweisTyp.Standard;
|
||||
ausweis.zurueckgestellt = false;
|
||||
ausweis.storniert = false;
|
||||
ausweis.rechnung_id = null;
|
||||
ausweis.registriernummer = null;
|
||||
// Die Daten sollen nicht aus dem localStorage genommen werden sonst kann es vorkommen, dass die ID noch besteht und der Vorgang nicht neu angelegt wird.
|
||||
loadFromDatabase = true;
|
||||
} else if (typ === AusstellungsTyp.Speichern) {
|
||||
@@ -176,7 +190,7 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
}
|
||||
|
||||
ausweis.id = null;
|
||||
aufnahme.erstellungsdatum = null
|
||||
delete aufnahme.erstellungsdatum;
|
||||
ausweis.created_at = new Date()
|
||||
ausweis.updated_at = new Date();
|
||||
ausweis.alte_ausweis_id = null;
|
||||
@@ -188,6 +202,8 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
ausweis.ausweistyp = Enums.AusweisTyp.Standard;
|
||||
ausweis.zurueckgestellt = false;
|
||||
ausweis.storniert = false;
|
||||
ausweis.rechnung_id = null;
|
||||
ausweis.registriernummer = null;
|
||||
// Die Daten sollen nicht aus dem localStorage genommen werden sonst kann es vorkommen, dass die ID noch besteht und der Vorgang nicht neu angelegt wird.
|
||||
loadFromDatabase = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
getAusweisartFromId,
|
||||
UUidWithPrefix,
|
||||
IDWithPrefix,
|
||||
} from "#components/Ausweis/types.js";
|
||||
import {
|
||||
adminMiddleware,
|
||||
@@ -18,7 +18,7 @@ import { getPrismaAusweisAdapter } from "#lib/server/ausweis.js";
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
input: z.object({
|
||||
id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: adminMiddleware,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { transport } from "#lib/mail.js";
|
||||
import { adminMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { mollieClient } from "#lib/mollie.js";
|
||||
@@ -10,7 +10,7 @@ import { z } from "zod";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.object({
|
||||
ausweis_id: UUidWithPrefix
|
||||
ausweis_id: IDWithPrefix
|
||||
}),
|
||||
middleware: adminMiddleware,
|
||||
async fetch(input, context, transfer) {
|
||||
|
||||
@@ -2,11 +2,11 @@ import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.array(UUidWithPrefix),
|
||||
input: z.array(IDWithPrefix),
|
||||
output: z.void(),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AufnahmeClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { AufnahmeClient, OptionalNullable, IDWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
|
||||
@@ -2,11 +2,11 @@ import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { UnterlageSchema } from "src/generated/zod/unterlage.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.array(UUidWithPrefix),
|
||||
input: z.array(IDWithPrefix),
|
||||
output: z.void(),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js"
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js"
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js"
|
||||
import { generatePrefixedId } from "#lib/db.js"
|
||||
import { generateIDWithPrefix } from "#lib/db.js"
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js"
|
||||
import { prisma } from "#lib/server/prisma.js"
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server"
|
||||
@@ -16,10 +16,10 @@ export const PUT = defineApiRoute({
|
||||
}).merge(z.object({
|
||||
baujahr_klima: z.array(z.number().int().positive()).optional()
|
||||
})),
|
||||
objekt_id: UUidWithPrefix
|
||||
objekt_id: IDWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
@@ -39,7 +39,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Aufnahme)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Aufnahme)
|
||||
|
||||
const aufnahme = await prisma.aufnahme.create({
|
||||
data: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AufnahmeClient, ObjektClient, BildClient, UUidWithPrefix, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
|
||||
import { AufnahmeClient, ObjektClient, BildClient, IDWithPrefix, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
|
||||
import { filterAusweise } from "#lib/filters.js";
|
||||
import { omit } from "#lib/helpers.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
|
||||
@@ -5,7 +5,7 @@ import { encodeToken } from "../../../lib/auth/token.js";
|
||||
import { validatePassword } from "../../../lib/password.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { TokenType } from "#lib/auth/types.js";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
@@ -20,7 +20,7 @@ export const GET = defineApiRoute({
|
||||
passwort: z.string().min(8).max(100),
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
accessToken: z.string(),
|
||||
refreshToken: z.string(),
|
||||
refreshTokenBase64: z.string(),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -64,7 +64,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -122,7 +122,7 @@ export const DELETE = defineApiRoute({
|
||||
}
|
||||
})
|
||||
|
||||
const event_id = generatePrefixedId(9, VALID_UUID_PREFIXES.Ticket)
|
||||
const event_id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Ticket)
|
||||
|
||||
// Wir erstellen ein Event, dass der Nachweis storniert wurde
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
@@ -164,9 +164,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: BedarfsausweisGewerbeSchema.merge(z.object({
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
aufnahme_id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
benutzer_id: IDWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
@@ -29,9 +29,9 @@ export const PUT = defineApiRoute({
|
||||
zurueckgestellt: true,
|
||||
ausweisart: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
aufnahme_id: IDWithPrefix
|
||||
}),
|
||||
output: UUidWithPrefix,
|
||||
output: IDWithPrefix,
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
@@ -48,7 +48,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.BedarfsausweisGewerbe)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.BedarfsausweisGewerbe)
|
||||
|
||||
const nachweis = await prisma.bedarfsausweisGewerbe.create({
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BedarfsausweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { BedarfsausweisWohnenClient, OptionalNullable, IDWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -63,7 +63,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -124,7 +124,7 @@ export const DELETE = defineApiRoute({
|
||||
}
|
||||
})
|
||||
|
||||
const event_id = generatePrefixedId(9, VALID_UUID_PREFIXES.Ticket)
|
||||
const event_id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Ticket)
|
||||
|
||||
// Wir erstellen ein Event, dass der Ausweis storniert wurde
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
@@ -166,9 +166,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<OptionalNullable<BedarfsausweisWohnenClient>>(BedarfsausweisWohnenSchema.merge(z.object({
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
aufnahme_id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
benutzer_id: IDWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import {
|
||||
authorizationHeaders,
|
||||
authorizationMiddleware,
|
||||
@@ -32,9 +32,9 @@ export const PUT = defineApiRoute({
|
||||
storniert: true,
|
||||
ausweisart: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
output: UUidWithPrefix,
|
||||
output: IDWithPrefix,
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
@@ -52,7 +52,7 @@ export const PUT = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(
|
||||
const id = generateIDWithPrefix(
|
||||
9,
|
||||
VALID_UUID_PREFIXES.BedarfsausweisWohnen
|
||||
);
|
||||
|
||||
@@ -3,23 +3,25 @@ import { prisma } from "#lib/server/prisma.js";
|
||||
import { defineApiRoute, APIError } from "astro-typesafe-api/server";
|
||||
import { z } from "astro:content";
|
||||
import isBase64 from "is-base64";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
import sharp from "sharp"
|
||||
import sharp from "sharp";
|
||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { s3Client } from "#lib/s3.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: BildSchema.pick({
|
||||
kategorie: true,
|
||||
name: true
|
||||
}).merge(z.object({
|
||||
data: z.string()
|
||||
})),
|
||||
name: true,
|
||||
}).merge(
|
||||
z.object({
|
||||
data: z.string(),
|
||||
})
|
||||
),
|
||||
output: z.object({
|
||||
id: z.string({ description: "Die id des Bildes." })
|
||||
id: z.string({ description: "Die id des Bildes." }),
|
||||
}),
|
||||
async fetch(input) {
|
||||
const data = input.data;
|
||||
@@ -31,44 +33,40 @@ export const PUT = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
const dataWithoutPrefix = data.replace(
|
||||
/^data:image\/\w+;base64,/,
|
||||
""
|
||||
);
|
||||
const dataWithoutPrefix = data.replace(/^data:image\/\w+;base64,/, "");
|
||||
const buffer = Buffer.from(dataWithoutPrefix, "base64");
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Bild)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Bild);
|
||||
|
||||
const bild = await prisma.bild.create({
|
||||
data: {
|
||||
id,
|
||||
kategorie: input.kategorie,
|
||||
name: input.name
|
||||
}
|
||||
name: input.name,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
// Wir optimieren das Bild und konvertieren es in JPEG
|
||||
const optimizedBuffer = await sharp(buffer).jpeg({ quality: 80 }).toBuffer();
|
||||
const optimizedBuffer = await sharp(buffer)
|
||||
.jpeg({ quality: 80 })
|
||||
.toBuffer();
|
||||
|
||||
const command = new PutObjectCommand({
|
||||
Bucket: "ibc-images",
|
||||
Key: `${id}.jpg`,
|
||||
Body: optimizedBuffer,
|
||||
ACL: "private"
|
||||
})
|
||||
ACL: "private",
|
||||
});
|
||||
|
||||
const response = await s3Client.send(command)
|
||||
} catch(e) {
|
||||
const response = await s3Client.send(command);
|
||||
} catch (e) {
|
||||
// Bild wurde nicht gespeichert, wir löschen den Eintrag wieder
|
||||
await prisma.bild.delete({
|
||||
where: {
|
||||
id
|
||||
}
|
||||
})
|
||||
id,
|
||||
},
|
||||
});
|
||||
// Und geben einen Fehler zurück
|
||||
throw new APIError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
@@ -77,14 +75,14 @@ export const PUT = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
id
|
||||
id,
|
||||
};
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
export const DELETE = defineApiRoute({
|
||||
input: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix,
|
||||
}),
|
||||
middleware: maybeAuthorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
@@ -95,24 +93,24 @@ export const DELETE = defineApiRoute({
|
||||
id: input.id,
|
||||
aufnahme: {
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await prisma.bild.delete({
|
||||
where: {
|
||||
id: input.id,
|
||||
aufnahme_id: null
|
||||
}
|
||||
})
|
||||
aufnahme_id: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
throw new APIError({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
message: "Bild konnte nicht gelöscht werden."
|
||||
})
|
||||
message: "Bild konnte nicht gelöscht werden.",
|
||||
});
|
||||
}
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { z } from "zod";
|
||||
import isBase64 from "is-base64";
|
||||
import { fileURLToPath } from "url";
|
||||
import { writeFileSync } from "fs";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import sharp from "sharp"
|
||||
import { BildSchema } from "src/generated/zod/bild.js";
|
||||
import { PERSISTENT_DIR } from "#lib/server/constants.js";
|
||||
@@ -19,7 +19,7 @@ export const PATCH = defineApiRoute({
|
||||
output: z.void(),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
if (!UUidWithPrefix.safeParse(ctx.params.uid).success) {
|
||||
if (!IDWithPrefix.safeParse(ctx.params.uid).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -63,7 +63,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -122,7 +122,7 @@ export const DELETE = defineApiRoute({
|
||||
})
|
||||
|
||||
|
||||
const event_id = generatePrefixedId(9, VALID_UUID_PREFIXES.Ticket)
|
||||
const event_id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Ticket)
|
||||
// Wir erstellen ein Event, dass der Nachweis storniert wurde
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
@@ -163,9 +163,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: GEGNachweisGewerbeSchema.merge(z.object({
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
aufnahme_id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
benutzer_id: IDWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
@@ -29,12 +29,12 @@ export const PUT = defineApiRoute({
|
||||
zurueckgestellt: true,
|
||||
ausweisart: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
aufnahme_id: IDWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -52,7 +52,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.GEGNachweisGewerbe)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.GEGNachweisGewerbe)
|
||||
|
||||
const nachweis = await prisma.gEGNachweisGewerbe.create({
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -63,7 +63,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -127,7 +127,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
data: {
|
||||
id: generatePrefixedId(9, VALID_UUID_PREFIXES.Event),
|
||||
id: generateIDWithPrefix(9, VALID_UUID_PREFIXES.Event),
|
||||
title: "Nachweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (nachweis.benutzer_id !== user.id)) ? "Nachweis wurde von einem Administrator storniert." : "Nachweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -163,9 +163,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: GEGNachweisWohnenSchema.merge(z.object({
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
aufnahme_id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
benutzer_id: IDWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
@@ -29,12 +29,12 @@ export const PUT = defineApiRoute({
|
||||
zurueckgestellt: true,
|
||||
ausweisart: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
aufnahme_id: IDWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -52,7 +52,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.GEGNachweisWohnen)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.GEGNachweisWohnen)
|
||||
|
||||
const nachweis = await prisma.gEGNachweisWohnen.create({
|
||||
data: {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -13,11 +13,11 @@ export const PUT = defineApiRoute({
|
||||
erstellungsdatum: true
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const id = generatePrefixedId(9, "OB")
|
||||
const id = generateIDWithPrefix(9, "OB")
|
||||
|
||||
console.log(id);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UUidWithPrefix, getAusweisartFromId } from "#components/Ausweis/types.js"
|
||||
import { IDWithPrefix, getAusweisartFromId } from "#components/Ausweis/types.js"
|
||||
import { Enums } from "#lib/client/prisma.js"
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js"
|
||||
import { mollieClient } from "#lib/mollie.js"
|
||||
@@ -25,7 +25,7 @@ export const PATCH = defineApiRoute({
|
||||
}),
|
||||
output: z.object({
|
||||
checkout_url: z.string().optional(),
|
||||
id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
}),
|
||||
middleware: authorizationMiddleware,
|
||||
headers: authorizationHeaders,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { getAusweisartFromId, UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { getAusweisartFromId, IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { omit } from "#lib/helpers.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendGEGAnforderungsMail } from "#lib/server/mail/geg-anfordern.js";
|
||||
@@ -15,10 +15,10 @@ export const PUT = defineApiRoute({
|
||||
id: true,
|
||||
status: true,
|
||||
}).merge(z.object({
|
||||
nachweis_id: UUidWithPrefix
|
||||
nachweis_id: IDWithPrefix
|
||||
})),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -59,7 +59,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.GEGEinpreisung)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.GEGEinpreisung)
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) {
|
||||
einpreisung = await prisma.gEGEinpreisung.create({
|
||||
|
||||
@@ -7,12 +7,12 @@ import {
|
||||
authorizationHeaders,
|
||||
authorizationMiddleware,
|
||||
} from "#lib/middleware/authorization.js";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { getPrismaAusweisAdapter } from "#lib/server/ausweis.js";
|
||||
import { PRICES, SERVICES, VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { Rechnung } from "#lib/client/prisma.js";
|
||||
import { RechnungSchema } from "src/generated/zod/rechnung.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
meta: {
|
||||
@@ -25,7 +25,7 @@ export const PUT = defineApiRoute({
|
||||
input: z
|
||||
.object({
|
||||
ausweisart: z.nativeEnum(Enums.Ausweisart),
|
||||
ausweis_id: UUidWithPrefix,
|
||||
ausweis_id: IDWithPrefix,
|
||||
})
|
||||
.merge(
|
||||
RechnungSchema.omit({
|
||||
@@ -43,7 +43,7 @@ export const PUT = defineApiRoute({
|
||||
),
|
||||
output: z.object({
|
||||
checkout_url: z.string().optional(),
|
||||
id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -99,7 +99,7 @@ export const PUT = defineApiRoute({
|
||||
betrag += servicePriceList[service]
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Rechnung);
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Rechnung);
|
||||
|
||||
// Wir erstellen eine neue Rechnung in unserer Datenbank.
|
||||
let rechnung: Rechnung | null = null;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { TicketsSchema } from "src/generated/zod/tickets.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
@@ -25,10 +25,10 @@ export const PUT = defineApiRoute({
|
||||
updated_at: true,
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
}),
|
||||
async fetch(input, ctx) {
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Ticket)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Ticket)
|
||||
|
||||
const ticket = await prisma.tickets.create({
|
||||
data: {
|
||||
|
||||
@@ -3,9 +3,9 @@ import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
import { UnterlageSchema } from "src/generated/zod/unterlage.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
||||
import { s3Client } from "#lib/s3.js";
|
||||
import mime from "mime"
|
||||
@@ -18,7 +18,7 @@ export const PUT = defineApiRoute({
|
||||
data: z.string(),
|
||||
})),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}),
|
||||
async fetch({ data, name, kategorie, mime: mimeType }, ctx, user) {
|
||||
const extension = mime.getExtension(mimeType);
|
||||
@@ -29,7 +29,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Unterlage)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Unterlage)
|
||||
|
||||
await prisma.unterlage.create({
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { adminMiddleware, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { hashPassword } from "#lib/password.js";
|
||||
import { createLexOfficeCustomer } from "#lib/server/lexoffice.js";
|
||||
@@ -47,7 +47,7 @@ export const POST = defineApiRoute({
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
input: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}).or(z.object({
|
||||
take: z.number(),
|
||||
email: z.string()
|
||||
@@ -90,7 +90,7 @@ export const PUT = defineApiRoute({
|
||||
name: z.string()
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix
|
||||
id: IDWithPrefix
|
||||
}),
|
||||
async fetch(input) {
|
||||
const existingUser = await prisma.benutzer.findUnique({
|
||||
@@ -106,7 +106,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.User);
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.User);
|
||||
|
||||
const user = await prisma.benutzer.create({
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { OptionalNullable, UUidWithPrefix, VerbrauchsausweisGewerbeClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { OptionalNullable, IDWithPrefix, VerbrauchsausweisGewerbeClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -61,7 +61,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "id konnte nicht verifiziert werden."
|
||||
@@ -123,7 +123,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
data: {
|
||||
id: generatePrefixedId(9, VALID_UUID_PREFIXES.Event),
|
||||
id: generateIDWithPrefix(9, VALID_UUID_PREFIXES.Event),
|
||||
title: "Ausweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (ausweis.benutzer_id !== user.id)) ? "Ausweis wurde von einem Administrator storniert." : "Ausweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -159,7 +159,7 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<OptionalNullable<VerbrauchsausweisGewerbeClient>>(VerbrauchsausweisGewerbeSchema.merge(z.object({
|
||||
objekt_id: UUidWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
}))),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
@@ -27,12 +27,12 @@ export const PUT = defineApiRoute({
|
||||
}).merge(z.object({
|
||||
startdatum: z.coerce.date().nullable()
|
||||
})),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
aufnahme_id: IDWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
@@ -50,7 +50,7 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.VerbrauchsausweisGewerbe)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.VerbrauchsausweisGewerbe)
|
||||
|
||||
const createdAusweis = await prisma.verbrauchsausweisGewerbe.create({
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { OptionalNullable, UUidWithPrefix, VerbrauchsausweisWohnenClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { OptionalNullable, IDWithPrefix, VerbrauchsausweisWohnenClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
@@ -62,7 +62,7 @@ export const DELETE = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
if (!IDWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -124,7 +124,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
data: {
|
||||
id: generatePrefixedId(9, VALID_UUID_PREFIXES.Event),
|
||||
id: generateIDWithPrefix(9, VALID_UUID_PREFIXES.Event),
|
||||
title: "Ausweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (ausweis.benutzer_id !== user.id)) ? "Ausweis wurde von einem Administrator storniert." : "Ausweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -160,7 +160,7 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<OptionalNullable<VerbrauchsausweisWohnenClient>>(VerbrauchsausweisWohnenSchema.merge(z.object({
|
||||
objekt_id: UUidWithPrefix
|
||||
objekt_id: IDWithPrefix
|
||||
}))),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { IDWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import {
|
||||
authorizationHeaders,
|
||||
authorizationMiddleware,
|
||||
} from "#lib/middleware/authorization.js";
|
||||
import { sendAusweisGespeichertMail } from "#lib/server/mail/speichern-erfolgreich.js";
|
||||
import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -20,87 +23,102 @@ export const PUT = defineApiRoute({
|
||||
tags: ["Verbrauchsausweis Wohnen"],
|
||||
},
|
||||
input: z.object({
|
||||
ausweis: VerbrauchsausweisWohnenSchema.merge(z.object({
|
||||
startdatum: z.coerce.date().nullable()
|
||||
})).omit({
|
||||
ausweis: VerbrauchsausweisWohnenSchema.merge(
|
||||
z.object({
|
||||
startdatum: z.coerce.date().nullable(),
|
||||
})
|
||||
).omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
aufnahme_id: true,
|
||||
rechnung_id: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
ausweisart: true
|
||||
ausweisart: true,
|
||||
alte_ausweis_id: true,
|
||||
ausgestellt: true,
|
||||
bestellt: true,
|
||||
ausstellungsdatum: true,
|
||||
kontrolldatei_angefragt: true,
|
||||
registriernummer: true,
|
||||
storniert: true,
|
||||
zurueckgestellt: true,
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
output: z.object({
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
id: IDWithPrefix,
|
||||
objekt_id: IDWithPrefix,
|
||||
aufnahme_id: IDWithPrefix,
|
||||
}),
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const aufnahme = await prisma.aufnahme.findUnique({
|
||||
where: {
|
||||
id: input.aufnahme_id
|
||||
}
|
||||
})
|
||||
id: input.aufnahme_id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!aufnahme || aufnahme.benutzer_id !== user.id) {
|
||||
throw new APIError({
|
||||
code: "FORBIDDEN",
|
||||
message: "Aufnahme konnte nicht gefunden werden oder gehört nicht zu diesem Benutzer."
|
||||
})
|
||||
message:
|
||||
"Aufnahme konnte nicht gefunden werden oder gehört nicht zu diesem Benutzer.",
|
||||
});
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.VerbrauchsausweisWohnen);
|
||||
const id = generateIDWithPrefix(
|
||||
9,
|
||||
VALID_UUID_PREFIXES.VerbrauchsausweisWohnen
|
||||
);
|
||||
|
||||
const createdAusweis = await prisma.verbrauchsausweisWohnen.create({
|
||||
data: {
|
||||
id,
|
||||
...input.ausweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
aufnahme: {
|
||||
connect: {
|
||||
id: aufnahme.id,
|
||||
},
|
||||
const ausweis = await prisma.verbrauchsausweisWohnen.create({
|
||||
data: {
|
||||
id,
|
||||
...input.ausweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
aufnahme: {
|
||||
connect: {
|
||||
id: aufnahme.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (user.rolle === Enums.BenutzerRolle.USER) {
|
||||
await sendAusweisGespeichertMail(user, id)
|
||||
}
|
||||
return {
|
||||
id: createdAusweis.id,
|
||||
objekt_id: createdAusweis.aufnahme.objekt.id,
|
||||
aufnahme_id: createdAusweis.aufnahme.id,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
if (user.rolle === Enums.BenutzerRolle.USER) {
|
||||
await sendAusweisGespeichertMail(user, id);
|
||||
}
|
||||
return {
|
||||
id: ausweis.id,
|
||||
objekt_id: ausweis.aufnahme.objekt.id,
|
||||
aufnahme_id: ausweis.aufnahme.id,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
meta: {
|
||||
description: "Gibt ein spezifisches Gebäude des Benutzers zurück.",
|
||||
tags: ["Gebäude"],
|
||||
description:
|
||||
"Gibt einen spezifischen Verbrauchsausweis Wohngebäude des Benutzers zurück.",
|
||||
tags: ["Verbrauchsausweis Wohnen"],
|
||||
headers: {
|
||||
Authorization: {
|
||||
description: "Ein gültiger Authentifizierungstoken",
|
||||
|
||||
@@ -96,7 +96,7 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
|
||||
ausweis.id = null;
|
||||
aufnahme.id = null;
|
||||
aufnahme.erstellungsdatum = null
|
||||
delete aufnahme.erstellungsdatum;
|
||||
ausweis.created_at = new Date()
|
||||
ausweis.updated_at = new Date();
|
||||
ausweis.alte_ausweis_id = null;
|
||||
@@ -108,6 +108,8 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
ausweis.ausweistyp = Enums.AusweisTyp.Standard;
|
||||
ausweis.zurueckgestellt = false;
|
||||
ausweis.storniert = false;
|
||||
ausweis.rechnung_id = null;
|
||||
ausweis.registriernummer = null;
|
||||
// Die Daten sollen nicht aus dem localStorage genommen werden sonst kann es vorkommen, dass die ID noch besteht und der Vorgang nicht neu angelegt wird.
|
||||
loadFromDatabase = true;
|
||||
} else if (typ === AusstellungsTyp.Speichern) {
|
||||
@@ -187,7 +189,7 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
}
|
||||
|
||||
ausweis.id = null;
|
||||
aufnahme.erstellungsdatum = null
|
||||
delete aufnahme.erstellungsdatum;
|
||||
ausweis.created_at = new Date()
|
||||
ausweis.updated_at = new Date();
|
||||
ausweis.alte_ausweis_id = null;
|
||||
@@ -199,6 +201,8 @@ if (typ === AusstellungsTyp.Neuausstellung) {
|
||||
ausweis.ausweistyp = Enums.AusweisTyp.Standard;
|
||||
ausweis.zurueckgestellt = false;
|
||||
ausweis.storniert = false;
|
||||
ausweis.rechnung_id = null;
|
||||
ausweis.registriernummer = null;
|
||||
// Die Daten sollen nicht aus dem localStorage genommen werden sonst kann es vorkommen, dass die ID noch besteht und der Vorgang nicht neu angelegt wird.
|
||||
loadFromDatabase = true;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
import Papa from "papaparse"
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
const path = fileURLToPath(new URL("./rechnungen.csv", import.meta.url));
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { hashPassword } from "#lib/password.js";
|
||||
import Papa from "papaparse";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { tryCatch } from "#lib/tryCatch.js";
|
||||
|
||||
@@ -78,7 +78,7 @@ Papa.parse(file, {
|
||||
console.log(`Missing user ${user_id}`);
|
||||
|
||||
if (email) {
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.User);
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.User);
|
||||
|
||||
user = await prisma.benutzer.create({
|
||||
data: {
|
||||
@@ -104,7 +104,7 @@ Papa.parse(file, {
|
||||
}
|
||||
}
|
||||
|
||||
const objekt_id = generatePrefixedId(9, VALID_UUID_PREFIXES.Objekt);
|
||||
const objekt_id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Objekt);
|
||||
const [objekt, objekt_error] = await tryCatch(prisma.objekt.create({
|
||||
data: {
|
||||
id: objekt_id,
|
||||
@@ -137,7 +137,7 @@ Papa.parse(file, {
|
||||
continue;
|
||||
}
|
||||
|
||||
const aufnahme_id = generatePrefixedId(
|
||||
const aufnahme_id = generateIDWithPrefix(
|
||||
9,
|
||||
VALID_UUID_PREFIXES.Aufnahme
|
||||
);
|
||||
@@ -263,7 +263,7 @@ Papa.parse(file, {
|
||||
heizung: Enums.BilderKategorie.Heizung,
|
||||
};
|
||||
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Bild);
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Bild);
|
||||
const img = await prisma.bild.create({
|
||||
data: {
|
||||
id,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
import Papa from "papaparse"
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
const path = fileURLToPath(new URL("./users.csv", import.meta.url));
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Enums, prisma } from "#lib/server/prisma.js";
|
||||
import Papa from "papaparse"
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
const path = fileURLToPath(new URL("./users.csv", import.meta.url));
|
||||
@@ -36,7 +36,7 @@ Papa.parse(file, {
|
||||
}
|
||||
|
||||
try {
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.User)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.User)
|
||||
|
||||
await prisma.benutzer.create({
|
||||
data: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Enums, Prisma, prisma } from "#lib/server/prisma.js";
|
||||
import Papa from "papaparse"
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { generateIDWithPrefix } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import moment from "moment";
|
||||
|
||||
@@ -45,7 +45,7 @@ Papa.parse(file, {
|
||||
}
|
||||
|
||||
try {
|
||||
const id = generatePrefixedId(9, VALID_UUID_PREFIXES.Rechnung)
|
||||
const id = generateIDWithPrefix(9, VALID_UUID_PREFIXES.Rechnung)
|
||||
|
||||
const services: Enums.Service[] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user