mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-19 00:30:56 +00:00
Fix: Requested changes
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
import { TDbClient } from "@app/db";
|
||||
import { TableName, TSuperAdmin } from "@app/db/schemas";
|
||||
import { TableName, TSuperAdmin, TSuperAdminUpdate } from "@app/db/schemas";
|
||||
import { ormify } from "@app/lib/knex";
|
||||
|
||||
export type TSuperAdminDALFactory = ReturnType<typeof superAdminDALFactory>;
|
||||
|
||||
export const superAdminDALFactory = (db: TDbClient) => {
|
||||
const orm = ormify(db, TableName.SuperAdmin);
|
||||
const superAdminOrm = ormify(db, TableName.SuperAdmin);
|
||||
|
||||
const findById = async (id: string) => {
|
||||
const config = await db(TableName.SuperAdmin)
|
||||
const findById = async (id: string, tx?: Knex) => {
|
||||
const config = await (tx || db)(TableName.SuperAdmin)
|
||||
.where(`${TableName.SuperAdmin}.id`, id)
|
||||
.leftJoin(TableName.Organization, `${TableName.SuperAdmin}.defaultAuthOrgId`, `${TableName.Organization}.id`)
|
||||
.select(
|
||||
@@ -23,8 +25,20 @@ export const superAdminDALFactory = (db: TDbClient) => {
|
||||
} as TSuperAdmin & { defaultAuthOrgSlug: string | null };
|
||||
};
|
||||
|
||||
const updateById = async (id: string, data: TSuperAdminUpdate, tx?: Knex) => {
|
||||
const updatedConfig = await superAdminOrm.transaction(async (trx) => {
|
||||
await superAdminOrm.updateById(id, data, tx || trx);
|
||||
const config = await findById(id, tx || trx);
|
||||
|
||||
return config;
|
||||
});
|
||||
|
||||
return updatedConfig;
|
||||
};
|
||||
|
||||
return {
|
||||
...orm,
|
||||
findById
|
||||
...superAdminOrm,
|
||||
findById,
|
||||
updateById
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user