misc: added transaction for cert template create and update

This commit is contained in:
Sheen Capadngan
2024-08-28 13:45:25 +08:00
parent 7ac4ad3194
commit 0ab7a4e713
2 changed files with 47 additions and 35 deletions
@@ -1,3 +1,5 @@
import { Knex } from "knex";
import { TDbClient } from "@app/db";
import { TableName } from "@app/db/schemas";
import { DatabaseError } from "@app/lib/errors";
@@ -30,10 +32,9 @@ export const certificateTemplateDALFactory = (db: TDbClient) => {
}
};
const getById = async (id: string) => {
const getById = async (id: string, tx?: Knex) => {
try {
const certTemplate = await db
.replicaNode()(TableName.CertificateTemplate)
const certTemplate = await (tx || db.replicaNode())(TableName.CertificateTemplate)
.join(
TableName.CertificateAuthority,
`${TableName.CertificateAuthority}.id`,