feat(platform): harden access scoping and delivery baseline

This commit is contained in:
2026-03-30 00:27:31 +02:00
parent 00b936fa1f
commit 819345acfa
109 changed files with 26142 additions and 8081 deletions
+92
View File
@@ -78,6 +78,98 @@ export const orgUnitRouter = createTRPCRouter({
return unit;
}),
resolveByIdentifier: protectedProcedure
.input(z.object({ identifier: z.string().trim().min(1) }))
.query(async ({ ctx, input }) => {
const identifier = input.identifier.trim();
const select = {
id: true,
name: true,
shortName: true,
level: true,
isActive: true,
} as const;
let unit = await ctx.db.orgUnit.findUnique({
where: { id: identifier },
select,
});
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: { name: { equals: identifier, mode: "insensitive" } },
select,
});
}
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: { shortName: { equals: identifier, mode: "insensitive" } },
select,
});
}
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: {
OR: [
{ name: { contains: identifier, mode: "insensitive" } },
{ shortName: { contains: identifier, mode: "insensitive" } },
],
},
select,
});
}
if (!unit) {
throw new TRPCError({ code: "NOT_FOUND", message: `Org unit not found: ${identifier}` });
}
return unit;
}),
getByIdentifier: protectedProcedure
.input(z.object({ identifier: z.string().trim().min(1) }))
.query(async ({ ctx, input }) => {
const identifier = input.identifier.trim();
let unit = await ctx.db.orgUnit.findUnique({
where: { id: identifier },
include: { _count: { select: { resources: true } } },
});
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: { name: { equals: identifier, mode: "insensitive" } },
include: { _count: { select: { resources: true } } },
});
}
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: { shortName: { equals: identifier, mode: "insensitive" } },
include: { _count: { select: { resources: true } } },
});
}
if (!unit) {
unit = await ctx.db.orgUnit.findFirst({
where: {
OR: [
{ name: { contains: identifier, mode: "insensitive" } },
{ shortName: { contains: identifier, mode: "insensitive" } },
],
},
include: { _count: { select: { resources: true } } },
});
}
if (!unit) {
throw new TRPCError({ code: "NOT_FOUND", message: `Org unit not found: ${identifier}` });
}
return unit;
}),
create: adminProcedure
.input(CreateOrgUnitSchema)
.mutation(async ({ ctx, input }) => {