Speichern verbessert
This commit is contained in:
@@ -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
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user