Cypress und API
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { AufnahmeClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { AufnahmeSchema, prisma } from "@ibcornelsen/database/server";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -55,6 +57,13 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<AufnahmeClient>(AufnahmeSchema.omit({
|
||||
id: true,
|
||||
objekt_id: true,
|
||||
benutzer_id: true
|
||||
}).merge(z.object({
|
||||
uid_objekt: z.string().uuid()
|
||||
}))),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
@@ -64,6 +73,13 @@ export const GET = defineApiRoute({
|
||||
uid,
|
||||
benutzer_id: user.id
|
||||
},
|
||||
include: {
|
||||
objekt: {
|
||||
select: {
|
||||
uid: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!aufnahme) {
|
||||
@@ -73,6 +89,9 @@ export const GET = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
return aufnahme
|
||||
return exclude({
|
||||
uid_objekt: aufnahme.objekt.uid,
|
||||
...aufnahme
|
||||
}, ["id", "objekt_id", "benutzer_id", "objekt"])
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { ObjektClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { ObjektSchema, prisma } from "@ibcornelsen/database/server";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
@@ -57,6 +59,10 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
}
|
||||
},
|
||||
output: ZodOverlap<ObjektClient>(ObjektSchema.omit({
|
||||
benutzer_id: true,
|
||||
id: true
|
||||
})),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, ctx, user) {
|
||||
const { uid } = ctx.params;
|
||||
@@ -75,6 +81,6 @@ export const GET = defineApiRoute({
|
||||
})
|
||||
}
|
||||
|
||||
return objekt
|
||||
return exclude(objekt, ["benutzer_id", "id"])
|
||||
},
|
||||
});
|
||||
|
||||
41
src/pages/api/user/index.ts
Normal file
41
src/pages/api/user/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { hashPassword } from "#lib/password.js";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import { z } from "zod";
|
||||
|
||||
export const PUT = defineApiRoute({
|
||||
input: z.object({
|
||||
email: z.string().email(),
|
||||
passwort: z.string().min(6),
|
||||
vorname: z.string(),
|
||||
name: z.string()
|
||||
}),
|
||||
output: z.object({
|
||||
uid: z.string().uuid()
|
||||
}),
|
||||
async fetch(input) {
|
||||
const user = await prisma.benutzer.findUnique({
|
||||
where: {
|
||||
email: input.email
|
||||
}
|
||||
})
|
||||
|
||||
if (user) {
|
||||
throw new APIError({
|
||||
code: "CONFLICT",
|
||||
message: "Email Adresse ist bereits vergeben."
|
||||
})
|
||||
}
|
||||
|
||||
const { uid } = await prisma.benutzer.create({
|
||||
data: {
|
||||
email: input.email,
|
||||
passwort: hashPassword(input.passwort),
|
||||
vorname: input.vorname,
|
||||
name: input.name
|
||||
}
|
||||
})
|
||||
|
||||
return { uid }
|
||||
},
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { VerbrauchsausweisWohnenClient, ZodOverlap } from "#components/Ausweis/types.js";
|
||||
import { exclude } from "#lib/exclude.js";
|
||||
import { authorizationMiddleware } from "#lib/middleware/authorization.js";
|
||||
import { prisma, VerbrauchsausweisWohnenSchema } from "@ibcornelsen/database/server";
|
||||
@@ -59,15 +60,15 @@ export const GET = defineApiRoute({
|
||||
}
|
||||
}
|
||||
},
|
||||
output: VerbrauchsausweisWohnenSchema.merge(z.object({
|
||||
output: ZodOverlap<VerbrauchsausweisWohnenClient>(VerbrauchsausweisWohnenSchema.merge(z.object({
|
||||
uid_aufnahme: z.string().uuid(),
|
||||
uid_objekt: z.string().uuid(),
|
||||
uid_benutzer: z.string().uuid().optional()
|
||||
})).omit({
|
||||
id: true,
|
||||
aufnahme_id: true,
|
||||
benutzer_id: true,
|
||||
}),
|
||||
benutzer_id: true
|
||||
})),
|
||||
middleware: authorizationMiddleware,
|
||||
async fetch(input, context, user) {
|
||||
const { uid } = context.params;
|
||||
|
||||
Reference in New Issue
Block a user