mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 03:29:18 +00:00
feat: completed query hooks for identities
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { queryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import {
|
||||
TGetProjectIdentityByIdDTO,
|
||||
TListProjectIdentitiesDTO,
|
||||
TProjectIdentity
|
||||
} from "./types";
|
||||
|
||||
export const projectIdentityQuery = {
|
||||
allKey: () => ["project-identities"] as const,
|
||||
getByIdKey: (params: TGetProjectIdentityByIdDTO) =>
|
||||
[...projectIdentityQuery.allKey(), "by-id", params] as const,
|
||||
listKey: (params: TListProjectIdentitiesDTO) =>
|
||||
[...projectIdentityQuery.allKey(), "list", params] as const,
|
||||
getById: (params: TGetProjectIdentityByIdDTO) =>
|
||||
queryOptions({
|
||||
queryKey: projectIdentityQuery.getByIdKey(params),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{ identity: TProjectIdentity }>(
|
||||
`/api/v1/projects/${params.projectId}/identities/${params.identityId}`
|
||||
);
|
||||
return data.identity;
|
||||
}
|
||||
}),
|
||||
list: (params: TListProjectIdentitiesDTO) =>
|
||||
queryOptions({
|
||||
queryKey: projectIdentityQuery.listKey(params),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<{
|
||||
identities: TProjectIdentity[];
|
||||
totalCount: number;
|
||||
}>(`/api/v1/projects/${params.projectId}/identities`, {
|
||||
params: {
|
||||
offset: params.offset,
|
||||
limit: params.limit,
|
||||
search: params.search
|
||||
}
|
||||
});
|
||||
return data;
|
||||
}
|
||||
})
|
||||
};
|
||||
Reference in New Issue
Block a user