Fix: Handle potential undefined values in LDAP query builder and database queries.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/e6f1810b-5d83-4907-ac49-d7d4e6aaf193.jpg
This commit is contained in:
alphaeusmote
2025-04-09 01:02:31 +00:00
parent f7908467b7
commit e27da69dd8
2 changed files with 14 additions and 14 deletions
+6 -6
View File
@@ -80,28 +80,28 @@ const LdapQueryBuilderPage = () => {
// Query to get LDAP connections // Query to get LDAP connections
const { const {
data: connections, data: connections = [],
isLoading: connectionsLoading isLoading: connectionsLoading
} = useQuery({ } = useQuery<LdapConnection[]>({
queryKey: ["/api/ldap-connections"], queryKey: ["/api/ldap-connections"],
enabled: !!user enabled: !!user
}); });
// Query to get LDAP filters for the selected connection // Query to get LDAP filters for the selected connection
const { const {
data: filters, data: filters = [],
isLoading: filtersLoading isLoading: filtersLoading
} = useQuery({ } = useQuery<LdapFilter[]>({
queryKey: ["/api/connections", selectedConnectionId, "ldap-filters"], queryKey: ["/api/connections", selectedConnectionId, "ldap-filters"],
enabled: !!selectedConnectionId, enabled: !!selectedConnectionId,
}); });
// Query to get LDAP filter revisions // Query to get LDAP filter revisions
const { const {
data: revisions, data: revisions = [],
isLoading: revisionsLoading, isLoading: revisionsLoading,
refetch: refetchRevisions refetch: refetchRevisions
} = useQuery({ } = useQuery<LdapFilterRevision[]>({
queryKey: ["/api/ldap-filters", selectedFilter?.id, "revisions"], queryKey: ["/api/ldap-filters", selectedFilter?.id, "revisions"],
enabled: !!selectedFilter?.id && showRevisionsDialog, enabled: !!selectedFilter?.id && showRevisionsDialog,
}); });
+8 -8
View File
@@ -590,12 +590,12 @@ export class DatabaseStorage implements IStorage {
// Apply where conditions if any // Apply where conditions if any
if (whereClause) { if (whereClause) {
baseQuery = baseQuery.where(whereClause); baseQuery = baseQuery.where(whereClause as any);
} }
// Apply ordering if any // Apply ordering if any
if (orderClauses.length > 0) { if (orderClauses && orderClauses.length > 0) {
baseQuery = baseQuery.orderBy(...orderClauses); baseQuery = baseQuery.orderBy(...(orderClauses as any[]));
} }
// Apply pagination if specified // Apply pagination if specified
@@ -611,7 +611,7 @@ export class DatabaseStorage implements IStorage {
const users = await baseQuery; const users = await baseQuery;
// Handle field selection if specified // Handle field selection if specified
if (selectedFields.length > 0) { if (selectedFields && selectedFields.length > 0) {
const result = users.map(user => { const result = users.map(user => {
const filtered: Partial<AdUser> = { id: user.id }; const filtered: Partial<AdUser> = { id: user.id };
selectedFields.forEach(field => { selectedFields.forEach(field => {
@@ -679,12 +679,12 @@ export class DatabaseStorage implements IStorage {
// Apply where conditions if any // Apply where conditions if any
if (whereClause) { if (whereClause) {
baseQuery = baseQuery.where(whereClause); baseQuery = baseQuery.where(whereClause as any);
} }
// Apply ordering if any // Apply ordering if any
if (orderClauses.length > 0) { if (orderClauses && orderClauses.length > 0) {
baseQuery = baseQuery.orderBy(...orderClauses); baseQuery = baseQuery.orderBy(...(orderClauses as any[]));
} }
// Apply pagination if specified // Apply pagination if specified
@@ -700,7 +700,7 @@ export class DatabaseStorage implements IStorage {
const groups = await baseQuery; const groups = await baseQuery;
// Handle field selection if specified // Handle field selection if specified
if (selectedFields.length > 0) { if (selectedFields && selectedFields.length > 0) {
const result = groups.map(group => { const result = groups.map(group => {
const filtered: Partial<AdGroup> = { id: group.id }; const filtered: Partial<AdGroup> = { id: group.id };
selectedFields.forEach(field => { selectedFields.forEach(field => {