diff --git a/backend/src/services/certificate-policy/certificate-policy-dal.ts b/backend/src/services/certificate-policy/certificate-policy-dal.ts index fcc21ec829b..f82df2d46e7 100644 --- a/backend/src/services/certificate-policy/certificate-policy-dal.ts +++ b/backend/src/services/certificate-policy/certificate-policy-dal.ts @@ -120,7 +120,11 @@ export const certificatePolicyDALFactory = (db: TDbClient) => { .del() .returning("*")) as Record[]; - return certificatePolicy; + if (!certificatePolicy) { + return null; + } + + return parseJsonFields(certificatePolicy); } catch (error) { throw new DatabaseError({ error, name: "Delete certificate policy" }); } diff --git a/backend/src/services/certificate-policy/certificate-policy-service.ts b/backend/src/services/certificate-policy/certificate-policy-service.ts index d6ec733a02d..30205009728 100644 --- a/backend/src/services/certificate-policy/certificate-policy-service.ts +++ b/backend/src/services/certificate-policy/certificate-policy-service.ts @@ -1007,7 +1007,7 @@ export const certificatePolicyServiceFactory = ({ throw new NotFoundError({ message: "Failed to delete certificate policy" }); } - return deletedTemplate as TCertificatePolicy; + return deletedTemplate; }; const validateCertificateRequest = async ( diff --git a/backend/src/services/certificate-profile/certificate-profile-dal.ts b/backend/src/services/certificate-profile/certificate-profile-dal.ts index b008ca1d978..82085f33143 100644 --- a/backend/src/services/certificate-profile/certificate-profile-dal.ts +++ b/backend/src/services/certificate-profile/certificate-profile-dal.ts @@ -78,13 +78,19 @@ export const certificateProfileDALFactory = (db: TDbClient) => { } }; - const deleteById = async (id: string, tx?: Knex): Promise => { + const deleteById = async (id: string, tx?: Knex): Promise => { try { - const [certificateProfile] = (await (tx || db)(TableName.PkiCertificateProfile) - .where({ id }) - .del() - .returning("*")) as [TCertificateProfile]; - return certificateProfile; + const [certificateProfile] = await (tx || db)(TableName.PkiCertificateProfile).where({ id }).del().returning("*"); + + if (!certificateProfile) return undefined; + + return { + ...certificateProfile, + externalConfigs: certificateProfile.externalConfigs + ? (JSON.parse(certificateProfile.externalConfigs) as Record) + : null, + defaults: (certificateProfile.defaults as TCertificateProfileDefaults) ?? null + } as TCertificateProfile; } catch (error) { throw new DatabaseError({ error, name: "Delete certificate profile" }); }