group validation
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
toNullIfDefaultMinDate,
|
||||
updateGroup,
|
||||
} from '@openpanel/db';
|
||||
import { zCreateGroup, zUpdateGroup } from '@openpanel/validation';
|
||||
import sqlstring from 'sqlstring';
|
||||
import { z } from 'zod';
|
||||
import { createTRPCRouter, protectedProcedure } from '../trpc';
|
||||
@@ -55,29 +56,13 @@ export const groupRouter = createTRPCRouter({
|
||||
}),
|
||||
|
||||
create: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
properties: z.record(z.string()).default({}),
|
||||
})
|
||||
)
|
||||
.input(zCreateGroup)
|
||||
.mutation(({ input }) => {
|
||||
return createGroup(input);
|
||||
}),
|
||||
|
||||
update: protectedProcedure
|
||||
.input(
|
||||
z.object({
|
||||
id: z.string().min(1),
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1).optional(),
|
||||
name: z.string().min(1).optional(),
|
||||
properties: z.record(z.string()).optional(),
|
||||
})
|
||||
)
|
||||
.input(zUpdateGroup)
|
||||
.mutation(({ input: { id, projectId, ...data } }) => {
|
||||
return updateGroup(id, projectId, data);
|
||||
}),
|
||||
|
||||
@@ -540,6 +540,32 @@ export const zCheckout = z.object({
|
||||
});
|
||||
export type ICheckout = z.infer<typeof zCheckout>;
|
||||
|
||||
export const zGroupId = z
|
||||
.string()
|
||||
.min(1)
|
||||
.regex(
|
||||
/^[a-z0-9_-]+$/,
|
||||
'ID must only contain lowercase letters, digits, hyphens, or underscores',
|
||||
);
|
||||
|
||||
export const zCreateGroup = z.object({
|
||||
id: zGroupId,
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
properties: z.record(z.string()).default({}),
|
||||
});
|
||||
export type ICreateGroup = z.infer<typeof zCreateGroup>;
|
||||
|
||||
export const zUpdateGroup = z.object({
|
||||
id: z.string().min(1),
|
||||
projectId: z.string(),
|
||||
type: z.string().min(1).optional(),
|
||||
name: z.string().min(1).optional(),
|
||||
properties: z.record(z.string()).optional(),
|
||||
});
|
||||
export type IUpdateGroup = z.infer<typeof zUpdateGroup>;
|
||||
|
||||
export const zEditOrganization = z.object({
|
||||
id: z.string().min(2),
|
||||
name: z.string().min(2),
|
||||
|
||||
Reference in New Issue
Block a user