mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 20:27:43 +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 { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { TPkiAcmeAccountsInsert, TPkiAcmeAccountsUpdate } from "@app/db/schemas/pki-acme-accounts";
|
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
import { ormify } from "@app/lib/knex";
|
import { ormify } from "@app/lib/knex";
|
||||||
|
|
||||||
@@ -11,21 +10,6 @@ export type TPkiAcmeAccountDALFactory = ReturnType<typeof pkiAcmeAccountDALFacto
|
|||||||
export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
||||||
const pkiAcmeAccountOrm = ormify(db, TableName.PkiAcmeAccount);
|
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) => {
|
const findByProjectIdAndAccountId = async (profileId: string, id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, id }).first();
|
const account = await (tx || db)(TableName.PkiAcmeAccount).where({ profileId, id }).first();
|
||||||
@@ -48,7 +32,6 @@ export const pkiAcmeAccountDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...pkiAcmeAccountOrm,
|
...pkiAcmeAccountOrm,
|
||||||
create,
|
|
||||||
findByProjectIdAndAccountId,
|
findByProjectIdAndAccountId,
|
||||||
findByPublicKey
|
findByPublicKey
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,59 +2,53 @@ import { Knex } from "knex";
|
|||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { TPkiAcmeAuthsInsert, TPkiAcmeAuthsUpdate } from "@app/db/schemas/pki-acme-auths";
|
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
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 type TPkiAcmeAuthDALFactory = ReturnType<typeof pkiAcmeAuthDALFactory>;
|
||||||
|
|
||||||
export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
|
export const pkiAcmeAuthDALFactory = (db: TDbClient) => {
|
||||||
const pkiAcmeAuthOrm = ormify(db, TableName.PkiAcmeAuth);
|
const pkiAcmeAuthOrm = ormify(db, TableName.PkiAcmeAuth);
|
||||||
|
|
||||||
const create = async (data: TPkiAcmeAuthsInsert, tx?: Knex) => {
|
const findByAccountIdAndAuthIdWithChallenges = async (accountId: string, authId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const result = await (tx || db)(TableName.PkiAcmeAuth).insert(data).returning("*");
|
const rows = await (tx || db)(TableName.PkiAcmeAuth)
|
||||||
const [auth] = result;
|
.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) {
|
if (rows.length === 0) {
|
||||||
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) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return sqlNestRelationships({
|
||||||
return auth;
|
data: rows,
|
||||||
} catch (error) {
|
key: "id",
|
||||||
throw new DatabaseError({ error, name: "Update PKI ACME auth" });
|
parentMapper: (row) => row,
|
||||||
|
childrenMapper: [
|
||||||
|
{
|
||||||
|
key: "challengeId",
|
||||||
|
label: "challenges" as const,
|
||||||
|
mapper: ({ challengeId, challengeToken, challengeStatus }) => ({
|
||||||
|
id: challengeId,
|
||||||
|
token: challengeToken,
|
||||||
|
status: challengeStatus
|
||||||
|
})
|
||||||
}
|
}
|
||||||
};
|
]
|
||||||
|
})?.[0];
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
|
||||||
try {
|
|
||||||
const auth = await (tx || db)(TableName.PkiAcmeAuth).where({ id }).first();
|
|
||||||
|
|
||||||
return auth || null;
|
|
||||||
} catch (error) {
|
} 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 {
|
return {
|
||||||
...pkiAcmeAuthOrm,
|
...pkiAcmeAuthOrm,
|
||||||
create,
|
findByAccountIdAndAuthIdWithChallenges
|
||||||
updateById,
|
|
||||||
findById
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { Knex } from "knex";
|
|
||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
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";
|
import { ormify } from "@app/lib/knex";
|
||||||
|
|
||||||
export type TPkiAcmeOrderAuthDALFactory = ReturnType<typeof pkiAcmeOrderAuthDALFactory>;
|
export type TPkiAcmeOrderAuthDALFactory = ReturnType<typeof pkiAcmeOrderAuthDALFactory>;
|
||||||
@@ -11,17 +7,7 @@ export type TPkiAcmeOrderAuthDALFactory = ReturnType<typeof pkiAcmeOrderAuthDALF
|
|||||||
export const pkiAcmeOrderAuthDALFactory = (db: TDbClient) => {
|
export const pkiAcmeOrderAuthDALFactory = (db: TDbClient) => {
|
||||||
const pkiAcmeOrderAuthOrm = ormify(db, TableName.PkiAcmeOrderAuth);
|
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 {
|
return {
|
||||||
...pkiAcmeOrderAuthOrm,
|
...pkiAcmeOrderAuthOrm
|
||||||
insertMany
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Knex } from "knex";
|
|||||||
|
|
||||||
import { TDbClient } from "@app/db";
|
import { TDbClient } from "@app/db";
|
||||||
import { TableName } from "@app/db/schemas";
|
import { TableName } from "@app/db/schemas";
|
||||||
import { TPkiAcmeOrdersInsert, TPkiAcmeOrdersUpdate } from "@app/db/schemas/pki-acme-orders";
|
|
||||||
import { DatabaseError } from "@app/lib/errors";
|
import { DatabaseError } from "@app/lib/errors";
|
||||||
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
|
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
|
||||||
|
|
||||||
@@ -11,46 +10,6 @@ export type TPkiAcmeOrderDALFactory = ReturnType<typeof pkiAcmeOrderDALFactory>;
|
|||||||
export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
||||||
const pkiAcmeOrderOrm = ormify(db, TableName.PkiAcmeOrder);
|
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) => {
|
const findByAccountAndOrderIdWithAuthorizations = async (accountId: string, orderId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const rows = await (tx || db)(TableName.PkiAcmeOrder)
|
const rows = await (tx || db)(TableName.PkiAcmeOrder)
|
||||||
@@ -94,9 +53,6 @@ export const pkiAcmeOrderDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...pkiAcmeOrderOrm,
|
...pkiAcmeOrderOrm,
|
||||||
create,
|
|
||||||
updateById,
|
|
||||||
findById,
|
|
||||||
findByAccountAndOrderIdWithAuthorizations
|
findByAccountAndOrderIdWithAuthorizations
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user