mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
Address code review feedback - use spread operator, fix path parsing logic, remove non-null assertion
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -78,14 +78,11 @@ export async function getSessionUser(_req?: Request): Promise<SessionUser> {
|
||||
}
|
||||
|
||||
// Convert User to Record<string, unknown> for compatibility
|
||||
// Use spread operator for maintainability
|
||||
return {
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
...user,
|
||||
tenantId: user.tenantId ?? null,
|
||||
createdAt: user.createdAt,
|
||||
profilePicture: user.profilePicture ?? null,
|
||||
bio: user.bio ?? null,
|
||||
isInstanceOwner: user.isInstanceOwner ?? false,
|
||||
|
||||
@@ -30,9 +30,9 @@ export function parseRoute(url: string): ParsedRoute {
|
||||
|
||||
// Try to extract tenant/package/path from segments
|
||||
// Pattern: /{tenant}/{package}/...rest
|
||||
if (segments.length >= 1) {
|
||||
if (segments.length >= 1 && segments[0] !== undefined) {
|
||||
const firstSegment = segments[0]
|
||||
if (firstSegment !== undefined && !isReservedPath(firstSegment)) {
|
||||
if (!isReservedPath(firstSegment)) {
|
||||
result.tenant = firstSegment
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,9 @@ export function getTableName(entity: string, tenantId?: string): string {
|
||||
}
|
||||
|
||||
export function isReservedPath(path: string): boolean {
|
||||
// Get the first segment of the path
|
||||
const segment = path.startsWith('/') ? path.split('/')[1] : path.split('/')[0]
|
||||
// Normalize path to get the first segment
|
||||
const normalizedPath = path.startsWith('/') ? path.slice(1) : path
|
||||
const segment = normalizedPath.split('/')[0]
|
||||
|
||||
// Check if the segment matches any reserved paths
|
||||
return segment !== undefined && RESERVED_PATHS.includes(segment)
|
||||
|
||||
Reference in New Issue
Block a user