mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Remove not needed dal methods
This commit is contained in:
@@ -2,7 +2,6 @@ import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { TPkiAcmeAccountsInsert, TPkiAcmeAccountsUpdate } from "@app/db/schemas/pki-acme-accounts";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
|
||||
@@ -11,21 +10,6 @@ export type TPkiAcmeAccountDALFactory = ReturnType<typeof pkiAcmeAccountDALFacto
|
||||
export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
||||
const pkiAcmeAccountOrm = ormify(db, TableName.PkiAcmeAccount);
|
||||
|
||||
const create = async (data: TPkiAcmeAccountsInsert, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeAccount).insert(data).returning("*");
|
||||
const [account] = result;
|
||||
|
||||
if (!account) {
|
||||
throw new Error("Failed to create PKI ACME account");
|
||||
}
|
||||
|
||||
return account;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Create PKI ACME account" });
|
||||
}
|
||||
};
|
||||
|
||||
const findByProjectIdAndAccountId = async (profileId: string, id: string, tx?: Knex) => {
|
||||
try {
|
||||
const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, id }).first();
|
||||
@@ -48,7 +32,6 @@ export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
||||
|
||||
return {
|
||||
...pkiAcmeAccountOrm,
|
||||
create,
|
||||
findByProjectIdAndAccountId,
|
||||
findByPublicKey
|
||||
};
|
||||
|
||||
@@ -2,59 +2,53 @@ import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { TPkiAcmeAuthsInsert, TPkiAcmeAuthsUpdate } from "@app/db/schemas/pki-acme-auths";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
|
||||
|
||||
export type TPkiAcmeAuthDALFactory = ReturnType<typeof pkiAcmeAuthDALFactory>;
|
||||
|
||||
export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
|
||||
const pkiAcmeAuthOrm = ormify(db, TableName.PkiAcmeAuth);
|
||||
|
||||
const create = async (data: TPkiAcmeAuthsInsert, tx?: Knex) => {
|
||||
const findByAccountIdAndAuthIdWithChallenges = async (accountId: string, authId: string, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeAuth).insert(data).returning("*");
|
||||
const [auth] = result;
|
||||
const rows = await (tx || db)(TableName.PkiAcmeAuth)
|
||||
.join(TableName.PkiAcmeChallenge, `${TableName.PkiAcmeChallenge}.authId`, `${TableName.PkiAcmeAuth}.id`)
|
||||
.select(
|
||||
selectAllTableCols(TableName.PkiAcmeAuth),
|
||||
db.ref("id").withSchema(TableName.PkiAcmeChallenge).as("challengeId"),
|
||||
db.ref("token").withSchema(TableName.PkiAcmeChallenge).as("challengeToken"),
|
||||
db.ref("status").withSchema(TableName.PkiAcmeChallenge).as("challengeStatus")
|
||||
)
|
||||
.where(`${TableName.PkiAcmeAuth}.accountId`, accountId)
|
||||
.where(`${TableName.PkiAcmeAuth}.id`, authId);
|
||||
|
||||
if (!auth) {
|
||||
throw new Error("Failed to create PKI ACME auth");
|
||||
}
|
||||
|
||||
return auth;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Create PKI ACME auth" });
|
||||
}
|
||||
};
|
||||
|
||||
const updateById = async (id: string, data: TPkiAcmeAuthsUpdate, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeAuth).where({ id }).update(data).returning("*");
|
||||
const [auth] = result;
|
||||
|
||||
if (!auth) {
|
||||
if (rows.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return auth;
|
||||
return sqlNestRelationships({
|
||||
data: rows,
|
||||
key: "id",
|
||||
parentMapper: (row) => row,
|
||||
childrenMapper: [
|
||||
{
|
||||
key: "challengeId",
|
||||
label: "challenges" as const,
|
||||
mapper: ({ challengeId, challengeToken, challengeStatus }) => ({
|
||||
id: challengeId,
|
||||
token: challengeToken,
|
||||
status: challengeStatus
|
||||
})
|
||||
}
|
||||
]
|
||||
})?.[0];
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Update PKI ACME auth" });
|
||||
}
|
||||
};
|
||||
|
||||
const findById = async (id: string, tx?: Knex) => {
|
||||
try {
|
||||
const auth = await (tx || db)(TableName.PkiAcmeAuth).where({ id }).first();
|
||||
|
||||
return auth || null;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find PKI ACME auth by id" });
|
||||
throw new DatabaseError({ error, name: "Find PKI ACME auth by account id and auth id with challenges" });
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...pkiAcmeAuthOrm,
|
||||
create,
|
||||
updateById,
|
||||
findById
|
||||
findByAccountIdAndAuthIdWithChallenges
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { TPkiAcmeOrderAuthsInsert } from "@app/db/schemas/pki-acme-order-auths";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
|
||||
export type TPkiAcmeOrderAuthDALFactory = ReturnType<typeof pkiAcmeOrderAuthDALFactory>;
|
||||
@@ -11,17 +7,7 @@ export type TPkiAcmeOrderAuthDALFactory = ReturnType<typeof pkiAcmeOrderAuthDALF
|
||||
export const pkiAcmeOrderAuthDALFactory = (db: TDbClient) => {
|
||||
const pkiAcmeOrderAuthOrm = ormify(db, TableName.PkiAcmeOrderAuth);
|
||||
|
||||
const insertMany = async (rows: TPkiAcmeOrderAuthsInsert[], tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeOrderAuth).insert(rows).returning("*");
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Insert many PKI ACME order auths" });
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
...pkiAcmeOrderAuthOrm,
|
||||
insertMany
|
||||
...pkiAcmeOrderAuthOrm
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@ import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName } from "@app/db/schemas";
|
||||
import { TPkiAcmeOrdersInsert, TPkiAcmeOrdersUpdate } from "@app/db/schemas/pki-acme-orders";
|
||||
import { DatabaseError } from "@app/lib/errors";
|
||||
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
|
||||
|
||||
@@ -11,46 +10,6 @@ export type TPkiAcmeOrderDALFactory = ReturnType<typeof pkiAcmeOrderDALFactory>;
|
||||
export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
||||
const pkiAcmeOrderOrm = ormify(db, TableName.PkiAcmeOrder);
|
||||
|
||||
const create = async (data: TPkiAcmeOrdersInsert, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeOrder).insert(data).returning("*");
|
||||
const [order] = result;
|
||||
|
||||
if (!order) {
|
||||
throw new Error("Failed to create PKI ACME order");
|
||||
}
|
||||
|
||||
return order;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Create PKI ACME order" });
|
||||
}
|
||||
};
|
||||
|
||||
const updateById = async (id: string, data: TPkiAcmeOrdersUpdate, tx?: Knex) => {
|
||||
try {
|
||||
const result = await (tx || db)(TableName.PkiAcmeOrder).where({ id }).update(data).returning("*");
|
||||
const [order] = result;
|
||||
|
||||
if (!order) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return order;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Update PKI ACME order" });
|
||||
}
|
||||
};
|
||||
|
||||
const findById = async (id: string, tx?: Knex) => {
|
||||
try {
|
||||
const order = await (tx || db)(TableName.PkiAcmeOrder).where({ id }).first();
|
||||
|
||||
return order || null;
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "Find PKI ACME order by id" });
|
||||
}
|
||||
};
|
||||
|
||||
const findByAccountAndOrderIdWithAuthorizations = async (accountId: string, orderId: string, tx?: Knex) => {
|
||||
try {
|
||||
const rows = await (tx || db)(TableName.PkiAcmeOrder)
|
||||
@@ -94,9 +53,6 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
||||
|
||||
return {
|
||||
...pkiAcmeOrderOrm,
|
||||
create,
|
||||
updateById,
|
||||
findById,
|
||||
findByAccountAndOrderIdWithAuthorizations
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user