mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
- Added the ensure_publication function to create and verify the zero_publication if it is missing, ensuring idempotency during database initialization. - Integrated ensure_publication into the create_db_and_tables function to prevent zero-cache crash loops on startup. - Introduced a self-check script to validate the ensure_publication functionality on a create_all-bootstrapped database. - Updated various components to reflect the transition from search space to workspace, including adjustments in imports and routing paths.
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { atomWithMutation } from "jotai-tanstack-query";
|
|
import { activeWorkspaceIdAtom } from "@/atoms/workspaces/workspace-query.atoms";
|
|
import type {
|
|
CreateLogRequest,
|
|
DeleteLogRequest,
|
|
UpdateLogRequest,
|
|
} from "@/contracts/types/log.types";
|
|
import { logsApiService } from "@/lib/apis/logs-api.service";
|
|
import { cacheKeys } from "@/lib/query-client/cache-keys";
|
|
import { queryClient } from "@/lib/query-client/client";
|
|
|
|
/**
|
|
* Create Log Mutation
|
|
*/
|
|
export const createLogMutationAtom = atomWithMutation((get) => {
|
|
const searchSpaceId = get(activeWorkspaceIdAtom);
|
|
return {
|
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
|
enabled: !!searchSpaceId,
|
|
mutationFn: async (request: CreateLogRequest) => logsApiService.createLog(request),
|
|
onSuccess: () => {
|
|
// Invalidate all log-related queries (list, summary, detail, withQueryParams)
|
|
queryClient.invalidateQueries({ queryKey: ["logs"] });
|
|
},
|
|
};
|
|
});
|
|
|
|
/**
|
|
* Update Log Mutation
|
|
*/
|
|
export const updateLogMutationAtom = atomWithMutation((get) => {
|
|
const searchSpaceId = get(activeWorkspaceIdAtom);
|
|
return {
|
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
|
enabled: !!searchSpaceId,
|
|
mutationFn: async ({ logId, data }: { logId: number; data: UpdateLogRequest }) =>
|
|
logsApiService.updateLog(logId, data),
|
|
onSuccess: (_data, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ["logs"] });
|
|
},
|
|
};
|
|
});
|
|
|
|
/**
|
|
* Delete Log Mutation
|
|
*/
|
|
export const deleteLogMutationAtom = atomWithMutation((get) => {
|
|
const searchSpaceId = get(activeWorkspaceIdAtom);
|
|
return {
|
|
mutationKey: cacheKeys.logs.list(searchSpaceId ?? undefined),
|
|
enabled: !!searchSpaceId,
|
|
mutationFn: async (request: DeleteLogRequest) => logsApiService.deleteLog(request),
|
|
onSuccess: (_data, request) => {
|
|
queryClient.invalidateQueries({ queryKey: ["logs"] });
|
|
},
|
|
};
|
|
});
|