@@ -1,4 +1,6 @@
|
||||
import { GEGNachweisWohnenClient, 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 { prisma } from "#lib/server/prisma.js";
|
||||
@@ -8,11 +10,16 @@ import { z } from "zod";
|
||||
|
||||
export const PATCH = defineApiRoute({
|
||||
input: BedarfsausweisGewerbeSchema.omit({
|
||||
uid: true,
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
geg_einpreisung_id: true,
|
||||
aufnahme_id: true,
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
output: z.void(),
|
||||
headers: {
|
||||
@@ -22,7 +29,7 @@ export const PATCH = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const objekt = await prisma.bedarfsausweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid: ctx.params.uid,
|
||||
id: ctx.params.id,
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
@@ -38,7 +45,7 @@ export const PATCH = defineApiRoute({
|
||||
|
||||
await prisma.bedarfsausweisGewerbe.update({
|
||||
where: {
|
||||
uid: ctx.params.uid
|
||||
id: ctx.params.id
|
||||
},
|
||||
data: input
|
||||
})
|
||||
@@ -52,9 +59,9 @@ export const DELETE = defineApiRoute({
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const { uid } = ctx.params;
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(uid).success) {
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -65,7 +72,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dieser MUSS mit dem Nutzer verknüpft sein.
|
||||
const nachweis = await prisma.bedarfsausweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -112,10 +119,13 @@ export const DELETE = defineApiRoute({
|
||||
}
|
||||
})
|
||||
|
||||
const event_id = generatePrefixedId(6, 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({
|
||||
data: {
|
||||
id: event_id,
|
||||
title: "Nachweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (nachweis.benutzer_id !== user.id)) ? "Nachweis wurde von einem Administrator storniert." : "Nachweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -151,9 +161,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: BedarfsausweisGewerbeSchema.merge(z.object({
|
||||
uid_aufnahme: UUidWithPrefix,
|
||||
uid_objekt: UUidWithPrefix,
|
||||
uid_benutzer: UUidWithPrefix.optional()
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
@@ -161,9 +171,9 @@ export const GET = defineApiRoute({
|
||||
}),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
const { id } = context.params;
|
||||
|
||||
if (!uid) {
|
||||
if (!id) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Missing uid in request params"
|
||||
@@ -172,21 +182,21 @@ export const GET = defineApiRoute({
|
||||
|
||||
const nachweis = await prisma.bedarfsausweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
benutzer_id: user.id
|
||||
},
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
},
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,9 +213,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
uid_aufnahme: nachweis.aufnahme.uid,
|
||||
uid_objekt: nachweis.aufnahme.objekt.uid,
|
||||
uid_benutzer: nachweis.benutzer?.uid,
|
||||
aufnahme_id: nachweis.aufnahme.id,
|
||||
objekt_id: nachweis.aufnahme.objekt.id,
|
||||
benutzer_id: nachweis.benutzer?.id,
|
||||
...exclude(nachweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"])
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { UUidWithPrefix } 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 { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -16,24 +18,24 @@ export const PUT = defineApiRoute({
|
||||
nachweis: BedarfsausweisGewerbeSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
uid: true,
|
||||
aufnahme_id: true,
|
||||
geg_einpreisung_id: true,
|
||||
rechnung_id: true
|
||||
aufnahme_id: true,
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
uid_aufnahme: UUidWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
uid: UUidWithPrefix,
|
||||
objekt_uid: UUidWithPrefix,
|
||||
aufnahme_uid: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix
|
||||
}),
|
||||
output: UUidWithPrefix,
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const aufnahme = await prisma.aufnahme.findUnique({
|
||||
where: {
|
||||
uid: input.uid_aufnahme
|
||||
id: input.aufnahme_id
|
||||
}
|
||||
})
|
||||
|
||||
@@ -44,8 +46,11 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGNachweisGewerbe)
|
||||
|
||||
const nachweis = await prisma.bedarfsausweisGewerbe.create({
|
||||
data: {
|
||||
id,
|
||||
...input.nachweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
@@ -57,27 +62,10 @@ export const PUT = defineApiRoute({
|
||||
id: aufnahme.id,
|
||||
},
|
||||
}
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
uid: nachweis.uid,
|
||||
objekt_uid: nachweis.aufnahme.objekt.uid,
|
||||
aufnahme_uid: nachweis.aufnahme.uid,
|
||||
};
|
||||
return nachweis.id
|
||||
},
|
||||
});
|
||||
|
||||
@@ -101,11 +89,11 @@ export const GET = defineApiRoute({
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
const { id } = context.params;
|
||||
|
||||
const nachweis = await prisma.bedarfsausweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
benutzer: true,
|
||||
@@ -115,7 +103,7 @@ export const GET = defineApiRoute({
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
import { BedarfsausweisWohnenClient, OptionalNullable, UUidWithPrefix, VerbrauchsausweisWohnenClient, 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 { BedarfsausweisWohnenSchema, prisma, VerbrauchsausweisWohnenSchema } from "#lib/server/prisma";
|
||||
import { BedarfsausweisWohnen, 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";
|
||||
|
||||
export const PATCH = defineApiRoute({
|
||||
input: VerbrauchsausweisWohnenSchema.omit({
|
||||
uid: true,
|
||||
input: BedarfsausweisWohnenSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
aufnahme_id: true,
|
||||
rechnung_id: true,
|
||||
ausgestellt: true,
|
||||
bestellt: true,
|
||||
zurueckgestellt: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
storniert: true
|
||||
}),
|
||||
output: z.void(),
|
||||
headers: {
|
||||
@@ -18,9 +27,9 @@ export const PATCH = defineApiRoute({
|
||||
},
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const objekt = await prisma.verbrauchsausweisWohnen.findUnique({
|
||||
const objekt = await prisma.bedarfsausweisWohnen.findUnique({
|
||||
where: {
|
||||
uid: ctx.params.uid,
|
||||
id: ctx.params.id,
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
@@ -34,9 +43,9 @@ export const PATCH = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
await prisma.verbrauchsausweisWohnen.update({
|
||||
await prisma.bedarfsausweisWohnen.update({
|
||||
where: {
|
||||
uid: ctx.params.uid
|
||||
id: ctx.params.id
|
||||
},
|
||||
data: input
|
||||
})
|
||||
@@ -50,9 +59,9 @@ export const DELETE = defineApiRoute({
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const { uid } = ctx.params;
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(uid).success) {
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -61,15 +70,11 @@ export const DELETE = defineApiRoute({
|
||||
|
||||
// Wir holen uns den Bedarfsausweis
|
||||
// Dieser MUSS mit dem Nutzer verknüpft sein.
|
||||
const ausweis = await prisma.verbrauchsausweisWohnen.findUnique({
|
||||
const ausweis = await prisma.bedarfsausweisWohnen.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
include: {
|
||||
aufnahme: {
|
||||
select: {
|
||||
storniert: true
|
||||
}
|
||||
id,
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -100,7 +105,7 @@ export const DELETE = defineApiRoute({
|
||||
// });
|
||||
// }
|
||||
|
||||
if (ausweis.aufnahme.storniert) {
|
||||
if (ausweis.storniert) {
|
||||
// Falls der Ausweis bereits storniert ist, werfen wir einen Fehler
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
@@ -108,19 +113,22 @@ export const DELETE = defineApiRoute({
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.aufnahme.update({
|
||||
await prisma.bedarfsausweisWohnen.update({
|
||||
where: {
|
||||
id: ausweis.aufnahme_id
|
||||
id
|
||||
},
|
||||
data: {
|
||||
storniert: true
|
||||
}
|
||||
})
|
||||
|
||||
const event_id = generatePrefixedId(6, VALID_UUID_PREFIXES.Ticket)
|
||||
|
||||
// Wir erstellen ein Event, dass der Ausweis storniert wurde
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
data: {
|
||||
id: event_id,
|
||||
title: "Ausweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (ausweis.benutzer_id !== user.id)) ? "Ausweis wurde von einem Administrator storniert." : "Ausweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -155,10 +163,10 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<OptionalNullable<VerbrauchsausweisWohnenClient>>(VerbrauchsausweisWohnenSchema.merge(z.object({
|
||||
uid_aufnahme: UUidWithPrefix,
|
||||
uid_objekt: UUidWithPrefix,
|
||||
uid_benutzer: UUidWithPrefix.optional()
|
||||
output: ZodOverlap<OptionalNullable<BedarfsausweisWohnenClient>>(BedarfsausweisWohnenSchema.merge(z.object({
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
@@ -166,9 +174,9 @@ export const GET = defineApiRoute({
|
||||
})),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
const { id } = context.params;
|
||||
|
||||
if (!uid) {
|
||||
if (!id) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Missing uid in request params"
|
||||
@@ -177,21 +185,21 @@ export const GET = defineApiRoute({
|
||||
|
||||
const ausweis = await prisma.verbrauchsausweisWohnen.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
benutzer_id: user.id
|
||||
},
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
},
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,9 +216,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
uid_aufnahme: ausweis.aufnahme.uid,
|
||||
uid_objekt: ausweis.aufnahme.objekt.uid,
|
||||
uid_benutzer: ausweis.benutzer?.uid,
|
||||
aufnahme_id: ausweis.aufnahme.id,
|
||||
objekt_id: ausweis.aufnahme.objekt.id,
|
||||
benutzer_id: ausweis.benutzer?.id,
|
||||
...exclude(ausweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"])
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import {
|
||||
authorizationHeaders,
|
||||
authorizationMiddleware,
|
||||
} from "#lib/middleware/authorization.js";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { BedarfsausweisWohnenSchema } from "src/generated/zod/bedarfsausweiswohnen.js";
|
||||
@@ -16,66 +21,58 @@ export const PUT = defineApiRoute({
|
||||
ausweis: BedarfsausweisWohnenSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
uid: true,
|
||||
aufnahme_id: true
|
||||
aufnahme_id: true,
|
||||
rechnung_id: true,
|
||||
ausgestellt: true,
|
||||
bestellt: true,
|
||||
zurueckgestellt: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
storniert: true,
|
||||
}),
|
||||
uid_aufnahme: UUidWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
uid: UUidWithPrefix,
|
||||
objekt_uid: UUidWithPrefix,
|
||||
aufnahme_uid: UUidWithPrefix,
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
}),
|
||||
output: UUidWithPrefix,
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const aufnahme = await prisma.aufnahme.findUnique({
|
||||
where: {
|
||||
uid: input.uid_aufnahme
|
||||
}
|
||||
})
|
||||
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 createdAusweis = await prisma.bedarfsausweisWohnen.create({
|
||||
data: {
|
||||
...input.ausweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
aufnahme: {
|
||||
connect: {
|
||||
uid: aufnahme.uid,
|
||||
},
|
||||
},
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const id = generatePrefixedId(
|
||||
6,
|
||||
VALID_UUID_PREFIXES.BedarfsausweisWohnen
|
||||
);
|
||||
|
||||
return {
|
||||
uid: createdAusweis.uid,
|
||||
objekt_uid: createdAusweis.aufnahme.objekt.uid,
|
||||
aufnahme_uid: createdAusweis.aufnahme.uid,
|
||||
};
|
||||
await prisma.bedarfsausweisWohnen.create({
|
||||
data: {
|
||||
id,
|
||||
...input.ausweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
aufnahme: {
|
||||
connect: {
|
||||
id: aufnahme.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return id;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -98,27 +95,22 @@ export const GET = defineApiRoute({
|
||||
},
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
const { id } = context.params;
|
||||
|
||||
const ausweis = await prisma.bedarfsausweisWohnen.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
benutzer: true,
|
||||
aufnahme: {
|
||||
include: {
|
||||
objekt: {
|
||||
include: {
|
||||
bilder: true,
|
||||
},
|
||||
},
|
||||
rechnungen: true,
|
||||
bilder: true,
|
||||
events: {
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
import { GEGNachweisWohnenClient, 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 { GEGNachweisGewerbeSchema, GEGNachweisWohnenSchema, prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { GEGNachweisGewerbeSchema } from "src/generated/zod/gegnachweisgewerbe.js";
|
||||
import { z } from "zod";
|
||||
|
||||
export const PATCH = defineApiRoute({
|
||||
input: GEGNachweisGewerbeSchema.omit({
|
||||
uid: true,
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
geg_einpreisung_id: true,
|
||||
aufnahme_id: true,
|
||||
geg_einpreisung_id: true
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
output: z.void(),
|
||||
headers: {
|
||||
@@ -21,7 +29,7 @@ export const PATCH = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const objekt = await prisma.gEGNachweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid: ctx.params.uid,
|
||||
id: ctx.params.id,
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
@@ -37,7 +45,7 @@ export const PATCH = defineApiRoute({
|
||||
|
||||
await prisma.gEGNachweisGewerbe.update({
|
||||
where: {
|
||||
uid: ctx.params.uid
|
||||
id: ctx.params.id
|
||||
},
|
||||
data: input
|
||||
})
|
||||
@@ -51,9 +59,9 @@ export const DELETE = defineApiRoute({
|
||||
headers: authorizationHeaders,
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const { uid } = ctx.params;
|
||||
const { id } = ctx.params;
|
||||
|
||||
if (!UUidWithPrefix.safeParse(uid).success) {
|
||||
if (!UUidWithPrefix.safeParse(id).success) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "UID konnte nicht verifiziert werden."
|
||||
@@ -64,7 +72,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dieser MUSS mit dem Nutzer verknüpft sein.
|
||||
const nachweis = await prisma.gEGNachweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -111,10 +119,13 @@ export const DELETE = defineApiRoute({
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
const event_id = generatePrefixedId(6, 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({
|
||||
data: {
|
||||
id: event_id,
|
||||
title: "Nachweis storniert",
|
||||
description: ((user.rolle === "ADMIN") && (nachweis.benutzer_id !== user.id)) ? "Nachweis wurde von einem Administrator storniert." : "Nachweis wurde vom Besitzer storniert.",
|
||||
benutzer: {
|
||||
@@ -150,9 +161,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: GEGNachweisGewerbeSchema.merge(z.object({
|
||||
uid_aufnahme: UUidWithPrefix,
|
||||
uid_objekt: UUidWithPrefix,
|
||||
uid_benutzer: UUidWithPrefix.optional()
|
||||
aufnahme_id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
benutzer_id: UUidWithPrefix.optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
@@ -160,9 +171,9 @@ export const GET = defineApiRoute({
|
||||
}),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
const { id } = context.params;
|
||||
|
||||
if (!uid) {
|
||||
if (!id) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Missing uid in request params"
|
||||
@@ -171,21 +182,21 @@ export const GET = defineApiRoute({
|
||||
|
||||
const nachweis = await prisma.gEGNachweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
benutzer_id: user.id
|
||||
},
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
},
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true
|
||||
id: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,9 +213,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
uid_aufnahme: nachweis.aufnahme.uid,
|
||||
uid_objekt: nachweis.aufnahme.objekt.uid,
|
||||
uid_benutzer: nachweis.benutzer?.uid,
|
||||
aufnahme_id: nachweis.aufnahme.id,
|
||||
objekt_id: nachweis.aufnahme.objekt.id,
|
||||
benutzer_id: nachweis.benutzer?.id,
|
||||
...exclude(nachweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"])
|
||||
}
|
||||
},
|
||||
|
||||
@@ -18,11 +18,14 @@ export const PUT = defineApiRoute({
|
||||
nachweis: GEGNachweisGewerbeSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
aufnahme_id: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
geg_einpreisung_id: true,
|
||||
rechnung_id: true
|
||||
aufnahme_id: true,
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
}),
|
||||
|
||||
@@ -14,6 +14,12 @@ export const PATCH = defineApiRoute({
|
||||
benutzer_id: true,
|
||||
geg_einpreisung_id: true,
|
||||
aufnahme_id: true,
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
output: z.void(),
|
||||
headers: {
|
||||
|
||||
@@ -18,11 +18,14 @@ export const PUT = defineApiRoute({
|
||||
nachweis: GEGNachweisWohnenSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
aufnahme_id: true,
|
||||
updated_at: true,
|
||||
created_at: true,
|
||||
geg_einpreisung_id: true,
|
||||
rechnung_id: true
|
||||
aufnahme_id: true,
|
||||
bestellt: true,
|
||||
created_at: true,
|
||||
rechnung_id: true,
|
||||
storniert: true,
|
||||
updated_at: true,
|
||||
zurueckgestellt: true
|
||||
}),
|
||||
aufnahme_id: UUidWithPrefix
|
||||
}),
|
||||
|
||||
@@ -3,6 +3,8 @@ import { prisma } from "#lib/server/prisma.js";
|
||||
import { defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { TicketsSchema } from "src/generated/zod/tickets.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
meta: {
|
||||
@@ -20,23 +22,22 @@ export const PUT = defineApiRoute({
|
||||
id: true,
|
||||
prioritaet: true,
|
||||
status: true,
|
||||
uid: true,
|
||||
updated_at: true,
|
||||
}),
|
||||
output: z.object({
|
||||
uid: UUidWithPrefix,
|
||||
id: UUidWithPrefix,
|
||||
}),
|
||||
async fetch(input, ctx) {
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.Ticket)
|
||||
|
||||
const ticket = await prisma.tickets.create({
|
||||
data: {
|
||||
id,
|
||||
beschreibung: input.beschreibung,
|
||||
email: input.email,
|
||||
titel: input.titel,
|
||||
metadata: input.metadata,
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
// Das sind die Label IDs von Trello
|
||||
@@ -71,7 +72,7 @@ export const PUT = defineApiRoute({
|
||||
|
||||
|
||||
return {
|
||||
uid: ticket.uid,
|
||||
id: ticket.id,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,112 +1,85 @@
|
||||
---
|
||||
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
|
||||
import { AufnahmeClient, ObjektClient, BildClient, VerbrauchsausweisGewerbeClient } from "#components/Ausweis/types";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
import VerbrauchsausweisGewerbeModule from "#modules/VerbrauchsausweisGewerbe/VerbrauchsausweisGewerbeModule.svelte";
|
||||
import { Enums } from "#lib/server/prisma";
|
||||
import { Aufnahme, Enums, Objekt, VerbrauchsausweisGewerbe } from "#lib/server/prisma";
|
||||
import { getAufnahme, getObjekt, getBilder, getVerbrauchsausweisGewerbe } from "#lib/server/db";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
|
||||
const id = Astro.url.searchParams.get("uid");
|
||||
const id = Astro.url.searchParams.get("id");
|
||||
const aufnahme_id = Astro.url.searchParams.get("aufnahme")
|
||||
const ausweistyp = Astro.url.searchParams.get("ausweistyp") || Enums.AusweisTyp.Standard;
|
||||
let ausweistyp = Astro.url.searchParams.get("ausweistyp") as Enums.AusweisTyp || Enums.AusweisTyp.Standard;
|
||||
|
||||
let ausweis: VerbrauchsausweisGewerbeClient = {} as VerbrauchsausweisGewerbeClient;
|
||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||
let objekt: ObjektClient = {} as ObjektClient;
|
||||
let bilder: BildClient[] = []
|
||||
|
||||
const valid = validateAccessTokenServer(Astro);
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
const user = await getCurrentUser(Astro)
|
||||
|
||||
if (id) {
|
||||
if (!valid) {
|
||||
if (!user) {
|
||||
return Astro.redirect(
|
||||
`/auth/login?redirect=${Astro.url.toString()}`
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let { aufnahme_id, objekt_id, benutzer_id, ...result } = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id
|
||||
}
|
||||
});
|
||||
ausweis = await getVerbrauchsausweisGewerbe(id) as VerbrauchsausweisGewerbe
|
||||
|
||||
ausweis = result
|
||||
|
||||
aufnahme = await caller.aufnahme._id.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id: aufnahme_id
|
||||
}
|
||||
})
|
||||
|
||||
objekt = await caller.objekt._id.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id: objekt_id
|
||||
}
|
||||
})
|
||||
|
||||
bilder = await caller.aufnahme._id.bilder.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id: aufnahme_id
|
||||
}
|
||||
})
|
||||
|
||||
if (!ausweis) {
|
||||
// Der Ausweis scheint nicht zu existieren.
|
||||
// Wir leiten auf die generische Ausweisseite ohne UID weiter.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-gewerbe"
|
||||
);
|
||||
}
|
||||
} catch(e) {
|
||||
if (!ausweis || ausweis.benutzer_id !== user.id) {
|
||||
// Der Ausweis scheint nicht zu existieren.
|
||||
// Wir leiten auf die generische Ausweisseite ohne ID weiter.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-gewerbe"
|
||||
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
||||
);
|
||||
}
|
||||
|
||||
aufnahme = await getAufnahme(ausweis.aufnahme_id) as Aufnahme
|
||||
|
||||
if (!aufnahme) {
|
||||
// Die Aufnahme existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
||||
);
|
||||
}
|
||||
|
||||
objekt = await getObjekt(aufnahme.objekt_id) as Objekt
|
||||
|
||||
if (!objekt) {
|
||||
// Das Objekt existiert nicht, das sollte eigentlich nicht passieren aber so können wir nicht fortfahren.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
||||
);
|
||||
}
|
||||
|
||||
bilder = await getBilder(aufnahme.id);
|
||||
} else if (aufnahme_id) {
|
||||
if (!valid) {
|
||||
if (!user) {
|
||||
return Astro.redirect(
|
||||
`/auth/login?redirect=${Astro.url.toString()}`
|
||||
);
|
||||
}
|
||||
|
||||
let { objekt_id, ...result} = await caller.aufnahme._id.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id: aufnahme_id
|
||||
}
|
||||
})
|
||||
aufnahme = await getAufnahme(ausweis.aufnahme_id) as Aufnahme
|
||||
|
||||
aufnahme = result;
|
||||
if (!aufnahme) {
|
||||
// Die Aufnahme existiert wohl nicht.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
||||
);
|
||||
}
|
||||
|
||||
objekt = await caller.objekt._id.GET.fetch(null, {
|
||||
headers: {
|
||||
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
id: objekt_id
|
||||
}
|
||||
})
|
||||
objekt = await getObjekt(aufnahme.objekt_id) as Objekt
|
||||
|
||||
if (!objekt) {
|
||||
// Das Objekt existiert nicht.
|
||||
return Astro.redirect(
|
||||
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
||||
);
|
||||
}
|
||||
}
|
||||
---
|
||||
|
||||
<AusweisLayout title="Verbrauchsausweis Gewerbe erstellen | IBCornelsen">
|
||||
<VerbrauchsausweisGewerbeModule client:only {ausweis} {objekt} {aufnahme} {bilder} {ausweistyp} />
|
||||
<VerbrauchsausweisGewerbeModule client:only {ausweis} {objekt} {aufnahme} {bilder} {ausweistyp} {user} {id} />
|
||||
</AusweisLayout>
|
||||
Reference in New Issue
Block a user