mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-30 11:19:12 +01:00
* 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
38 lines
892 B
TypeScript
38 lines
892 B
TypeScript
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,
|
|
};
|