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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user