feat: add user groups (#376)
* feat: add user groups * wip: add unit tests * wip: add more tests and normalized name for creation and update * test: add unit tests for group router * fix: type issues, missing mysql schema, rename column creator_id to owner_id * fix: lint and format issues * fix: deepsource issues * fix: forgot to add log message * fix: build not working * chore: address pull request feedback * feat: add mysql migration and fix merge conflicts * fix: format issue and test issue
This commit is contained in:
37
packages/validation/src/group.ts
Normal file
37
packages/validation/src/group.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { groupPermissionKeys } from "@homarr/definitions";
|
||||
|
||||
import { zodEnumFromArray } from "./enums";
|
||||
|
||||
const paginatedSchema = z.object({
|
||||
search: z.string().optional(),
|
||||
pageSize: z.number().int().positive().default(10),
|
||||
page: z.number().int().positive().default(1),
|
||||
});
|
||||
|
||||
const byIdSchema = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
const createSchema = z.object({
|
||||
name: z.string().max(64),
|
||||
});
|
||||
|
||||
const updateSchema = createSchema.merge(byIdSchema);
|
||||
|
||||
const savePermissionsSchema = z.object({
|
||||
groupId: z.string(),
|
||||
permissions: z.array(zodEnumFromArray(groupPermissionKeys)),
|
||||
});
|
||||
|
||||
const groupUserSchema = z.object({ groupId: z.string(), userId: z.string() });
|
||||
|
||||
export const groupSchemas = {
|
||||
paginated: paginatedSchema,
|
||||
byId: byIdSchema,
|
||||
create: createSchema,
|
||||
update: updateSchema,
|
||||
savePermissions: savePermissionsSchema,
|
||||
groupUser: groupUserSchema,
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { appSchemas } from "./app";
|
||||
import { boardSchemas } from "./board";
|
||||
import { groupSchemas } from "./group";
|
||||
import { integrationSchemas } from "./integration";
|
||||
import { locationSchemas } from "./location";
|
||||
import { userSchemas } from "./user";
|
||||
@@ -7,6 +8,7 @@ import { widgetSchemas } from "./widgets";
|
||||
|
||||
export const validation = {
|
||||
user: userSchemas,
|
||||
group: groupSchemas,
|
||||
integration: integrationSchemas,
|
||||
board: boardSchemas,
|
||||
app: appSchemas,
|
||||
|
||||
Reference in New Issue
Block a user