Tests
This commit is contained in:
@@ -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,25 @@ export const PUT = defineApiRoute({
|
||||
nachweis: GEGNachweisGewerbeSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
uid: true,
|
||||
aufnahme_id: true,
|
||||
created_at: true,
|
||||
updated_at: true,
|
||||
geg_einpreisung_id: true,
|
||||
rechnung_id: true
|
||||
}),
|
||||
uid_aufnahme: UUidWithPrefix
|
||||
aufnahme_id: UUidWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
uid: UUidWithPrefix,
|
||||
objekt_uid: UUidWithPrefix,
|
||||
aufnahme_uid: UUidWithPrefix,
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: 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 +47,11 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGNachweisGewerbe)
|
||||
|
||||
const nachweis = await prisma.gEGNachweisGewerbe.create({
|
||||
data: {
|
||||
id,
|
||||
...input.nachweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
@@ -59,13 +65,13 @@ export const PUT = defineApiRoute({
|
||||
}
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -74,9 +80,9 @@ export const PUT = defineApiRoute({
|
||||
});
|
||||
|
||||
return {
|
||||
uid: nachweis.uid,
|
||||
objekt_uid: nachweis.aufnahme.objekt.uid,
|
||||
aufnahme_uid: nachweis.aufnahme.uid,
|
||||
id: nachweis.id,
|
||||
objekt_id: nachweis.aufnahme.objekt.id,
|
||||
aufnahme_id: nachweis.aufnahme.id,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -101,11 +107,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.gEGNachweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
benutzer: true,
|
||||
@@ -115,7 +121,7 @@ export const GET = defineApiRoute({
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { GEGNachweisWohnenClient, OptionalNullable, UUidWithPrefix, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } from "#lib/db.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationHeaders, authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { GEGNachweisWohnenSchema, prisma } from "#lib/server/prisma";
|
||||
import { prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { GEGNachweisWohnenSchema } from "src/generated/zod/gegnachweiswohnen.js";
|
||||
import { z } from "zod";
|
||||
|
||||
export const PATCH = defineApiRoute({
|
||||
input: GEGNachweisWohnenSchema.omit({
|
||||
uid: true,
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
geg_einpreisung_id: true,
|
||||
@@ -21,7 +23,7 @@ export const PATCH = defineApiRoute({
|
||||
async fetch(input, ctx, user) {
|
||||
const objekt = await prisma.gEGNachweisWohnen.findUnique({
|
||||
where: {
|
||||
uid: ctx.params.uid,
|
||||
id: ctx.params.id,
|
||||
benutzer: {
|
||||
id: user.id
|
||||
}
|
||||
@@ -37,7 +39,7 @@ export const PATCH = defineApiRoute({
|
||||
|
||||
await prisma.gEGNachweisWohnen.update({
|
||||
where: {
|
||||
uid: ctx.params.uid
|
||||
id: ctx.params.id
|
||||
},
|
||||
data: input
|
||||
})
|
||||
@@ -51,9 +53,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 +66,7 @@ export const DELETE = defineApiRoute({
|
||||
// Dieser MUSS mit dem Nutzer verknüpft sein.
|
||||
const nachweis = await prisma.gEGNachweisWohnen.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
}
|
||||
});
|
||||
|
||||
@@ -111,10 +113,13 @@ export const DELETE = defineApiRoute({
|
||||
}
|
||||
})
|
||||
|
||||
const event_id =
|
||||
|
||||
// Wir erstellen ein Event, dass der Nachweis storniert wurde
|
||||
// Dann können wir das in der Historie anzeigen
|
||||
await prisma.event.create({
|
||||
data: {
|
||||
id: generatePrefixedId(6, 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: {
|
||||
@@ -150,9 +155,9 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
},
|
||||
output: GEGNachweisWohnenSchema.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,32 +165,32 @@ 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"
|
||||
})
|
||||
}
|
||||
|
||||
const Nachweis = await prisma.gEGNachweisWohnen.findUnique({
|
||||
const nachweis = await prisma.gEGNachweisWohnen.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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,7 +198,7 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
});
|
||||
|
||||
if (!Nachweis) {
|
||||
if (!nachweis) {
|
||||
// Falls wir den Nachweis nicht finden können, werfen wir einen Fehler
|
||||
throw new APIError({
|
||||
code: "NOT_FOUND",
|
||||
@@ -202,10 +207,10 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
|
||||
return {
|
||||
uid_aufnahme: Nachweis.aufnahme.uid,
|
||||
uid_objekt: Nachweis.aufnahme.objekt.uid,
|
||||
uid_benutzer: Nachweis.benutzer?.uid,
|
||||
...exclude(Nachweis, ["id", "aufnahme_id", "benutzer_id", "aufnahme"])
|
||||
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,25 @@ export const PUT = defineApiRoute({
|
||||
nachweis: GEGNachweisWohnenSchema.omit({
|
||||
id: true,
|
||||
benutzer_id: true,
|
||||
uid: true,
|
||||
aufnahme_id: true,
|
||||
updated_at: true,
|
||||
created_at: true,
|
||||
geg_einpreisung_id: true,
|
||||
rechnung_id: true
|
||||
}),
|
||||
uid_aufnahme: UUidWithPrefix
|
||||
aufnahme_id: UUidWithPrefix
|
||||
}),
|
||||
output: z.object({
|
||||
uid: UUidWithPrefix,
|
||||
objekt_uid: UUidWithPrefix,
|
||||
aufnahme_uid: UUidWithPrefix,
|
||||
id: UUidWithPrefix,
|
||||
objekt_id: UUidWithPrefix,
|
||||
aufnahme_id: 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 +47,11 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGNachweisWohnen)
|
||||
|
||||
const nachweis = await prisma.gEGNachweisWohnen.create({
|
||||
data: {
|
||||
id,
|
||||
...input.nachweis,
|
||||
benutzer: {
|
||||
connect: {
|
||||
@@ -59,13 +65,13 @@ export const PUT = defineApiRoute({
|
||||
}
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
aufnahme: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -74,9 +80,9 @@ export const PUT = defineApiRoute({
|
||||
});
|
||||
|
||||
return {
|
||||
uid: nachweis.uid,
|
||||
objekt_uid: nachweis.aufnahme.objekt.uid,
|
||||
aufnahme_uid: nachweis.aufnahme.uid,
|
||||
id: nachweis.id,
|
||||
objekt_id: nachweis.aufnahme.objekt.id,
|
||||
aufnahme_id: nachweis.aufnahme.id,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -101,11 +107,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.gEGNachweisGewerbe.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
id,
|
||||
},
|
||||
include: {
|
||||
benutzer: true,
|
||||
@@ -115,7 +121,7 @@ export const GET = defineApiRoute({
|
||||
include: {
|
||||
benutzer: {
|
||||
select: {
|
||||
uid: true,
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import { getAusweisartFromId, UUidWithPrefix } from "#components/Ausweis/types.js";
|
||||
import { VALID_UUID_PREFIXES } from "#lib/constants.js";
|
||||
import { generatePrefixedId } 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";
|
||||
import { Enums, GEGNachweisGewerbe, GEGNachweisWohnen, prisma } from "#lib/server/prisma.js";
|
||||
import { BedarfsausweisGewerbe, Enums, GEGNachweisGewerbe, GEGNachweisWohnen, prisma } from "#lib/server/prisma.js";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { GEGEinpreisungSchema } from "src/generated/zod/gegeinpreisung.js";
|
||||
import { z } from "zod";
|
||||
@@ -21,7 +23,7 @@ export const PUT = defineApiRoute({
|
||||
const ausweisart = getAusweisartFromId(input.nachweis_id);
|
||||
|
||||
let einpreisung;
|
||||
let nachweis: GEGNachweisWohnen | GEGNachweisGewerbe;
|
||||
let nachweis: GEGNachweisWohnen | GEGNachweisGewerbe | BedarfsausweisGewerbe;
|
||||
if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) {
|
||||
nachweis = await prisma.gEGNachweisWohnen.findUnique({
|
||||
where: {
|
||||
@@ -55,9 +57,12 @@ export const PUT = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
const id = generatePrefixedId(6, VALID_UUID_PREFIXES.GEGEinpreisung)
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) {
|
||||
einpreisung = await prisma.gEGEinpreisung.create({
|
||||
data: {
|
||||
id,
|
||||
...omit(input, ["nachweis_id"]),
|
||||
status: Enums.Einpreisungsstatus.open,
|
||||
benutzer: {
|
||||
@@ -75,6 +80,7 @@ export const PUT = defineApiRoute({
|
||||
} else if (ausweisart === Enums.Ausweisart.GEGNachweisGewerbe) {
|
||||
einpreisung = await prisma.gEGEinpreisung.create({
|
||||
data: {
|
||||
id,
|
||||
...omit(input, ["nachweis_id"]),
|
||||
status: Enums.Einpreisungsstatus.open,
|
||||
benutzer: {
|
||||
@@ -92,6 +98,7 @@ export const PUT = defineApiRoute({
|
||||
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) {
|
||||
einpreisung = await prisma.gEGEinpreisung.create({
|
||||
data: {
|
||||
id,
|
||||
...omit(input, ["nachweis_id"]),
|
||||
status: Enums.Einpreisungsstatus.open,
|
||||
benutzer: {
|
||||
@@ -111,7 +118,7 @@ export const PUT = defineApiRoute({
|
||||
await sendGEGAnforderungsMail(nachweis, user)
|
||||
|
||||
return {
|
||||
id: einpreisung.id
|
||||
id
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user