mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 19:28:09 +00:00
feat: switched read db operations to replica nodes
This commit is contained in:
@@ -32,7 +32,7 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await accessApprovalPolicyFindQuery(tx || db, {
|
const doc = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), {
|
||||||
[`${TableName.AccessApprovalPolicy}.id` as "id"]: id
|
[`${TableName.AccessApprovalPolicy}.id` as "id"]: id
|
||||||
});
|
});
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
const formatedDoc = mergeOneToManyRelation(
|
||||||
@@ -54,7 +54,7 @@ export const accessApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
const find = async (filter: TFindFilter<TAccessApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await accessApprovalPolicyFindQuery(tx || db, filter);
|
const docs = await accessApprovalPolicyFindQuery(tx || db.replicaNode(), filter);
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
const formatedDoc = mergeOneToManyRelation(
|
||||||
docs,
|
docs,
|
||||||
"id",
|
"id",
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findRequestsWithPrivilegeByPolicyIds = async (policyIds: string[]) => {
|
const findRequestsWithPrivilegeByPolicyIds = async (policyIds: string[]) => {
|
||||||
try {
|
try {
|
||||||
const docs = await db(TableName.AccessApprovalRequest)
|
const docs = await db
|
||||||
|
.replicaNode()(TableName.AccessApprovalRequest)
|
||||||
.whereIn(`${TableName.AccessApprovalRequest}.policyId`, policyIds)
|
.whereIn(`${TableName.AccessApprovalRequest}.policyId`, policyIds)
|
||||||
|
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
@@ -170,7 +171,7 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const sql = findQuery({ [`${TableName.AccessApprovalRequest}.id` as "id"]: id }, tx || db);
|
const sql = findQuery({ [`${TableName.AccessApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());
|
||||||
const docs = await sql;
|
const docs = await sql;
|
||||||
const formatedDoc = sqlNestRelationships({
|
const formatedDoc = sqlNestRelationships({
|
||||||
data: docs,
|
data: docs,
|
||||||
@@ -207,7 +208,8 @@ export const accessApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const getCount = async ({ projectId }: { projectId: string }) => {
|
const getCount = async ({ projectId }: { projectId: string }) => {
|
||||||
try {
|
try {
|
||||||
const accessRequests = await db(TableName.AccessApprovalRequest)
|
const accessRequests = await db
|
||||||
|
.replicaNode()(TableName.AccessApprovalRequest)
|
||||||
.leftJoin(
|
.leftJoin(
|
||||||
TableName.AccessApprovalPolicy,
|
TableName.AccessApprovalPolicy,
|
||||||
`${TableName.AccessApprovalRequest}.policyId`,
|
`${TableName.AccessApprovalRequest}.policyId`,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export const auditLogDALFactory = (db: TDbClient) => {
|
|||||||
tx?: Knex
|
tx?: Knex
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const sqlQuery = (tx || db)(TableName.AuditLog)
|
const sqlQuery = (tx || db.replicaNode())(TableName.AuditLog)
|
||||||
.where(
|
.where(
|
||||||
stripUndefinedInWhere({
|
stripUndefinedInWhere({
|
||||||
projectId,
|
projectId,
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ export const dynamicSecretLeaseDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const countLeasesForDynamicSecret = async (dynamicSecretId: string, tx?: Knex) => {
|
const countLeasesForDynamicSecret = async (dynamicSecretId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.DynamicSecretLease).count("*").where({ dynamicSecretId }).first();
|
const doc = await (tx || db.replicaNode())(TableName.DynamicSecretLease)
|
||||||
|
.count("*")
|
||||||
|
.where({ dynamicSecretId })
|
||||||
|
.first();
|
||||||
return parseInt(doc || "0", 10);
|
return parseInt(doc || "0", 10);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "DynamicSecretCountLeases" });
|
throw new DatabaseError({ error, name: "DynamicSecretCountLeases" });
|
||||||
@@ -21,7 +24,7 @@ export const dynamicSecretLeaseDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.DynamicSecretLease)
|
const doc = await (tx || db.replicaNode())(TableName.DynamicSecretLease)
|
||||||
.where({ [`${TableName.DynamicSecretLease}.id` as "id"]: id })
|
.where({ [`${TableName.DynamicSecretLease}.id` as "id"]: id })
|
||||||
.first()
|
.first()
|
||||||
.join(
|
.join(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findGroups = async (filter: TFindFilter<TGroups>, { offset, limit, sort, tx }: TFindOpt<TGroups> = {}) => {
|
const findGroups = async (filter: TFindFilter<TGroups>, { offset, limit, sort, tx }: TFindOpt<TGroups> = {}) => {
|
||||||
try {
|
try {
|
||||||
const query = (tx || db)(TableName.Groups)
|
const query = (tx || db.replicaNode())(TableName.Groups)
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
.where(buildFindFilter(filter))
|
.where(buildFindFilter(filter))
|
||||||
.select(selectAllTableCols(TableName.Groups));
|
.select(selectAllTableCols(TableName.Groups));
|
||||||
@@ -32,7 +32,7 @@ export const groupDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByOrgId = async (orgId: string, tx?: Knex) => {
|
const findByOrgId = async (orgId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.Groups)
|
const docs = await (tx || db.replicaNode())(TableName.Groups)
|
||||||
.where(`${TableName.Groups}.orgId`, orgId)
|
.where(`${TableName.Groups}.orgId`, orgId)
|
||||||
.leftJoin(TableName.OrgRoles, `${TableName.Groups}.roleId`, `${TableName.OrgRoles}.id`)
|
.leftJoin(TableName.OrgRoles, `${TableName.Groups}.roleId`, `${TableName.OrgRoles}.id`)
|
||||||
.select(selectAllTableCols(TableName.Groups))
|
.select(selectAllTableCols(TableName.Groups))
|
||||||
@@ -74,11 +74,12 @@ export const groupDALFactory = (db: TDbClient) => {
|
|||||||
username?: string;
|
username?: string;
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
let query = db(TableName.OrgMembership)
|
let query = db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin(TableName.UserGroupMembership, function () {
|
.leftJoin(TableName.UserGroupMembership, (bd) => {
|
||||||
this.on(`${TableName.UserGroupMembership}.userId`, "=", `${TableName.Users}.id`).andOn(
|
bd.on(`${TableName.UserGroupMembership}.userId`, "=", `${TableName.Users}.id`).andOn(
|
||||||
`${TableName.UserGroupMembership}.groupId`,
|
`${TableName.UserGroupMembership}.groupId`,
|
||||||
"=",
|
"=",
|
||||||
db.raw("?", [groupId])
|
db.raw("?", [groupId])
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export const userGroupMembershipDALFactory = (db: TDbClient) => {
|
|||||||
*/
|
*/
|
||||||
const filterProjectsByUserMembership = async (userId: string, groupId: string, projectIds: string[], tx?: Knex) => {
|
const filterProjectsByUserMembership = async (userId: string, groupId: string, projectIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const userProjectMemberships: string[] = await (tx || db)(TableName.ProjectMembership)
|
const userProjectMemberships: string[] = await (tx || db.replicaNode())(TableName.ProjectMembership)
|
||||||
.where(`${TableName.ProjectMembership}.userId`, userId)
|
.where(`${TableName.ProjectMembership}.userId`, userId)
|
||||||
.whereIn(`${TableName.ProjectMembership}.projectId`, projectIds)
|
.whereIn(`${TableName.ProjectMembership}.projectId`, projectIds)
|
||||||
.pluck(`${TableName.ProjectMembership}.projectId`);
|
.pluck(`${TableName.ProjectMembership}.projectId`);
|
||||||
@@ -43,7 +43,8 @@ export const userGroupMembershipDALFactory = (db: TDbClient) => {
|
|||||||
// special query
|
// special query
|
||||||
const findUserGroupMembershipsInProject = async (usernames: string[], projectId: string) => {
|
const findUserGroupMembershipsInProject = async (usernames: string[], projectId: string) => {
|
||||||
try {
|
try {
|
||||||
const usernameDocs: string[] = await db(TableName.UserGroupMembership)
|
const usernameDocs: string[] = await db
|
||||||
|
.replicaNode()(TableName.UserGroupMembership)
|
||||||
.join(
|
.join(
|
||||||
TableName.GroupProjectMembership,
|
TableName.GroupProjectMembership,
|
||||||
`${TableName.UserGroupMembership}.groupId`,
|
`${TableName.UserGroupMembership}.groupId`,
|
||||||
@@ -73,7 +74,7 @@ export const userGroupMembershipDALFactory = (db: TDbClient) => {
|
|||||||
try {
|
try {
|
||||||
// get list of groups in the project with id [projectId]
|
// get list of groups in the project with id [projectId]
|
||||||
// that that are not the group with id [groupId]
|
// that that are not the group with id [groupId]
|
||||||
const groups: string[] = await (tx || db)(TableName.GroupProjectMembership)
|
const groups: string[] = await (tx || db.replicaNode())(TableName.GroupProjectMembership)
|
||||||
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
||||||
.whereNot(`${TableName.GroupProjectMembership}.groupId`, groupId)
|
.whereNot(`${TableName.GroupProjectMembership}.groupId`, groupId)
|
||||||
.pluck(`${TableName.GroupProjectMembership}.groupId`);
|
.pluck(`${TableName.GroupProjectMembership}.groupId`);
|
||||||
@@ -83,8 +84,8 @@ export const userGroupMembershipDALFactory = (db: TDbClient) => {
|
|||||||
.where(`${TableName.UserGroupMembership}.groupId`, groupId)
|
.where(`${TableName.UserGroupMembership}.groupId`, groupId)
|
||||||
.where(`${TableName.UserGroupMembership}.isPending`, false)
|
.where(`${TableName.UserGroupMembership}.isPending`, false)
|
||||||
.join(TableName.Users, `${TableName.UserGroupMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.UserGroupMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin(TableName.ProjectMembership, function () {
|
.leftJoin(TableName.ProjectMembership, (bd) => {
|
||||||
this.on(`${TableName.Users}.id`, "=", `${TableName.ProjectMembership}.userId`).andOn(
|
bd.on(`${TableName.Users}.id`, "=", `${TableName.ProjectMembership}.userId`).andOn(
|
||||||
`${TableName.ProjectMembership}.projectId`,
|
`${TableName.ProjectMembership}.projectId`,
|
||||||
"=",
|
"=",
|
||||||
db.raw("?", [projectId])
|
db.raw("?", [projectId])
|
||||||
@@ -107,9 +108,9 @@ export const userGroupMembershipDALFactory = (db: TDbClient) => {
|
|||||||
db.ref("publicKey").withSchema(TableName.UserEncryptionKey)
|
db.ref("publicKey").withSchema(TableName.UserEncryptionKey)
|
||||||
)
|
)
|
||||||
.where({ isGhost: false }) // MAKE SURE USER IS NOT A GHOST USER
|
.where({ isGhost: false }) // MAKE SURE USER IS NOT A GHOST USER
|
||||||
.whereNotIn(`${TableName.UserGroupMembership}.userId`, function () {
|
.whereNotIn(`${TableName.UserGroupMembership}.userId`, (bd) => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
this.select(`${TableName.UserGroupMembership}.userId`)
|
bd.select(`${TableName.UserGroupMembership}.userId`)
|
||||||
.from(TableName.UserGroupMembership)
|
.from(TableName.UserGroupMembership)
|
||||||
.whereIn(`${TableName.UserGroupMembership}.groupId`, groups);
|
.whereIn(`${TableName.UserGroupMembership}.groupId`, groups);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ export const ldapGroupMapDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findLdapGroupMapsByLdapConfigId = async (ldapConfigId: string) => {
|
const findLdapGroupMapsByLdapConfigId = async (ldapConfigId: string) => {
|
||||||
try {
|
try {
|
||||||
const docs = await db(TableName.LdapGroupMap)
|
const docs = await db
|
||||||
|
.replicaNode()(TableName.LdapGroupMap)
|
||||||
.where(`${TableName.LdapGroupMap}.ldapConfigId`, ldapConfigId)
|
.where(`${TableName.LdapGroupMap}.ldapConfigId`, ldapConfigId)
|
||||||
.join(TableName.Groups, `${TableName.LdapGroupMap}.groupId`, `${TableName.Groups}.id`)
|
.join(TableName.Groups, `${TableName.LdapGroupMap}.groupId`, `${TableName.Groups}.id`)
|
||||||
.select(selectAllTableCols(TableName.LdapGroupMap))
|
.select(selectAllTableCols(TableName.LdapGroupMap))
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export type TLicenseDALFactory = ReturnType<typeof licenseDALFactory>;
|
|||||||
export const licenseDALFactory = (db: TDbClient) => {
|
export const licenseDALFactory = (db: TDbClient) => {
|
||||||
const countOfOrgMembers = async (orgId: string | null, tx?: Knex) => {
|
const countOfOrgMembers = async (orgId: string | null, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.OrgMembership)
|
const doc = await (tx || db.replicaNode())(TableName.OrgMembership)
|
||||||
.where({ status: OrgMembershipStatus.Accepted })
|
.where({ status: OrgMembershipStatus.Accepted })
|
||||||
.andWhere((bd) => {
|
.andWhere((bd) => {
|
||||||
if (orgId) {
|
if (orgId) {
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ export type TPermissionDALFactory = ReturnType<typeof permissionDALFactory>;
|
|||||||
export const permissionDALFactory = (db: TDbClient) => {
|
export const permissionDALFactory = (db: TDbClient) => {
|
||||||
const getOrgPermission = async (userId: string, orgId: string) => {
|
const getOrgPermission = async (userId: string, orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const membership = await db(TableName.OrgMembership)
|
const membership = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.leftJoin(TableName.OrgRoles, `${TableName.OrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
.leftJoin(TableName.OrgRoles, `${TableName.OrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
||||||
.join(TableName.Organization, `${TableName.OrgMembership}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.OrgMembership}.orgId`, `${TableName.Organization}.id`)
|
||||||
.where("userId", userId)
|
.where("userId", userId)
|
||||||
@@ -28,7 +29,8 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const getOrgIdentityPermission = async (identityId: string, orgId: string) => {
|
const getOrgIdentityPermission = async (identityId: string, orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const membership = await db(TableName.IdentityOrgMembership)
|
const membership = await db
|
||||||
|
.replicaNode()(TableName.IdentityOrgMembership)
|
||||||
.leftJoin(TableName.OrgRoles, `${TableName.IdentityOrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
.leftJoin(TableName.OrgRoles, `${TableName.IdentityOrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
||||||
.join(TableName.Organization, `${TableName.IdentityOrgMembership}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.IdentityOrgMembership}.orgId`, `${TableName.Organization}.id`)
|
||||||
.where("identityId", identityId)
|
.where("identityId", identityId)
|
||||||
@@ -45,11 +47,13 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const getProjectPermission = async (userId: string, projectId: string) => {
|
const getProjectPermission = async (userId: string, projectId: string) => {
|
||||||
try {
|
try {
|
||||||
const groups: string[] = await db(TableName.GroupProjectMembership)
|
const groups: string[] = await db
|
||||||
|
.replicaNode()(TableName.GroupProjectMembership)
|
||||||
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
||||||
.pluck(`${TableName.GroupProjectMembership}.groupId`);
|
.pluck(`${TableName.GroupProjectMembership}.groupId`);
|
||||||
|
|
||||||
const groupDocs = await db(TableName.UserGroupMembership)
|
const groupDocs = await db
|
||||||
|
.replicaNode()(TableName.UserGroupMembership)
|
||||||
.where(`${TableName.UserGroupMembership}.userId`, userId)
|
.where(`${TableName.UserGroupMembership}.userId`, userId)
|
||||||
.whereIn(`${TableName.UserGroupMembership}.groupId`, groups)
|
.whereIn(`${TableName.UserGroupMembership}.groupId`, groups)
|
||||||
.join(
|
.join(
|
||||||
@@ -231,7 +235,8 @@ export const permissionDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const getProjectIdentityPermission = async (identityId: string, projectId: string) => {
|
const getProjectIdentityPermission = async (identityId: string, projectId: string) => {
|
||||||
try {
|
try {
|
||||||
const docs = await db(TableName.IdentityProjectMembership)
|
const docs = await db
|
||||||
|
.replicaNode()(TableName.IdentityProjectMembership)
|
||||||
.join(
|
.join(
|
||||||
TableName.IdentityProjectMembershipRole,
|
TableName.IdentityProjectMembershipRole,
|
||||||
`${TableName.IdentityProjectMembershipRole}.projectMembershipId`,
|
`${TableName.IdentityProjectMembershipRole}.projectMembershipId`,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ export const samlConfigDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findEnforceableSamlCfg = async (orgId: string) => {
|
const findEnforceableSamlCfg = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const samlCfg = await db(TableName.SamlConfig)
|
const samlCfg = await db
|
||||||
|
.replicaNode()(TableName.SamlConfig)
|
||||||
.where({
|
.where({
|
||||||
orgId,
|
orgId,
|
||||||
isActive: true
|
isActive: true
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await sapFindQuery(tx || db, {
|
const doc = await sapFindQuery(tx || db.replicaNode(), {
|
||||||
[`${TableName.SecretApprovalPolicy}.id` as "id"]: id
|
[`${TableName.SecretApprovalPolicy}.id` as "id"]: id
|
||||||
});
|
});
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
const formatedDoc = mergeOneToManyRelation(
|
||||||
@@ -52,7 +52,7 @@ export const secretApprovalPolicyDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
const find = async (filter: TFindFilter<TSecretApprovalPolicies & { projectId: string }>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await sapFindQuery(tx || db, filter);
|
const docs = await sapFindQuery(tx || db.replicaNode(), filter);
|
||||||
const formatedDoc = mergeOneToManyRelation(
|
const formatedDoc = mergeOneToManyRelation(
|
||||||
docs,
|
docs,
|
||||||
"id",
|
"id",
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const sql = findQuery({ [`${TableName.SecretApprovalRequest}.id` as "id"]: id }, tx || db);
|
const sql = findQuery({ [`${TableName.SecretApprovalRequest}.id` as "id"]: id }, tx || db.replicaNode());
|
||||||
const docs = await sql;
|
const docs = await sql;
|
||||||
const formatedDoc = sqlNestRelationships({
|
const formatedDoc = sqlNestRelationships({
|
||||||
data: docs,
|
data: docs,
|
||||||
@@ -102,7 +102,7 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
const docs = await (tx || db)
|
const docs = await (tx || db)
|
||||||
.with(
|
.with(
|
||||||
"temp",
|
"temp",
|
||||||
(tx || db)(TableName.SecretApprovalRequest)
|
(tx || db.replicaNode())(TableName.SecretApprovalRequest)
|
||||||
.join(TableName.SecretFolder, `${TableName.SecretApprovalRequest}.folderId`, `${TableName.SecretFolder}.id`)
|
.join(TableName.SecretFolder, `${TableName.SecretApprovalRequest}.folderId`, `${TableName.SecretFolder}.id`)
|
||||||
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
||||||
.join(
|
.join(
|
||||||
@@ -148,7 +148,7 @@ export const secretApprovalRequestDALFactory = (db: TDbClient) => {
|
|||||||
try {
|
try {
|
||||||
// akhilmhdh: If ever u wanted a 1 to so many relationship connected with pagination
|
// akhilmhdh: If ever u wanted a 1 to so many relationship connected with pagination
|
||||||
// this is the place u wanna look at.
|
// this is the place u wanna look at.
|
||||||
const query = (tx || db)(TableName.SecretApprovalRequest)
|
const query = (tx || db.replicaNode())(TableName.SecretApprovalRequest)
|
||||||
.join(TableName.SecretFolder, `${TableName.SecretApprovalRequest}.folderId`, `${TableName.SecretFolder}.id`)
|
.join(TableName.SecretFolder, `${TableName.SecretApprovalRequest}.folderId`, `${TableName.SecretFolder}.id`)
|
||||||
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
||||||
.join(
|
.join(
|
||||||
|
|||||||
+1
-1
@@ -47,7 +47,7 @@ export const secretApprovalRequestSecretDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByRequestId = async (requestId: string, tx?: Knex) => {
|
const findByRequestId = async (requestId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)({
|
const doc = await (tx || db.replicaNode())({
|
||||||
secVerTag: TableName.SecretTag
|
secVerTag: TableName.SecretTag
|
||||||
})
|
})
|
||||||
.from(TableName.SecretApprovalRequestSecret)
|
.from(TableName.SecretApprovalRequestSecret)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export const secretRotationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: TFindFilter<TSecretRotations & { projectId: string }>, tx?: Knex) => {
|
const find = async (filter: TFindFilter<TSecretRotations & { projectId: string }>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const data = await findQuery(filter, tx || db);
|
const data = await findQuery(filter, tx || db.replicaNode());
|
||||||
return sqlNestRelationships({
|
return sqlNestRelationships({
|
||||||
data,
|
data,
|
||||||
key: "id",
|
key: "id",
|
||||||
@@ -93,7 +93,7 @@ export const secretRotationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.SecretRotation)
|
const doc = await (tx || db.replicaNode())(TableName.SecretRotation)
|
||||||
.join(TableName.Environment, `${TableName.SecretRotation}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretRotation}.envId`, `${TableName.Environment}.id`)
|
||||||
.where({ [`${TableName.SecretRotation}.id` as "id"]: id })
|
.where({ [`${TableName.SecretRotation}.id` as "id"]: id })
|
||||||
.select(selectAllTableCols(TableName.SecretRotation))
|
.select(selectAllTableCols(TableName.SecretRotation))
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const data = await (tx || db)(TableName.Snapshot)
|
const data = await (tx || db.replicaNode())(TableName.Snapshot)
|
||||||
.where(`${TableName.Snapshot}.id`, id)
|
.where(`${TableName.Snapshot}.id`, id)
|
||||||
.join(TableName.Environment, `${TableName.Snapshot}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.Snapshot}.envId`, `${TableName.Environment}.id`)
|
||||||
.select(selectAllTableCols(TableName.Snapshot))
|
.select(selectAllTableCols(TableName.Snapshot))
|
||||||
@@ -43,7 +43,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const countOfSnapshotsByFolderId = async (folderId: string, tx?: Knex) => {
|
const countOfSnapshotsByFolderId = async (folderId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.Snapshot)
|
const doc = await (tx || db.replicaNode())(TableName.Snapshot)
|
||||||
.where({ folderId })
|
.where({ folderId })
|
||||||
.groupBy(["folderId"])
|
.groupBy(["folderId"])
|
||||||
.count("folderId")
|
.count("folderId")
|
||||||
@@ -56,7 +56,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findSecretSnapshotDataById = async (snapshotId: string, tx?: Knex) => {
|
const findSecretSnapshotDataById = async (snapshotId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const data = await (tx || db)(TableName.Snapshot)
|
const data = await (tx || db.replicaNode())(TableName.Snapshot)
|
||||||
.where(`${TableName.Snapshot}.id`, snapshotId)
|
.where(`${TableName.Snapshot}.id`, snapshotId)
|
||||||
.join(TableName.Environment, `${TableName.Snapshot}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.Snapshot}.envId`, `${TableName.Environment}.id`)
|
||||||
.leftJoin(TableName.SnapshotSecret, `${TableName.Snapshot}.id`, `${TableName.SnapshotSecret}.snapshotId`)
|
.leftJoin(TableName.SnapshotSecret, `${TableName.Snapshot}.id`, `${TableName.SnapshotSecret}.snapshotId`)
|
||||||
@@ -309,7 +309,7 @@ export const snapshotDALFactory = (db: TDbClient) => {
|
|||||||
// when we need to rollback we will pull from these snapshots
|
// when we need to rollback we will pull from these snapshots
|
||||||
const findLatestSnapshotByFolderId = async (folderId: string, tx?: Knex) => {
|
const findLatestSnapshotByFolderId = async (folderId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.Snapshot)
|
const docs = await (tx || db.replicaNode())(TableName.Snapshot)
|
||||||
.where(`${TableName.Snapshot}.folderId`, folderId)
|
.where(`${TableName.Snapshot}.folderId`, folderId)
|
||||||
.join<TSecretSnapshots>(
|
.join<TSecretSnapshots>(
|
||||||
(tx || db)(TableName.Snapshot).groupBy("folderId").max("createdAt").select("folderId").as("latestVersion"),
|
(tx || db)(TableName.Snapshot).groupBy("folderId").max("createdAt").select("folderId").as("latestVersion"),
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(db: Kne
|
|||||||
}),
|
}),
|
||||||
findById: async (id: string, tx?: Knex) => {
|
findById: async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const result = await (tx || db)(tableName)
|
const result = await (tx || db.replicaNode())(tableName)
|
||||||
.where({ id } as never)
|
.where({ id } as never)
|
||||||
.first("*");
|
.first("*");
|
||||||
return result;
|
return result;
|
||||||
@@ -60,7 +60,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(db: Kne
|
|||||||
},
|
},
|
||||||
findOne: async (filter: Partial<Tables[Tname]["base"]>, tx?: Knex) => {
|
findOne: async (filter: Partial<Tables[Tname]["base"]>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const res = await (tx || db)(tableName).where(filter).first("*");
|
const res = await (tx || db.replicaNode())(tableName).where(filter).first("*");
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find one" });
|
throw new DatabaseError({ error, name: "Find one" });
|
||||||
@@ -71,7 +71,7 @@ export const ormify = <DbOps extends object, Tname extends keyof Tables>(db: Kne
|
|||||||
{ offset, limit, sort, tx }: TFindOpt<Tables[Tname]["base"]> = {}
|
{ offset, limit, sort, tx }: TFindOpt<Tables[Tname]["base"]> = {}
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const query = (tx || db)(tableName).where(buildFindFilter(filter));
|
const query = (tx || db.replicaNode())(tableName).where(buildFindFilter(filter));
|
||||||
if (limit) void query.limit(limit);
|
if (limit) void query.limit(limit);
|
||||||
if (offset) void query.offset(offset);
|
if (offset) void query.offset(offset);
|
||||||
if (sort) {
|
if (sort) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const tokenDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOneTokenSession = async (filter: Partial<TAuthTokenSessions>): Promise<TAuthTokenSessions | undefined> => {
|
const findOneTokenSession = async (filter: Partial<TAuthTokenSessions>): Promise<TAuthTokenSessions | undefined> => {
|
||||||
try {
|
try {
|
||||||
const doc = await db(TableName.AuthTokenSession).where(filter).first();
|
const doc = await db.replicaNode()(TableName.AuthTokenSession).where(filter).first();
|
||||||
return doc;
|
return doc;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "FindOneTokenSession" });
|
throw new DatabaseError({ error, name: "FindOneTokenSession" });
|
||||||
@@ -44,7 +44,7 @@ export const tokenDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findTokenSessions = async (filter: Partial<TAuthTokenSessions>, tx?: Knex) => {
|
const findTokenSessions = async (filter: Partial<TAuthTokenSessions>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const sessions = await (tx || db)(TableName.AuthTokenSession).where(filter);
|
const sessions = await (tx || db.replicaNode())(TableName.AuthTokenSession).where(filter);
|
||||||
return sessions;
|
return sessions;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ name: "Find all token session", error });
|
throw new DatabaseError({ name: "Find all token session", error });
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const certificateAuthorityDALFactory = (db: TDbClient) => {
|
|||||||
parentCaId?: string;
|
parentCaId?: string;
|
||||||
encryptedCertificate: Buffer;
|
encryptedCertificate: Buffer;
|
||||||
}[] = await db
|
}[] = await db
|
||||||
|
.replicaNode()
|
||||||
.withRecursive("cte", (cte) => {
|
.withRecursive("cte", (cte) => {
|
||||||
void cte
|
void cte
|
||||||
.select("ca.id as caId", "ca.parentCaId", "cert.encryptedCertificate")
|
.select("ca.id as caId", "ca.parentCaId", "cert.encryptedCertificate")
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export const certificateDALFactory = (db: TDbClient) => {
|
|||||||
count: string;
|
count: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await db(TableName.Certificate)
|
const count = await db
|
||||||
|
.replicaNode()(TableName.Certificate)
|
||||||
.join(TableName.CertificateAuthority, `${TableName.Certificate}.caId`, `${TableName.CertificateAuthority}.id`)
|
.join(TableName.CertificateAuthority, `${TableName.Certificate}.caId`, `${TableName.CertificateAuthority}.id`)
|
||||||
.join(TableName.Project, `${TableName.CertificateAuthority}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.CertificateAuthority}.projectId`, `${TableName.Project}.id`)
|
||||||
.where(`${TableName.Project}.id`, projectId)
|
.where(`${TableName.Project}.id`, projectId)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const groupProjectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByProjectId = async (projectId: string, tx?: Knex) => {
|
const findByProjectId = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.GroupProjectMembership)
|
const docs = await (tx || db.replicaNode())(TableName.GroupProjectMembership)
|
||||||
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
.where(`${TableName.GroupProjectMembership}.projectId`, projectId)
|
||||||
.join(TableName.Groups, `${TableName.GroupProjectMembership}.groupId`, `${TableName.Groups}.id`)
|
.join(TableName.Groups, `${TableName.GroupProjectMembership}.groupId`, `${TableName.Groups}.id`)
|
||||||
.join(
|
.join(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const identityAccessTokenDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (filter: Partial<TIdentityAccessTokens>, tx?: Knex) => {
|
const findOne = async (filter: Partial<TIdentityAccessTokens>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.IdentityAccessToken)
|
const doc = await (tx || db.replicaNode())(TableName.IdentityAccessToken)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.IdentityAccessToken}.identityId`)
|
.join(TableName.Identity, `${TableName.Identity}.id`, `${TableName.IdentityAccessToken}.identityId`)
|
||||||
.leftJoin(TableName.IdentityUaClientSecret, (qb) => {
|
.leftJoin(TableName.IdentityUaClientSecret, (qb) => {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByProjectId = async (projectId: string, filter: { identityId?: string } = {}, tx?: Knex) => {
|
const findByProjectId = async (projectId: string, filter: { identityId?: string } = {}, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.IdentityProjectMembership)
|
const docs = await (tx || db.replicaNode())(TableName.IdentityProjectMembership)
|
||||||
.where(`${TableName.IdentityProjectMembership}.projectId`, projectId)
|
.where(`${TableName.IdentityProjectMembership}.projectId`, projectId)
|
||||||
.join(TableName.Identity, `${TableName.IdentityProjectMembership}.identityId`, `${TableName.Identity}.id`)
|
.join(TableName.Identity, `${TableName.IdentityProjectMembership}.identityId`, `${TableName.Identity}.id`)
|
||||||
.where((qb) => {
|
.where((qb) => {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (filter: Partial<TIdentityOrgMemberships>, tx?: Knex) => {
|
const findOne = async (filter: Partial<TIdentityOrgMemberships>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const [data] = await (tx || db)(TableName.IdentityOrgMembership)
|
const [data] = await (tx || db.replicaNode())(TableName.IdentityOrgMembership)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`)
|
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`)
|
||||||
.select(selectAllTableCols(TableName.IdentityOrgMembership))
|
.select(selectAllTableCols(TableName.IdentityOrgMembership))
|
||||||
@@ -29,7 +29,7 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: Partial<TIdentityOrgMemberships>, tx?: Knex) => {
|
const find = async (filter: Partial<TIdentityOrgMemberships>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.IdentityOrgMembership)
|
const docs = await (tx || db.replicaNode())(TableName.IdentityOrgMembership)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`)
|
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`)
|
||||||
.leftJoin(TableName.OrgRoles, `${TableName.IdentityOrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
.leftJoin(TableName.OrgRoles, `${TableName.IdentityOrgMembership}.roleId`, `${TableName.OrgRoles}.id`)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const integrationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: Partial<TIntegrations>, tx?: Knex) => {
|
const find = async (filter: Partial<TIntegrations>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await integrationFindQuery(tx || db, filter);
|
const docs = await integrationFindQuery(tx || db.replicaNode(), filter);
|
||||||
return docs.map(({ envId, envSlug, envName, ...el }) => ({
|
return docs.map(({ envId, envSlug, envName, ...el }) => ({
|
||||||
...el,
|
...el,
|
||||||
environment: {
|
environment: {
|
||||||
@@ -38,7 +38,7 @@ export const integrationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (filter: Partial<TIntegrations>, tx?: Knex) => {
|
const findOne = async (filter: Partial<TIntegrations>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await integrationFindQuery(tx || db, filter).first();
|
const doc = await integrationFindQuery(tx || db.replicaNode(), filter).first();
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
|
|
||||||
const { envName: name, envSlug: slug, envId: id, ...el } = doc;
|
const { envName: name, envSlug: slug, envId: id, ...el } = doc;
|
||||||
@@ -50,7 +50,7 @@ export const integrationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await integrationFindQuery(tx || db, {
|
const doc = await integrationFindQuery(tx || db.replicaNode(), {
|
||||||
[`${TableName.Integration}.id` as "id"]: id
|
[`${TableName.Integration}.id` as "id"]: id
|
||||||
}).first();
|
}).first();
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
@@ -64,7 +64,7 @@ export const integrationDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByProjectId = async (projectId: string, tx?: Knex) => {
|
const findByProjectId = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const integrations = await (tx || db)(TableName.Integration)
|
const integrations = await (tx || db.replicaNode())(TableName.Integration)
|
||||||
.where(`${TableName.Environment}.projectId`, projectId)
|
.where(`${TableName.Environment}.projectId`, projectId)
|
||||||
.join(TableName.Environment, `${TableName.Integration}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.Integration}.envId`, `${TableName.Environment}.id`)
|
||||||
.select(db.ref("name").withSchema(TableName.Environment).as("envName"))
|
.select(db.ref("name").withSchema(TableName.Environment).as("envName"))
|
||||||
@@ -90,7 +90,7 @@ export const integrationDALFactory = (db: TDbClient) => {
|
|||||||
// used for syncing secrets
|
// used for syncing secrets
|
||||||
// this will populate integration auth also
|
// this will populate integration auth also
|
||||||
const findByProjectIdV2 = async (projectId: string, environment: string, tx?: Knex) => {
|
const findByProjectIdV2 = async (projectId: string, environment: string, tx?: Knex) => {
|
||||||
const docs = await (tx || db)(TableName.Integration)
|
const docs = await (tx || db.replicaNode())(TableName.Integration)
|
||||||
.where(`${TableName.Environment}.projectId`, projectId)
|
.where(`${TableName.Environment}.projectId`, projectId)
|
||||||
.where("isActive", true)
|
.where("isActive", true)
|
||||||
.where(`${TableName.Environment}.slug`, environment)
|
.where(`${TableName.Environment}.slug`, environment)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const incidentContactDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByOrgId = async (orgId: string) => {
|
const findByOrgId = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const incidentContacts = await db(TableName.IncidentContact).where({ orgId });
|
const incidentContacts = await db.replicaNode()(TableName.IncidentContact).where({ orgId });
|
||||||
return incidentContacts;
|
return incidentContacts;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ name: "Incident contact list", error });
|
throw new DatabaseError({ name: "Incident contact list", error });
|
||||||
@@ -25,7 +25,8 @@ export const incidentContactDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (orgId: string, data: Partial<TIncidentContacts>) => {
|
const findOne = async (orgId: string, data: Partial<TIncidentContacts>) => {
|
||||||
try {
|
try {
|
||||||
const incidentContacts = await db(TableName.IncidentContact)
|
const incidentContacts = await db
|
||||||
|
.replicaNode()(TableName.IncidentContact)
|
||||||
.where({ orgId, ...data })
|
.where({ orgId, ...data })
|
||||||
.first();
|
.first();
|
||||||
return incidentContacts;
|
return incidentContacts;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOrgById = async (orgId: string) => {
|
const findOrgById = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const org = await db(TableName.Organization).where({ id: orgId }).first();
|
const org = await db.replicaNode()(TableName.Organization).where({ id: orgId }).first();
|
||||||
return org;
|
return org;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find org by id" });
|
throw new DatabaseError({ error, name: "Find org by id" });
|
||||||
@@ -30,7 +30,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
// special query
|
// special query
|
||||||
const findAllOrgsByUserId = async (userId: string): Promise<TOrganizations[]> => {
|
const findAllOrgsByUserId = async (userId: string): Promise<TOrganizations[]> => {
|
||||||
try {
|
try {
|
||||||
const org = await db(TableName.OrgMembership)
|
const org = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where({ userId })
|
.where({ userId })
|
||||||
.join(TableName.Organization, `${TableName.OrgMembership}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.OrgMembership}.orgId`, `${TableName.Organization}.id`)
|
||||||
.select(selectAllTableCols(TableName.Organization));
|
.select(selectAllTableCols(TableName.Organization));
|
||||||
@@ -42,7 +43,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOrgByProjectId = async (projectId: string): Promise<TOrganizations> => {
|
const findOrgByProjectId = async (projectId: string): Promise<TOrganizations> => {
|
||||||
try {
|
try {
|
||||||
const [org] = await db(TableName.Project)
|
const [org] = await db
|
||||||
|
.replicaNode()(TableName.Project)
|
||||||
.where({ [`${TableName.Project}.id` as "id"]: projectId })
|
.where({ [`${TableName.Project}.id` as "id"]: projectId })
|
||||||
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
.join(TableName.Organization, `${TableName.Project}.orgId`, `${TableName.Organization}.id`)
|
||||||
.select(selectAllTableCols(TableName.Organization));
|
.select(selectAllTableCols(TableName.Organization));
|
||||||
@@ -56,7 +58,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
// special query
|
// special query
|
||||||
const findAllOrgMembers = async (orgId: string) => {
|
const findAllOrgMembers = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const members = await db(TableName.OrgMembership)
|
const members = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin<TUserEncryptionKeys>(
|
.leftJoin<TUserEncryptionKeys>(
|
||||||
@@ -95,7 +98,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
count: string;
|
count: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await db(TableName.OrgMembership)
|
const count = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
||||||
.count("*")
|
.count("*")
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
@@ -110,7 +114,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOrgMembersByUsername = async (orgId: string, usernames: string[]) => {
|
const findOrgMembersByUsername = async (orgId: string, usernames: string[]) => {
|
||||||
try {
|
try {
|
||||||
const members = await db(TableName.OrgMembership)
|
const members = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
.where(`${TableName.OrgMembership}.orgId`, orgId)
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin<TUserEncryptionKeys>(
|
.leftJoin<TUserEncryptionKeys>(
|
||||||
@@ -145,7 +150,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOrgGhostUser = async (orgId: string) => {
|
const findOrgGhostUser = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const member = await db(TableName.OrgMembership)
|
const member = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where({ orgId })
|
.where({ orgId })
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
||||||
@@ -169,7 +175,8 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const ghostUserExists = async (orgId: string) => {
|
const ghostUserExists = async (orgId: string) => {
|
||||||
try {
|
try {
|
||||||
const member = await db(TableName.OrgMembership)
|
const member = await db
|
||||||
|
.replicaNode()(TableName.OrgMembership)
|
||||||
.where({ orgId })
|
.where({ orgId })
|
||||||
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
||||||
@@ -257,7 +264,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
|||||||
{ offset, limit, sort, tx }: TFindOpt<TOrgMemberships> = {}
|
{ offset, limit, sort, tx }: TFindOpt<TOrgMemberships> = {}
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const query = (tx || db)(TableName.OrgMembership)
|
const query = (tx || db.replicaNode())(TableName.OrgMembership)
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
.where(buildFindFilter(filter))
|
.where(buildFindFilter(filter))
|
||||||
.join(TableName.Users, `${TableName.Users}.id`, `${TableName.OrgMembership}.userId`)
|
.join(TableName.Users, `${TableName.Users}.id`, `${TableName.OrgMembership}.userId`)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const projectBotDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (filter: Partial<TProjectBots>, tx?: Knex) => {
|
const findOne = async (filter: Partial<TProjectBots>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const bot = await (tx || db)(TableName.ProjectBot)
|
const bot = await (tx || db.replicaNode())(TableName.ProjectBot)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.leftJoin(TableName.Users, `${TableName.ProjectBot}.senderId`, `${TableName.Users}.id`)
|
.leftJoin(TableName.Users, `${TableName.ProjectBot}.senderId`, `${TableName.Users}.id`)
|
||||||
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
.leftJoin(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ export const projectEnvDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findBySlugs = async (projectId: string, env: string[], tx?: Knex) => {
|
const findBySlugs = async (projectId: string, env: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const envs = await (tx || db)(TableName.Environment).where("projectId", projectId).whereIn("slug", env);
|
const envs = await (tx || db.replicaNode())(TableName.Environment)
|
||||||
|
.where("projectId", projectId)
|
||||||
|
.whereIn("slug", env);
|
||||||
return envs;
|
return envs;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find by slugs" });
|
throw new DatabaseError({ error, name: "Find by slugs" });
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const projectKeyDALFactory = (db: TDbClient) => {
|
|||||||
tx?: Knex
|
tx?: Knex
|
||||||
): Promise<(TProjectKeys & { sender: { publicKey: string } }) | undefined> => {
|
): Promise<(TProjectKeys & { sender: { publicKey: string } }) | undefined> => {
|
||||||
try {
|
try {
|
||||||
const projectKey = await (tx || db)(TableName.ProjectKeys)
|
const projectKey = await (tx || db.replicaNode())(TableName.ProjectKeys)
|
||||||
.join(TableName.Users, `${TableName.ProjectKeys}.senderId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectKeys}.senderId`, `${TableName.Users}.id`)
|
||||||
.join(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
.join(TableName.UserEncryptionKey, `${TableName.UserEncryptionKey}.userId`, `${TableName.Users}.id`)
|
||||||
.where({ projectId, receiverId: userId })
|
.where({ projectId, receiverId: userId })
|
||||||
@@ -34,7 +34,7 @@ export const projectKeyDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findAllProjectUserPubKeys = async (projectId: string, tx?: Knex) => {
|
const findAllProjectUserPubKeys = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const pubKeys = await (tx || db)(TableName.ProjectMembership)
|
const pubKeys = await (tx || db.replicaNode())(TableName.ProjectMembership)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
|
|||||||
// special query
|
// special query
|
||||||
const findAllProjectMembers = async (projectId: string, filter: { usernames?: string[]; username?: string } = {}) => {
|
const findAllProjectMembers = async (projectId: string, filter: { usernames?: string[]; username?: string } = {}) => {
|
||||||
try {
|
try {
|
||||||
const docs = await db(TableName.ProjectMembership)
|
const docs = await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.where({ [`${TableName.ProjectMembership}.projectId` as "projectId"]: projectId })
|
.where({ [`${TableName.ProjectMembership}.projectId` as "projectId"]: projectId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.where((qb) => {
|
.where((qb) => {
|
||||||
@@ -108,7 +109,7 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findProjectGhostUser = async (projectId: string, tx?: Knex) => {
|
const findProjectGhostUser = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const ghostUser = await (tx || db)(TableName.ProjectMembership)
|
const ghostUser = await (tx || db.replicaNode())(TableName.ProjectMembership)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.select(selectAllTableCols(TableName.Users))
|
.select(selectAllTableCols(TableName.Users))
|
||||||
@@ -123,7 +124,8 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findMembershipsByUsername = async (projectId: string, usernames: string[]) => {
|
const findMembershipsByUsername = async (projectId: string, usernames: string[]) => {
|
||||||
try {
|
try {
|
||||||
const members = await db(TableName.ProjectMembership)
|
const members = await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.join<TUserEncryptionKeys>(
|
.join<TUserEncryptionKeys>(
|
||||||
@@ -149,7 +151,8 @@ export const projectMembershipDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findProjectMembershipsByUserId = async (orgId: string, userId: string) => {
|
const findProjectMembershipsByUserId = async (orgId: string, userId: string) => {
|
||||||
try {
|
try {
|
||||||
const memberships = await db(TableName.ProjectMembership)
|
const memberships = await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.where({ userId })
|
.where({ userId })
|
||||||
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
.where({ [`${TableName.Project}.orgId` as "orgId"]: orgId })
|
.where({ [`${TableName.Project}.orgId` as "orgId"]: orgId })
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findAllProjects = async (userId: string) => {
|
const findAllProjects = async (userId: string) => {
|
||||||
try {
|
try {
|
||||||
const workspaces = await db(TableName.ProjectMembership)
|
const workspaces = await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.where({ userId })
|
.where({ userId })
|
||||||
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.ProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
||||||
@@ -83,7 +84,7 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findProjectGhostUser = async (projectId: string, tx?: Knex) => {
|
const findProjectGhostUser = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const ghostUser = await (tx || db)(TableName.ProjectMembership)
|
const ghostUser = await (tx || db.replicaNode())(TableName.ProjectMembership)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.select(selectAllTableCols(TableName.Users))
|
.select(selectAllTableCols(TableName.Users))
|
||||||
@@ -109,7 +110,8 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findAllProjectsByIdentity = async (identityId: string) => {
|
const findAllProjectsByIdentity = async (identityId: string) => {
|
||||||
try {
|
try {
|
||||||
const workspaces = await db(TableName.IdentityProjectMembership)
|
const workspaces = await db
|
||||||
|
.replicaNode()(TableName.IdentityProjectMembership)
|
||||||
.where({ identityId })
|
.where({ identityId })
|
||||||
.join(TableName.Project, `${TableName.IdentityProjectMembership}.projectId`, `${TableName.Project}.id`)
|
.join(TableName.Project, `${TableName.IdentityProjectMembership}.projectId`, `${TableName.Project}.id`)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
||||||
@@ -151,7 +153,8 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findProjectById = async (id: string) => {
|
const findProjectById = async (id: string) => {
|
||||||
try {
|
try {
|
||||||
const workspaces = await db(TableName.Project)
|
const workspaces = await db
|
||||||
|
.replicaNode()(TableName.Project)
|
||||||
.where(`${TableName.Project}.id`, id)
|
.where(`${TableName.Project}.id`, id)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
||||||
.select(
|
.select(
|
||||||
@@ -198,7 +201,8 @@ export const projectDALFactory = (db: TDbClient) => {
|
|||||||
throw new BadRequestError({ message: "Organization ID is required when querying with slugs" });
|
throw new BadRequestError({ message: "Organization ID is required when querying with slugs" });
|
||||||
}
|
}
|
||||||
|
|
||||||
const projects = await db(TableName.Project)
|
const projects = await db
|
||||||
|
.replicaNode()(TableName.Project)
|
||||||
.where(`${TableName.Project}.slug`, slug)
|
.where(`${TableName.Project}.slug`, slug)
|
||||||
.where(`${TableName.Project}.orgId`, orgId)
|
.where(`${TableName.Project}.orgId`, orgId)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.projectId`, `${TableName.Project}.id`)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const secretBlindIndexDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const countOfSecretsWithNullSecretBlindIndex = async (projectId: string, tx?: Knex) => {
|
const countOfSecretsWithNullSecretBlindIndex = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.Secret)
|
const doc = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
@@ -26,7 +26,7 @@ export const secretBlindIndexDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findAllSecretsByProjectId = async (projectId: string, tx?: Knex) => {
|
const findAllSecretsByProjectId = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.Secret)
|
const docs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
@@ -43,7 +43,7 @@ export const secretBlindIndexDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findSecretsByProjectId = async (projectId: string, secretIds: string[], tx?: Knex) => {
|
const findSecretsByProjectId = async (projectId: string, secretIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.Secret)
|
const docs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
.leftJoin(TableName.SecretFolder, `${TableName.SecretFolder}.id`, `${TableName.Secret}.folderId`)
|
||||||
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
.leftJoin(TableName.Environment, `${TableName.Environment}.id`, `${TableName.SecretFolder}.envId`)
|
||||||
.where({ projectId })
|
.where({ projectId })
|
||||||
|
|||||||
@@ -211,7 +211,12 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findBySecretPath = async (projectId: string, environment: string, path: string, tx?: Knex) => {
|
const findBySecretPath = async (projectId: string, environment: string, path: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const folder = await sqlFindFolderByPathQuery(tx || db, projectId, environment, removeTrailingSlash(path))
|
const folder = await sqlFindFolderByPathQuery(
|
||||||
|
tx || db.replicaNode(),
|
||||||
|
projectId,
|
||||||
|
environment,
|
||||||
|
removeTrailingSlash(path)
|
||||||
|
)
|
||||||
.orderBy("depth", "desc")
|
.orderBy("depth", "desc")
|
||||||
.first();
|
.first();
|
||||||
if (folder && folder.path !== removeTrailingSlash(path)) {
|
if (folder && folder.path !== removeTrailingSlash(path)) {
|
||||||
@@ -230,7 +235,12 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
// it will stop automatically at /path2
|
// it will stop automatically at /path2
|
||||||
const findClosestFolder = async (projectId: string, environment: string, path: string, tx?: Knex) => {
|
const findClosestFolder = async (projectId: string, environment: string, path: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const folder = await sqlFindFolderByPathQuery(tx || db, projectId, environment, removeTrailingSlash(path))
|
const folder = await sqlFindFolderByPathQuery(
|
||||||
|
tx || db.replicaNode(),
|
||||||
|
projectId,
|
||||||
|
environment,
|
||||||
|
removeTrailingSlash(path)
|
||||||
|
)
|
||||||
.orderBy("depth", "desc")
|
.orderBy("depth", "desc")
|
||||||
.first();
|
.first();
|
||||||
if (!folder) return;
|
if (!folder) return;
|
||||||
@@ -247,7 +257,7 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
envId,
|
envId,
|
||||||
secretPath: removeTrailingSlash(secretPath)
|
secretPath: removeTrailingSlash(secretPath)
|
||||||
}));
|
}));
|
||||||
const folders = await sqlFindMultipleFolderByEnvPathQuery(tx || db, formatedQuery);
|
const folders = await sqlFindMultipleFolderByEnvPathQuery(tx || db.replicaNode(), formatedQuery);
|
||||||
return formatedQuery.map(({ envId, secretPath }) =>
|
return formatedQuery.map(({ envId, secretPath }) =>
|
||||||
folders.find(({ path: targetPath, envId: targetEnvId }) => targetPath === secretPath && targetEnvId === envId)
|
folders.find(({ path: targetPath, envId: targetEnvId }) => targetPath === secretPath && targetEnvId === envId)
|
||||||
);
|
);
|
||||||
@@ -260,7 +270,7 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
// that is instances in which for a given folderid find the secret path
|
// that is instances in which for a given folderid find the secret path
|
||||||
const findSecretPathByFolderIds = async (projectId: string, folderIds: string[], tx?: Knex) => {
|
const findSecretPathByFolderIds = async (projectId: string, folderIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const folders = await sqlFindSecretPathByFolderId(tx || db, projectId, folderIds);
|
const folders = await sqlFindSecretPathByFolderId(tx || db.replicaNode(), projectId, folderIds);
|
||||||
|
|
||||||
// travelling all the way from leaf node to root contains real path
|
// travelling all the way from leaf node to root contains real path
|
||||||
const rootFolders = groupBy(
|
const rootFolders = groupBy(
|
||||||
@@ -299,7 +309,7 @@ export const secretFolderDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const folder = await (tx || db)(TableName.SecretFolder)
|
const folder = await (tx || db.replicaNode())(TableName.SecretFolder)
|
||||||
.where({ [`${TableName.SecretFolder}.id` as "id"]: id })
|
.where({ [`${TableName.SecretFolder}.id` as "id"]: id })
|
||||||
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
||||||
.select(selectAllTableCols(TableName.SecretFolder))
|
.select(selectAllTableCols(TableName.SecretFolder))
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const secretFolderVersionDALFactory = (db: TDbClient) => {
|
|||||||
// This will fetch all latest secret versions from a folder
|
// This will fetch all latest secret versions from a folder
|
||||||
const findLatestVersionByFolderId = async (folderId: string, tx?: Knex) => {
|
const findLatestVersionByFolderId = async (folderId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.SecretFolderVersion)
|
const docs = await (tx || db.replicaNode())(TableName.SecretFolderVersion)
|
||||||
.join(TableName.SecretFolder, `${TableName.SecretFolderVersion}.folderId`, `${TableName.SecretFolder}.id`)
|
.join(TableName.SecretFolder, `${TableName.SecretFolderVersion}.folderId`, `${TableName.SecretFolder}.id`)
|
||||||
.where({ parentId: folderId, isReserved: false })
|
.where({ parentId: folderId, isReserved: false })
|
||||||
.join<TSecretFolderVersions>(
|
.join<TSecretFolderVersions>(
|
||||||
@@ -38,7 +38,9 @@ export const secretFolderVersionDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findLatestFolderVersions = async (folderIds: string[], tx?: Knex) => {
|
const findLatestFolderVersions = async (folderIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs: Array<TSecretFolderVersions & { max: number }> = await (tx || db)(TableName.SecretFolderVersion)
|
const docs: Array<TSecretFolderVersions & { max: number }> = await (tx || db.replicaNode())(
|
||||||
|
TableName.SecretFolderVersion
|
||||||
|
)
|
||||||
.whereIn("folderId", folderIds)
|
.whereIn("folderId", folderIds)
|
||||||
.join(
|
.join(
|
||||||
(tx || db)(TableName.SecretFolderVersion)
|
(tx || db)(TableName.SecretFolderVersion)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export const secretImportDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: Partial<TSecretImports & { projectId: string }>, tx?: Knex) => {
|
const find = async (filter: Partial<TSecretImports & { projectId: string }>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.SecretImport)
|
const docs = await (tx || db.replicaNode())(TableName.SecretImport)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.join(TableName.Environment, `${TableName.SecretImport}.importEnv`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretImport}.importEnv`, `${TableName.Environment}.id`)
|
||||||
.select(
|
.select(
|
||||||
@@ -72,7 +72,7 @@ export const secretImportDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findByFolderIds = async (folderIds: string[], tx?: Knex) => {
|
const findByFolderIds = async (folderIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.SecretImport)
|
const docs = await (tx || db.replicaNode())(TableName.SecretImport)
|
||||||
.whereIn("folderId", folderIds)
|
.whereIn("folderId", folderIds)
|
||||||
.where("isReplication", false)
|
.where("isReplication", false)
|
||||||
.join(TableName.Environment, `${TableName.SecretImport}.importEnv`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretImport}.importEnv`, `${TableName.Environment}.id`)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const secretTagDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findManyTagsById = async (projectId: string, ids: string[], tx?: Knex) => {
|
const findManyTagsById = async (projectId: string, ids: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const tags = await (tx || db)(TableName.SecretTag).where({ projectId }).whereIn("id", ids);
|
const tags = await (tx || db.replicaNode())(TableName.SecretTag).where({ projectId }).whereIn("id", ids);
|
||||||
return tags;
|
return tags;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find all by ids" });
|
throw new DatabaseError({ error, name: "Find all by ids" });
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
userId = undefined;
|
userId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const secs = await (tx || db)(TableName.Secret)
|
const secs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.where({ folderId })
|
.where({ folderId })
|
||||||
.where((bd) => {
|
.where((bd) => {
|
||||||
void bd.whereNull("userId").orWhere({ userId: userId || null });
|
void bd.whereNull("userId").orWhere({ userId: userId || null });
|
||||||
@@ -152,7 +152,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const getSecretTags = async (secretId: string, tx?: Knex) => {
|
const getSecretTags = async (secretId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const tags = await (tx || db)(TableName.JnSecretTag)
|
const tags = await (tx || db.replicaNode())(TableName.JnSecretTag)
|
||||||
.join(TableName.SecretTag, `${TableName.JnSecretTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)
|
.join(TableName.SecretTag, `${TableName.JnSecretTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)
|
||||||
.where({ [`${TableName.Secret}Id` as const]: secretId })
|
.where({ [`${TableName.Secret}Id` as const]: secretId })
|
||||||
.select(db.ref("id").withSchema(TableName.SecretTag).as("tagId"))
|
.select(db.ref("id").withSchema(TableName.SecretTag).as("tagId"))
|
||||||
@@ -179,7 +179,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
userId = undefined;
|
userId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const secs = await (tx || db)(TableName.Secret)
|
const secs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.whereIn("folderId", folderIds)
|
.whereIn("folderId", folderIds)
|
||||||
.where((bd) => {
|
.where((bd) => {
|
||||||
void bd.whereNull("userId").orWhere({ userId: userId || null });
|
void bd.whereNull("userId").orWhere({ userId: userId || null });
|
||||||
@@ -223,7 +223,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
) => {
|
) => {
|
||||||
if (!blindIndexes.length) return [];
|
if (!blindIndexes.length) return [];
|
||||||
try {
|
try {
|
||||||
const secrets = await (tx || db)(TableName.Secret)
|
const secrets = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.where({ folderId })
|
.where({ folderId })
|
||||||
.where((bd) => {
|
.where((bd) => {
|
||||||
blindIndexes.forEach((el) => {
|
blindIndexes.forEach((el) => {
|
||||||
@@ -278,7 +278,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findReferencedSecretReferences = async (projectId: string, envSlug: string, secretPath: string, tx?: Knex) => {
|
const findReferencedSecretReferences = async (projectId: string, envSlug: string, secretPath: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.SecretReference)
|
const docs = await (tx || db.replicaNode())(TableName.SecretReference)
|
||||||
.where({
|
.where({
|
||||||
secretPath,
|
secretPath,
|
||||||
environment: envSlug
|
environment: envSlug
|
||||||
@@ -298,7 +298,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
// special query to backfill secret value
|
// special query to backfill secret value
|
||||||
const findAllProjectSecretValues = async (projectId: string, tx?: Knex) => {
|
const findAllProjectSecretValues = async (projectId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.Secret)
|
const docs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.join(TableName.SecretFolder, `${TableName.Secret}.folderId`, `${TableName.SecretFolder}.id`)
|
.join(TableName.SecretFolder, `${TableName.Secret}.folderId`, `${TableName.SecretFolder}.id`)
|
||||||
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
.join(TableName.Environment, `${TableName.SecretFolder}.envId`, `${TableName.Environment}.id`)
|
||||||
.where("projectId", projectId)
|
.where("projectId", projectId)
|
||||||
@@ -313,7 +313,7 @@ export const secretDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOneWithTags = async (filter: Partial<TSecrets>, tx?: Knex) => {
|
const findOneWithTags = async (filter: Partial<TSecrets>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const rawDocs = await (tx || db)(TableName.Secret)
|
const rawDocs = await (tx || db.replicaNode())(TableName.Secret)
|
||||||
.where(filter)
|
.where(filter)
|
||||||
.leftJoin(TableName.JnSecretTag, `${TableName.Secret}.id`, `${TableName.JnSecretTag}.${TableName.Secret}Id`)
|
.leftJoin(TableName.JnSecretTag, `${TableName.Secret}.id`, `${TableName.JnSecretTag}.${TableName.Secret}Id`)
|
||||||
.leftJoin(TableName.SecretTag, `${TableName.JnSecretTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)
|
.leftJoin(TableName.SecretTag, `${TableName.JnSecretTag}.${TableName.SecretTag}Id`, `${TableName.SecretTag}.id`)
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export const secretVersionDALFactory = (db: TDbClient) => {
|
|||||||
// This will fetch all latest secret versions from a folder
|
// This will fetch all latest secret versions from a folder
|
||||||
const findLatestVersionByFolderId = async (folderId: string, tx?: Knex) => {
|
const findLatestVersionByFolderId = async (folderId: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await (tx || db)(TableName.SecretVersion)
|
const docs = await (tx || db.replicaNode())(TableName.SecretVersion)
|
||||||
.where(`${TableName.SecretVersion}.folderId`, folderId)
|
.where(`${TableName.SecretVersion}.folderId`, folderId)
|
||||||
.join(TableName.Secret, `${TableName.Secret}.id`, `${TableName.SecretVersion}.secretId`)
|
.join(TableName.Secret, `${TableName.Secret}.id`, `${TableName.SecretVersion}.secretId`)
|
||||||
.join<TSecretVersions, TSecretVersions & { secretId: string; max: number }>(
|
.join<TSecretVersions, TSecretVersions & { secretId: string; max: number }>(
|
||||||
@@ -90,7 +90,7 @@ export const secretVersionDALFactory = (db: TDbClient) => {
|
|||||||
const findLatestVersionMany = async (folderId: string, secretIds: string[], tx?: Knex) => {
|
const findLatestVersionMany = async (folderId: string, secretIds: string[], tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
if (!secretIds.length) return {};
|
if (!secretIds.length) return {};
|
||||||
const docs: Array<TSecretVersions & { max: number }> = await (tx || db)(TableName.SecretVersion)
|
const docs: Array<TSecretVersions & { max: number }> = await (tx || db.replicaNode())(TableName.SecretVersion)
|
||||||
.where("folderId", folderId)
|
.where("folderId", folderId)
|
||||||
.whereIn(`${TableName.SecretVersion}.secretId`, secretIds)
|
.whereIn(`${TableName.SecretVersion}.secretId`, secretIds)
|
||||||
.join(
|
.join(
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export const serviceTokenDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await (tx || db)(TableName.ServiceToken)
|
const doc = await (tx || db.replicaNode())(TableName.ServiceToken)
|
||||||
.leftJoin<TUsers>(
|
.leftJoin<TUsers>(
|
||||||
TableName.Users,
|
TableName.Users,
|
||||||
`${TableName.Users}.id`,
|
`${TableName.Users}.id`,
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
// -------------------------
|
// -------------------------
|
||||||
const findUserEncKeyByUsername = async ({ username }: { username: string }) => {
|
const findUserEncKeyByUsername = async ({ username }: { username: string }) => {
|
||||||
try {
|
try {
|
||||||
return await db(TableName.Users)
|
return await db
|
||||||
|
.replicaNode()(TableName.Users)
|
||||||
.where({
|
.where({
|
||||||
username,
|
username,
|
||||||
isGhost: false
|
isGhost: false
|
||||||
@@ -36,7 +37,7 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findUserEncKeyByUserIdsBatch = async ({ userIds }: { userIds: string[] }, tx?: Knex) => {
|
const findUserEncKeyByUserIdsBatch = async ({ userIds }: { userIds: string[] }, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
return await (tx || db)(TableName.Users)
|
return await (tx || db.replicaNode())(TableName.Users)
|
||||||
.where({
|
.where({
|
||||||
isGhost: false
|
isGhost: false
|
||||||
})
|
})
|
||||||
@@ -49,7 +50,8 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findUserEncKeyByUserId = async (userId: string) => {
|
const findUserEncKeyByUserId = async (userId: string) => {
|
||||||
try {
|
try {
|
||||||
const user = await db(TableName.Users)
|
const user = await db
|
||||||
|
.replicaNode()(TableName.Users)
|
||||||
.where(`${TableName.Users}.id`, userId)
|
.where(`${TableName.Users}.id`, userId)
|
||||||
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
.join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`)
|
||||||
.first();
|
.first();
|
||||||
@@ -65,7 +67,8 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findUserByProjectMembershipId = async (projectMembershipId: string) => {
|
const findUserByProjectMembershipId = async (projectMembershipId: string) => {
|
||||||
try {
|
try {
|
||||||
return await db(TableName.ProjectMembership)
|
return await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.where({ [`${TableName.ProjectMembership}.id` as "id"]: projectMembershipId })
|
.where({ [`${TableName.ProjectMembership}.id` as "id"]: projectMembershipId })
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.first();
|
.first();
|
||||||
@@ -76,7 +79,8 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findUsersByProjectMembershipIds = async (projectMembershipIds: string[]) => {
|
const findUsersByProjectMembershipIds = async (projectMembershipIds: string[]) => {
|
||||||
try {
|
try {
|
||||||
return await db(TableName.ProjectMembership)
|
return await db
|
||||||
|
.replicaNode()(TableName.ProjectMembership)
|
||||||
.whereIn(`${TableName.ProjectMembership}.id`, projectMembershipIds)
|
.whereIn(`${TableName.ProjectMembership}.id`, projectMembershipIds)
|
||||||
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
.join(TableName.Users, `${TableName.ProjectMembership}.userId`, `${TableName.Users}.id`)
|
||||||
.select("*");
|
.select("*");
|
||||||
@@ -128,7 +132,7 @@ export const userDALFactory = (db: TDbClient) => {
|
|||||||
// ---------------------
|
// ---------------------
|
||||||
const findOneUserAction = (filter: TUserActionsUpdate, tx?: Knex) => {
|
const findOneUserAction = (filter: TUserActionsUpdate, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
return (tx || db)(TableName.UserAction).where(filter).first("*");
|
return (tx || db.replicaNode())(TableName.UserAction).where(filter).first("*");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new DatabaseError({ error, name: "Find one user action" });
|
throw new DatabaseError({ error, name: "Find one user action" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const webhookDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const find = async (filter: Partial<TWebhooks>, tx?: Knex) => {
|
const find = async (filter: Partial<TWebhooks>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const docs = await webhookFindQuery(tx || db, filter);
|
const docs = await webhookFindQuery(tx || db.replicaNode(), filter);
|
||||||
return docs.map(({ envId, envSlug, envName, ...el }) => ({
|
return docs.map(({ envId, envSlug, envName, ...el }) => ({
|
||||||
...el,
|
...el,
|
||||||
envId,
|
envId,
|
||||||
@@ -39,7 +39,7 @@ export const webhookDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findOne = async (filter: Partial<TWebhooks>, tx?: Knex) => {
|
const findOne = async (filter: Partial<TWebhooks>, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await webhookFindQuery(tx || db, filter).first();
|
const doc = await webhookFindQuery(tx || db.replicaNode(), filter).first();
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
|
|
||||||
const { envName: name, envSlug: slug, envId: id, ...el } = doc;
|
const { envName: name, envSlug: slug, envId: id, ...el } = doc;
|
||||||
@@ -51,7 +51,7 @@ export const webhookDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findById = async (id: string, tx?: Knex) => {
|
const findById = async (id: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const doc = await webhookFindQuery(tx || db, {
|
const doc = await webhookFindQuery(tx || db.replicaNode(), {
|
||||||
[`${TableName.Webhook}.id` as "id"]: id
|
[`${TableName.Webhook}.id` as "id"]: id
|
||||||
}).first();
|
}).first();
|
||||||
if (!doc) return;
|
if (!doc) return;
|
||||||
@@ -65,7 +65,7 @@ export const webhookDALFactory = (db: TDbClient) => {
|
|||||||
|
|
||||||
const findAllWebhooks = async (projectId: string, environment?: string, secretPath?: string, tx?: Knex) => {
|
const findAllWebhooks = async (projectId: string, environment?: string, secretPath?: string, tx?: Knex) => {
|
||||||
try {
|
try {
|
||||||
const webhooks = await (tx || db)(TableName.Webhook)
|
const webhooks = await (tx || db.replicaNode())(TableName.Webhook)
|
||||||
.where(`${TableName.Environment}.projectId`, projectId)
|
.where(`${TableName.Environment}.projectId`, projectId)
|
||||||
.where((qb) => {
|
.where((qb) => {
|
||||||
if (environment) {
|
if (environment) {
|
||||||
|
|||||||
Reference in New Issue
Block a user