mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 12:38:36 +00:00
address feedback suggestions
This commit is contained in:
@@ -112,7 +112,7 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
projectId: string,
|
||||
filter: { identityId?: string } & Pick<
|
||||
TListProjectIdentityDTO,
|
||||
"limit" | "offset" | "textFilter" | "orderBy" | "direction"
|
||||
"limit" | "offset" | "search" | "orderBy" | "orderDirection"
|
||||
> = {},
|
||||
tx?: Knex
|
||||
) => {
|
||||
@@ -126,8 +126,8 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
void qb.where("identityId", filter.identityId);
|
||||
}
|
||||
|
||||
if (filter.textFilter) {
|
||||
void qb.whereILike(`${TableName.Identity}.name`, `%${filter.textFilter}%`);
|
||||
if (filter.search) {
|
||||
void qb.whereILike(`${TableName.Identity}.name`, `%${filter.search}%`);
|
||||
}
|
||||
})
|
||||
.join(
|
||||
@@ -173,7 +173,7 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
if (filter.orderBy) {
|
||||
switch (filter.orderBy) {
|
||||
case "name":
|
||||
void query.orderBy(`${TableName.Identity}.${filter.orderBy}`, filter.direction);
|
||||
void query.orderBy(`${TableName.Identity}.${filter.orderBy}`, filter.orderDirection);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
@@ -238,7 +238,7 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
|
||||
const getCountByProjectId = async (
|
||||
projectId: string,
|
||||
filter: { identityId?: string } & Pick<TListProjectIdentityDTO, "textFilter"> = {},
|
||||
filter: { identityId?: string } & Pick<TListProjectIdentityDTO, "search"> = {},
|
||||
tx?: Knex
|
||||
) => {
|
||||
try {
|
||||
@@ -251,12 +251,13 @@ export const identityProjectDALFactory = (db: TDbClient) => {
|
||||
void qb.where("identityId", filter.identityId);
|
||||
}
|
||||
|
||||
if (filter.textFilter) {
|
||||
void qb.whereILike(`${TableName.Identity}.name`, `%${filter.textFilter}%`);
|
||||
if (filter.search) {
|
||||
void qb.whereILike(`${TableName.Identity}.name`, `%${filter.search}%`);
|
||||
}
|
||||
});
|
||||
})
|
||||
.count();
|
||||
|
||||
return identities.length;
|
||||
return Number(identities[0].count);
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "GetCountByProjectId" });
|
||||
}
|
||||
|
||||
@@ -272,8 +272,8 @@ export const identityProjectServiceFactory = ({
|
||||
limit,
|
||||
offset,
|
||||
orderBy,
|
||||
direction,
|
||||
textFilter
|
||||
orderDirection,
|
||||
search
|
||||
}: TListProjectIdentityDTO) => {
|
||||
const { permission } = await permissionService.getProjectPermission(
|
||||
actor,
|
||||
@@ -288,11 +288,11 @@ export const identityProjectServiceFactory = ({
|
||||
limit,
|
||||
offset,
|
||||
orderBy,
|
||||
direction,
|
||||
textFilter
|
||||
orderDirection,
|
||||
search
|
||||
});
|
||||
|
||||
const totalCount = await identityProjectDAL.getCountByProjectId(projectId, { textFilter });
|
||||
const totalCount = await identityProjectDAL.getCountByProjectId(projectId, { search });
|
||||
|
||||
return { identityMemberships, totalCount };
|
||||
};
|
||||
|
||||
@@ -44,8 +44,8 @@ export type TListProjectIdentityDTO = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
orderBy?: ProjectIdentityOrderBy;
|
||||
direction?: OrderByDirection;
|
||||
textFilter?: string;
|
||||
orderDirection?: OrderByDirection;
|
||||
search?: string;
|
||||
} & TProjectPermission;
|
||||
|
||||
export type TGetProjectIdentityByIdentityIdDTO = {
|
||||
|
||||
@@ -34,11 +34,11 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
||||
limit,
|
||||
offset = 0,
|
||||
orderBy,
|
||||
direction = OrderByDirection.ASC,
|
||||
textFilter,
|
||||
orderDirection = OrderByDirection.ASC,
|
||||
search,
|
||||
...filter
|
||||
}: Partial<TIdentityOrgMemberships> &
|
||||
Pick<TListOrgIdentitiesByOrgIdDTO, "offset" | "limit" | "orderBy" | "direction" | "textFilter">,
|
||||
Pick<TListOrgIdentitiesByOrgIdDTO, "offset" | "limit" | "orderBy" | "orderDirection" | "search">,
|
||||
tx?: Knex
|
||||
) => {
|
||||
try {
|
||||
@@ -65,18 +65,18 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
||||
if (orderBy) {
|
||||
switch (orderBy) {
|
||||
case "name":
|
||||
void query.orderBy(`${TableName.Identity}.${orderBy}`, direction);
|
||||
void query.orderBy(`${TableName.Identity}.${orderBy}`, orderDirection);
|
||||
break;
|
||||
case "role":
|
||||
void query.orderBy(`${TableName.IdentityOrgMembership}.${orderBy}`, direction);
|
||||
void query.orderBy(`${TableName.IdentityOrgMembership}.${orderBy}`, orderDirection);
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if (textFilter?.length) {
|
||||
void query.whereILike(`${TableName.Identity}.name`, `%${textFilter}%`);
|
||||
if (search?.length) {
|
||||
void query.whereILike(`${TableName.Identity}.name`, `%${search}%`);
|
||||
}
|
||||
|
||||
const docs = await query;
|
||||
@@ -117,21 +117,22 @@ export const identityOrgDALFactory = (db: TDbClient) => {
|
||||
};
|
||||
|
||||
const countAllOrgIdentities = async (
|
||||
{ textFilter, ...filter }: Partial<TIdentityOrgMemberships> & Pick<TListOrgIdentitiesByOrgIdDTO, "textFilter">,
|
||||
{ search, ...filter }: Partial<TIdentityOrgMemberships> & Pick<TListOrgIdentitiesByOrgIdDTO, "search">,
|
||||
tx?: Knex
|
||||
) => {
|
||||
try {
|
||||
const query = (tx || db.replicaNode())(TableName.IdentityOrgMembership)
|
||||
.where(filter)
|
||||
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`);
|
||||
.join(TableName.Identity, `${TableName.IdentityOrgMembership}.identityId`, `${TableName.Identity}.id`)
|
||||
.count();
|
||||
|
||||
if (textFilter?.length) {
|
||||
void query.whereILike(`${TableName.Identity}.name`, `%${textFilter}%`);
|
||||
if (search?.length) {
|
||||
void query.whereILike(`${TableName.Identity}.name`, `%${search}%`);
|
||||
}
|
||||
|
||||
const identities = await query;
|
||||
|
||||
return identities.length;
|
||||
return Number(identities[0].count);
|
||||
} catch (error) {
|
||||
throw new DatabaseError({ error, name: "countAllOrgIdentities" });
|
||||
}
|
||||
|
||||
@@ -204,8 +204,8 @@ export const identityServiceFactory = ({
|
||||
limit,
|
||||
offset,
|
||||
orderBy,
|
||||
direction,
|
||||
textFilter
|
||||
orderDirection,
|
||||
search
|
||||
}: TListOrgIdentitiesByOrgIdDTO) => {
|
||||
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
|
||||
ForbiddenError.from(permission).throwUnlessCan(OrgPermissionActions.Read, OrgPermissionSubjects.Identity);
|
||||
@@ -215,13 +215,13 @@ export const identityServiceFactory = ({
|
||||
limit,
|
||||
offset,
|
||||
orderBy,
|
||||
direction,
|
||||
textFilter
|
||||
orderDirection,
|
||||
search
|
||||
});
|
||||
|
||||
const totalCount = await identityOrgMembershipDAL.countAllOrgIdentities({
|
||||
[`${TableName.IdentityOrgMembership}.orgId` as "orgId"]: orgId,
|
||||
textFilter
|
||||
search
|
||||
});
|
||||
|
||||
return { identityMemberships, totalCount };
|
||||
|
||||
@@ -34,8 +34,8 @@ export type TListOrgIdentitiesByOrgIdDTO = {
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
orderBy?: OrgIdentityOrderBy;
|
||||
direction?: OrderByDirection;
|
||||
textFilter?: string;
|
||||
orderDirection?: OrderByDirection;
|
||||
search?: string;
|
||||
} & TOrgPermission;
|
||||
|
||||
export enum OrgIdentityOrderBy {
|
||||
|
||||
Reference in New Issue
Block a user