mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 01:29:03 +00:00
33 lines
819 B
TypeScript
33 lines
819 B
TypeScript
import { TDbClient } from "@app/db";
|
|
import { TableName } from "@app/db/schemas";
|
|
import { DatabaseError } from "@app/lib/errors";
|
|
import { ormify } from "@app/lib/knex";
|
|
|
|
export type TSamlConfigDALFactory = ReturnType<typeof samlConfigDALFactory>;
|
|
|
|
export const samlConfigDALFactory = (db: TDbClient) => {
|
|
const samlCfgOrm = ormify(db, TableName.SamlConfig);
|
|
|
|
const findEnforceableSamlCfg = async (orgId: string) => {
|
|
try {
|
|
const samlCfg = await db
|
|
.replicaNode()(TableName.SamlConfig)
|
|
.where({
|
|
orgId,
|
|
isActive: true
|
|
})
|
|
.whereNotNull("lastUsed")
|
|
.first();
|
|
|
|
return samlCfg;
|
|
} catch (error) {
|
|
throw new DatabaseError({ error, name: "Find org by id" });
|
|
}
|
|
};
|
|
|
|
return {
|
|
...samlCfgOrm,
|
|
findEnforceableSamlCfg
|
|
};
|
|
};
|