mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-12 22:42:13 +02:00
feat(workspace): refactor search space handling to workspace
This commit is contained in:
parent
e92b7a34ed
commit
c379ab1155
53 changed files with 268 additions and 169 deletions
|
|
@ -200,12 +200,18 @@ export const documentTitleRead = z.object({
|
|||
});
|
||||
|
||||
export const searchDocumentTitlesRequest = z.object({
|
||||
queryParams: z.object({
|
||||
search_space_id: z.number(),
|
||||
title: z.string().optional(),
|
||||
page: z.number().optional(),
|
||||
page_size: z.number().optional(),
|
||||
}),
|
||||
queryParams: z
|
||||
.object({
|
||||
search_space_id: z.number().optional(),
|
||||
workspace_id: z.number().optional(),
|
||||
title: z.string().optional(),
|
||||
page: z.number().optional(),
|
||||
page_size: z.number().optional(),
|
||||
})
|
||||
.refine((params) => params.search_space_id !== undefined || params.workspace_id !== undefined, {
|
||||
message: "workspace_id is required",
|
||||
path: ["search_space_id"],
|
||||
}),
|
||||
});
|
||||
|
||||
export const searchDocumentTitlesResponse = z.object({
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
import { z } from "zod";
|
||||
import { role } from "./roles.types";
|
||||
|
||||
export const membership = z.object({
|
||||
id: z.number(),
|
||||
user_id: z.string(),
|
||||
search_space_id: z.number(),
|
||||
role_id: z.number().nullable(),
|
||||
is_owner: z.boolean(),
|
||||
joined_at: z.string(),
|
||||
created_at: z.string(),
|
||||
role: role.nullable().optional(),
|
||||
user_email: z.string().nullable().optional(),
|
||||
user_display_name: z.string().nullable().optional(),
|
||||
user_avatar_url: z.string().nullable().optional(),
|
||||
user_last_login: z.string().nullable().optional(),
|
||||
user_is_active: z.boolean().nullable().optional(),
|
||||
});
|
||||
export const membership = z.preprocess(
|
||||
(value) => {
|
||||
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
||||
const record = value as Record<string, unknown>;
|
||||
if (record.search_space_id === undefined && record.workspace_id !== undefined) {
|
||||
return { ...record, search_space_id: record.workspace_id };
|
||||
}
|
||||
}
|
||||
return value;
|
||||
},
|
||||
z.object({
|
||||
id: z.number(),
|
||||
user_id: z.string(),
|
||||
search_space_id: z.number(),
|
||||
role_id: z.number().nullable(),
|
||||
is_owner: z.boolean(),
|
||||
joined_at: z.string(),
|
||||
created_at: z.string(),
|
||||
role: role.nullable().optional(),
|
||||
user_email: z.string().nullable().optional(),
|
||||
user_display_name: z.string().nullable().optional(),
|
||||
user_avatar_url: z.string().nullable().optional(),
|
||||
user_last_login: z.string().nullable().optional(),
|
||||
user_is_active: z.boolean().nullable().optional(),
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Get members
|
||||
|
|
@ -69,13 +80,19 @@ export const getMyAccessRequest = z.object({
|
|||
search_space_id: z.number(),
|
||||
});
|
||||
|
||||
export const getMyAccessResponse = z.object({
|
||||
search_space_name: z.string(),
|
||||
search_space_id: z.number(),
|
||||
is_owner: z.boolean(),
|
||||
permissions: z.array(z.string()),
|
||||
role_name: z.string().nullable(),
|
||||
});
|
||||
export const getMyAccessResponse = z
|
||||
.object({
|
||||
workspace_name: z.string(),
|
||||
workspace_id: z.number(),
|
||||
is_owner: z.boolean(),
|
||||
permissions: z.array(z.string()),
|
||||
role_name: z.string().nullable(),
|
||||
})
|
||||
.transform(({ workspace_id, workspace_name, ...rest }) => ({
|
||||
...rest,
|
||||
search_space_id: workspace_id,
|
||||
search_space_name: workspace_name,
|
||||
}));
|
||||
|
||||
export type Membership = z.infer<typeof membership>;
|
||||
export type GetMembersRequest = z.infer<typeof getMembersRequest>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { z } from "zod";
|
||||
|
||||
export const role = z.object({
|
||||
const roleBase = z.object({
|
||||
id: z.number(),
|
||||
name: z.string().min(1).max(100),
|
||||
description: z.string().max(500).nullable(),
|
||||
|
|
@ -11,12 +11,22 @@ export const role = z.object({
|
|||
created_at: z.string(),
|
||||
});
|
||||
|
||||
export const role = z.preprocess((value) => {
|
||||
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
||||
const record = value as Record<string, unknown>;
|
||||
if (record.search_space_id === undefined && record.workspace_id !== undefined) {
|
||||
return { ...record, search_space_id: record.workspace_id };
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}, roleBase);
|
||||
|
||||
/**
|
||||
* Create role
|
||||
*/
|
||||
export const createRoleRequest = z.object({
|
||||
search_space_id: z.number(),
|
||||
data: role.pick({
|
||||
data: roleBase.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
permissions: true,
|
||||
|
|
@ -51,7 +61,7 @@ export const getRoleByIdResponse = role;
|
|||
export const updateRoleRequest = z.object({
|
||||
search_space_id: z.number(),
|
||||
role_id: z.number(),
|
||||
data: role
|
||||
data: roleBase
|
||||
.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ export const updateSearchSpaceApiAccessResponse = searchSpace.omit({
|
|||
export const deleteSearchSpaceRequest = searchSpace.pick({ id: true });
|
||||
|
||||
export const deleteSearchSpaceResponse = z.object({
|
||||
message: z.literal("Search space deleted successfully"),
|
||||
message: z.literal("Workspace deleted successfully"),
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue