feat(platform): harden access scoping and delivery baseline
This commit is contained in:
@@ -6,6 +6,18 @@ import { adminProcedure, createTRPCRouter, protectedProcedure } from "../trpc.js
|
||||
import { createAuditEntry } from "../lib/audit.js";
|
||||
|
||||
export const blueprintRouter = createTRPCRouter({
|
||||
listSummaries: protectedProcedure
|
||||
.query(async ({ ctx }) => {
|
||||
return ctx.db.blueprint.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
_count: { select: { projects: true } },
|
||||
},
|
||||
orderBy: { name: "asc" },
|
||||
});
|
||||
}),
|
||||
|
||||
list: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
@@ -33,6 +45,70 @@ export const blueprintRouter = createTRPCRouter({
|
||||
return blueprint;
|
||||
}),
|
||||
|
||||
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,
|
||||
target: true,
|
||||
isActive: true,
|
||||
} as const;
|
||||
|
||||
let blueprint = await ctx.db.blueprint.findUnique({
|
||||
where: { id: identifier },
|
||||
select,
|
||||
});
|
||||
|
||||
if (!blueprint) {
|
||||
blueprint = await ctx.db.blueprint.findFirst({
|
||||
where: { name: { equals: identifier, mode: "insensitive" } },
|
||||
select,
|
||||
});
|
||||
}
|
||||
|
||||
if (!blueprint) {
|
||||
blueprint = await ctx.db.blueprint.findFirst({
|
||||
where: { name: { contains: identifier, mode: "insensitive" } },
|
||||
select,
|
||||
});
|
||||
}
|
||||
|
||||
if (!blueprint) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: `Blueprint not found: ${identifier}` });
|
||||
}
|
||||
|
||||
return blueprint;
|
||||
}),
|
||||
|
||||
getByIdentifier: protectedProcedure
|
||||
.input(z.object({ identifier: z.string().trim().min(1) }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const identifier = input.identifier.trim();
|
||||
let blueprint = await ctx.db.blueprint.findUnique({
|
||||
where: { id: identifier },
|
||||
});
|
||||
|
||||
if (!blueprint) {
|
||||
blueprint = await ctx.db.blueprint.findFirst({
|
||||
where: { name: { equals: identifier, mode: "insensitive" } },
|
||||
});
|
||||
}
|
||||
|
||||
if (!blueprint) {
|
||||
blueprint = await ctx.db.blueprint.findFirst({
|
||||
where: { name: { contains: identifier, mode: "insensitive" } },
|
||||
});
|
||||
}
|
||||
|
||||
if (!blueprint) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: `Blueprint not found: ${identifier}` });
|
||||
}
|
||||
|
||||
return blueprint;
|
||||
}),
|
||||
|
||||
create: adminProcedure
|
||||
.input(CreateBlueprintSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
|
||||
Reference in New Issue
Block a user