mirror of https://github.com/buster-so/buster.git
clean up tyeps
This commit is contained in:
parent
532ec54798
commit
4d7f1353ff
|
@ -1,4 +1,4 @@
|
|||
import type { Organization, OrganizationMember, User } from '@buster/database';
|
||||
import type { Organization, User } from '@buster/database';
|
||||
|
||||
export function createTestUser(overrides?: Partial<User>): User {
|
||||
const id = `test-user-${Math.random().toString(36).substring(7)}`;
|
||||
|
@ -39,35 +39,3 @@ export function createTestOrgMember(
|
|||
role,
|
||||
};
|
||||
}
|
||||
|
||||
export function createMockGetUserOrganizationId() {
|
||||
return vi.fn();
|
||||
}
|
||||
|
||||
export function createMockDb() {
|
||||
const mockSelect = vi.fn().mockReturnThis();
|
||||
const mockFrom = vi.fn().mockReturnThis();
|
||||
const mockWhere = vi.fn().mockReturnThis();
|
||||
const mockLimit = vi.fn().mockReturnThis();
|
||||
const mockUpdate = vi.fn().mockReturnThis();
|
||||
const mockSet = vi.fn().mockReturnThis();
|
||||
const mockReturning = vi.fn();
|
||||
|
||||
return {
|
||||
select: mockSelect,
|
||||
from: mockFrom,
|
||||
where: mockWhere,
|
||||
limit: mockLimit,
|
||||
update: mockUpdate,
|
||||
set: mockSet,
|
||||
returning: mockReturning,
|
||||
// For chaining
|
||||
mockSelect,
|
||||
mockFrom,
|
||||
mockWhere,
|
||||
mockLimit,
|
||||
mockUpdate,
|
||||
mockSet,
|
||||
mockReturning,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { type User, and, db, eq, isNull, organizations } from '@buster/database';
|
||||
import type { OrganizationRole } from '@buster/server-shared/organization';
|
||||
import type {
|
||||
UpdateWorkspaceSettingsRequest,
|
||||
UpdateWorkspaceSettingsResponse,
|
||||
|
@ -96,13 +97,28 @@ async function updateOrganizationSettings(
|
|||
updateData: {
|
||||
updatedAt: string;
|
||||
restrictNewUserInvitations?: boolean;
|
||||
defaultRole?: string;
|
||||
defaultRole?: OrganizationRole;
|
||||
}
|
||||
): Promise<void> {
|
||||
try {
|
||||
const dbUpdateData: {
|
||||
updatedAt: string;
|
||||
restrictNewUserInvitations?: boolean;
|
||||
defaultRole?: Exclude<OrganizationRole, 'none'>;
|
||||
} = {
|
||||
updatedAt: updateData.updatedAt,
|
||||
...(updateData.restrictNewUserInvitations !== undefined && {
|
||||
restrictNewUserInvitations: updateData.restrictNewUserInvitations,
|
||||
}),
|
||||
...(updateData.defaultRole !== undefined &&
|
||||
updateData.defaultRole !== 'none' && {
|
||||
defaultRole: updateData.defaultRole as Exclude<OrganizationRole, 'none'>,
|
||||
}),
|
||||
};
|
||||
|
||||
await db
|
||||
.update(organizations)
|
||||
.set(updateData)
|
||||
.set(dbUpdateData)
|
||||
.where(and(eq(organizations.id, organizationId), isNull(organizations.deletedAt)));
|
||||
|
||||
console.info('Updated organization settings:', {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import type { OrganizationRole } from '@buster/server-shared/organization';
|
||||
import type {
|
||||
GetWorkspaceSettingsResponse,
|
||||
UpdateWorkspaceSettingsRequest,
|
||||
|
@ -6,13 +7,7 @@ import type {
|
|||
export class WorkspaceSettingsService {
|
||||
formatWorkspaceSettingsResponse(settings: {
|
||||
restrictNewUserInvitations: boolean;
|
||||
defaultRole:
|
||||
| 'workspace_admin'
|
||||
| 'data_admin'
|
||||
| 'querier'
|
||||
| 'restricted_querier'
|
||||
| 'viewer'
|
||||
| 'none';
|
||||
defaultRole: OrganizationRole;
|
||||
defaultDatasets?: Array<{ id: string; name: string }>;
|
||||
}): GetWorkspaceSettingsResponse {
|
||||
return {
|
||||
|
@ -25,12 +20,12 @@ export class WorkspaceSettingsService {
|
|||
buildUpdateData(request: UpdateWorkspaceSettingsRequest): {
|
||||
updatedAt: string;
|
||||
restrictNewUserInvitations?: boolean;
|
||||
defaultRole?: string;
|
||||
defaultRole?: OrganizationRole;
|
||||
} {
|
||||
const updateData: {
|
||||
updatedAt: string;
|
||||
restrictNewUserInvitations?: boolean;
|
||||
defaultRole?: string;
|
||||
defaultRole?: OrganizationRole;
|
||||
} = {
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import type { userOrganizationRoleEnum } from '@buster/database'; //we import as type to avoid postgres dependency in the frontend ☹️
|
||||
import { z } from 'zod/v4';
|
||||
|
||||
type OrganizationRoleBase = (typeof userOrganizationRoleEnum.enumValues)[number] | 'none';
|
||||
type OrganizationRoleBase = (typeof userOrganizationRoleEnum.enumValues)[number];
|
||||
|
||||
//We need this to avoid postgres dependency in the frontend ☹️
|
||||
export const OrganizationRoleEnum: Record<OrganizationRoleBase, OrganizationRoleBase> =
|
||||
Object.freeze({
|
||||
none: 'none',
|
||||
// Got rid of none becauase it's not a valid role.
|
||||
viewer: 'viewer',
|
||||
workspace_admin: 'workspace_admin',
|
||||
data_admin: 'data_admin',
|
||||
|
|
Loading…
Reference in New Issue