misc: addressed comments

This commit is contained in:
Sheen Capadngan
2025-05-17 03:42:49 +08:00
parent 60ea4bb579
commit edefa7698c
25 changed files with 744 additions and 303 deletions
+3 -1
View File
@@ -4,10 +4,12 @@ export {
useCreateCertificate,
useCreateUnifiedCa,
useDeleteCa,
useDeleteUnifiedCa,
useImportCaCertificate,
useRenewCa,
useSignIntermediate,
useUpdateCa
useUpdateCa,
useUpdateUnifiedCa
} from "./mutations";
export {
useGetCaById,
+43 -1
View File
@@ -11,6 +11,7 @@ import {
TCreateCertificateResponse,
TCreateUnifiedCertificateAuthorityDTO,
TDeleteCaDTO,
TDeleteUnifiedCertificateAuthorityDTO,
TImportCaCertificateDTO,
TImportCaCertificateResponse,
TRenewCaDTO,
@@ -18,9 +19,31 @@ import {
TSignIntermediateDTO,
TSignIntermediateResponse,
TUnifiedCertificateAuthority,
TUpdateCaDTO
TUpdateCaDTO,
TUpdateUnifiedCertificateAuthorityDTO
} from "./types";
export const useUpdateUnifiedCa = () => {
const queryClient = useQueryClient();
return useMutation<TUnifiedCertificateAuthority, object, TUpdateUnifiedCertificateAuthorityDTO>({
mutationFn: async ({ id, ...body }) => {
const {
data: { certificateAuthority }
} = await apiRequest.patch<{ certificateAuthority: TUnifiedCertificateAuthority }>(
`/api/v1/pki/ca/${body.type}/${id}`,
body
);
return certificateAuthority;
},
onSuccess: ({ projectId, type }) => {
queryClient.invalidateQueries({
queryKey: caKeys.listCasByTypeAndProjectId(type, projectId)
});
}
});
};
export const useCreateUnifiedCa = () => {
const queryClient = useQueryClient();
return useMutation<TUnifiedCertificateAuthority, object, TCreateUnifiedCertificateAuthorityDTO>({
@@ -39,6 +62,25 @@ export const useCreateUnifiedCa = () => {
});
};
export const useDeleteUnifiedCa = () => {
const queryClient = useQueryClient();
return useMutation<TUnifiedCertificateAuthority, object, TDeleteUnifiedCertificateAuthorityDTO>({
mutationFn: async ({ caId, type }) => {
const {
data: { certificateAuthority }
} = await apiRequest.delete<{ certificateAuthority: TUnifiedCertificateAuthority }>(
`/api/v1/pki/ca/${type}/${caId}`
);
return certificateAuthority;
},
onSuccess: (_, { type, projectId }) => {
queryClient.invalidateQueries({
queryKey: caKeys.listCasByTypeAndProjectId(type, projectId)
});
}
});
};
export const useCreateCa = () => {
const queryClient = useQueryClient();
return useMutation<TCertificateAuthority, object, TCreateCaDTO>({
+14 -1
View File
@@ -10,7 +10,10 @@ export type TAcmeCertificateAuthority = {
disableDirectIssuance: boolean;
configuration: {
dnsAppConnectionId: string;
dnsProvider: AcmeDnsProvider;
dnsProviderConfig: {
provider: AcmeDnsProvider.ROUTE53;
hostedZoneId: string;
};
directoryUrl: string;
accountEmail: string;
};
@@ -48,6 +51,16 @@ export type TUnifiedCertificateAuthority =
| TInternalCertificateAuthority;
export type TCreateUnifiedCertificateAuthorityDTO = Omit<TUnifiedCertificateAuthority, "id">;
export type TUpdateUnifiedCertificateAuthorityDTO = Partial<TUnifiedCertificateAuthority> & {
id: string;
type: CaType;
};
export type TDeleteUnifiedCertificateAuthorityDTO = {
caId: string;
type: CaType;
projectId: string;
};
export type TCertificateAuthority = {
id: string;
@@ -1,6 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TReactQueryOptions } from "@app/types/reactQuery";
import { TCertificate } from "../certificates/types";
import { TPkiSubscriber } from "./types";
@@ -62,17 +63,20 @@ export const useGetPkiSubscriber = ({
});
};
export const useGetPkiSubscriberCertificates = ({
subscriberName,
projectId,
offset,
limit
}: {
subscriberName: string;
projectId: string;
offset: number;
limit: number;
}) => {
export const useGetPkiSubscriberCertificates = (
{
subscriberName,
projectId,
offset,
limit
}: {
subscriberName: string;
projectId: string;
offset: number;
limit: number;
},
options?: TReactQueryOptions["options"]
) => {
return useQuery({
queryKey: pkiSubscriberKeys.specificPkiSubscriberCertificates({
subscriberName,
@@ -97,6 +101,7 @@ export const useGetPkiSubscriberCertificates = ({
);
return { certificates, totalCount };
},
enabled: Boolean(subscriberName) && Boolean(projectId)
enabled: Boolean(subscriberName) && Boolean(projectId),
...options
});
};