2026-10-24 23:19:17 +00:00
|
|
|
import type { QueryClient } from "@tanstack/react-query";
|
|
|
|
|
import { z } from "zod/v4";
|
|
|
|
|
|
|
|
|
|
import type {
|
|
|
|
|
GlobalApplicationCapabilitiesDTO,
|
|
|
|
|
ListGlobalApplicationsRequestDTO,
|
|
|
|
|
} from "../../../../common";
|
|
|
|
|
|
|
|
|
|
export const globalApplicationKeys = {
|
|
|
|
|
root: ["resource-global-applications"],
|
|
|
|
|
capabilities: ["resource-global-applications", "capabilities"],
|
|
|
|
|
list: (query: ListGlobalApplicationsRequestDTO) => [
|
|
|
|
|
"resource-global-applications",
|
|
|
|
|
"list",
|
|
|
|
|
query,
|
|
|
|
|
],
|
|
|
|
|
detail: (id: string) => ["resource-global-applications", "detail", id],
|
|
|
|
|
admin: (id: string, actor: GlobalApplicationCapabilitiesDTO) => [
|
|
|
|
|
"resource-global-applications",
|
|
|
|
|
"admin",
|
|
|
|
|
actor.actorId,
|
|
|
|
|
actor.authVersion,
|
|
|
|
|
id,
|
|
|
|
|
],
|
|
|
|
|
history: (id: string, actor: GlobalApplicationCapabilitiesDTO, cursor?: string) => [
|
|
|
|
|
"resource-global-applications",
|
|
|
|
|
"history",
|
|
|
|
|
actor.actorId,
|
|
|
|
|
actor.authVersion,
|
|
|
|
|
id,
|
|
|
|
|
cursor,
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export async function invalidateGlobalApplication(client: QueryClient, id: string) {
|
|
|
|
|
await Promise.all([
|
2026-10-25 12:46:06 +00:00
|
|
|
client.invalidateQueries({ queryKey: ["company-application-catalog"] }),
|
2026-10-24 23:19:17 +00:00
|
|
|
client.invalidateQueries({ queryKey: ["resource-application-coincidences"] }),
|
|
|
|
|
client.invalidateQueries({ queryKey: ["resource-global-applications", "list"] }),
|
|
|
|
|
client.invalidateQueries({ queryKey: globalApplicationKeys.detail(id) }),
|
|
|
|
|
client.invalidateQueries({
|
|
|
|
|
predicate: (query) =>
|
|
|
|
|
query.queryKey[0] === "resource-global-applications" &&
|
|
|
|
|
["admin", "history"].includes(String(query.queryKey[1])) &&
|
|
|
|
|
query.queryKey.includes(id),
|
|
|
|
|
}),
|
|
|
|
|
client.invalidateQueries({ queryKey: ["resource-application-candidates"] }),
|
|
|
|
|
client.invalidateQueries({
|
|
|
|
|
predicate: (query) =>
|
|
|
|
|
query.queryKey[0] === "resource-application-references" &&
|
|
|
|
|
Array.isArray(query.queryKey[3]) &&
|
|
|
|
|
query.queryKey[3].includes(id),
|
|
|
|
|
}),
|
|
|
|
|
client.invalidateQueries({
|
|
|
|
|
predicate: (query) => {
|
|
|
|
|
if (
|
|
|
|
|
!["software-installations", "application-configurations"].includes(
|
|
|
|
|
String(query.queryKey[0])
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Inspección mínima de caché ya autorizada, sin importar DTO ni APIs del módulo consumidor.
|
|
|
|
|
const used = z
|
|
|
|
|
.object({
|
|
|
|
|
configurations: z.array(z.object({ values: z.object({ resourceId: z.uuid() }) })),
|
|
|
|
|
})
|
|
|
|
|
.safeParse(query.state.data);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
used.success && used.data.configurations.some((item) => item.values.resourceId === id)
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}
|