Update check-collections-containing-asset.ts

This commit is contained in:
Nate Kelley 2025-09-20 14:36:34 -06:00
parent 3cdd0bfa57
commit e5dbf41db5
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 5 additions and 13 deletions

View File

@ -13,6 +13,7 @@ import type {
BusterMetricDataExtended,
} from '@/api/asset_interfaces/metric';
import { metricsQueryKeys } from '@/api/query_keys/metric';
import { silenceAssetErrors } from '@/api/repsonse-helpers/silenece-asset-errors';
import {
getProtectedAssetPassword,
setProtectedAssetPasswordError,
@ -131,6 +132,7 @@ export const prefetchGetMetric = async (
password: undefined,
queryClient,
}),
retry: silenceAssetErrors,
});
}

View File

@ -11,19 +11,9 @@ export interface CollectionWithSharing {
export async function checkCollectionsContainingAsset(
assetId: string,
assetType: 'metric_file' | 'dashboard_file' | 'chat'
assetType: Extract<AssetType, 'metric_file' | 'dashboard_file' | 'chat' | 'report_file'>
): Promise<CollectionWithSharing[]> {
// Map our asset type strings to the enum values expected by the database
const assetTypeMap: Record<string, AssetType> = {
metric: 'metric_file',
dashboard: 'dashboard_file',
chat: 'chat',
};
const dbAssetType = assetTypeMap[assetType];
if (!dbAssetType) {
throw new Error(`Invalid asset type: ${assetType}`);
}
// The asset type parameter already matches the AssetType enum values
const result = await db
.select({
@ -36,7 +26,7 @@ export async function checkCollectionsContainingAsset(
.where(
and(
eq(collectionsToAssets.assetId, assetId),
eq(collectionsToAssets.assetType, dbAssetType),
eq(collectionsToAssets.assetType, assetType),
isNull(collectionsToAssets.deletedAt),
isNull(collections.deletedAt)
)