feat: be able to edit certificate

This commit is contained in:
Bima42
2025-12-26 14:00:58 +01:00
parent e4384075f2
commit 70776ba8ca
4 changed files with 169 additions and 52 deletions
@@ -126,3 +126,39 @@ const createCertificateFiles = async (certificate: Certificate) => {
fs.writeFileSync(configFile, yamlConfig);
}
};
export const updateCertificate = async (
certificateId: string,
updates: {
name?: string;
certificateData?: string;
privateKey?: string;
autoRenew?: boolean;
},
) => {
const existing = await findCertificateById(certificateId);
const updated = await db
.update(certificates)
.set({
...updates,
})
.where(eq(certificates.certificateId, certificateId))
.returning();
if (!updated || updated[0] === undefined) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Failed to update the certificate",
});
}
const cert = updated[0];
// If cert data or private key changed, rewrite files
if (updates.certificateData || updates.privateKey) {
await createCertificateFiles(cert);
}
return cert;
};