Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kimura-developer committed Sep 20, 2023
1 parent 17041be commit aad61fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
1 change: 1 addition & 0 deletions service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/lib/
/test-lib/
/functionalTests-lib/
.angular-cache/
30 changes: 4 additions & 26 deletions service/src/app.impl/users/app.impl.users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ import { UserRepository } from '../../entities/users/entities.users';
import { withPermission, KnownErrorsOf } from '../../app.api/app.api.global';
import { PageOf } from '../../entities/entities.global';

export function SearchUsers(
userRepo: UserRepository,
permissions: api.UsersPermissionService
export function SearchUsers(userRepo: UserRepository,permissions: api.UsersPermissionService
): api.SearchUsers {
return async function searchUsers(
req: api.UserSearchRequest
): ReturnType<api.SearchUsers> {
// Use the buildFilter function to construct the filter
const userSearch: api.UserSearchRequest['userSearch'] = buildFilter(
req.userSearch
);

// Continue with the rest of the logic, including the search operation
return async function searchUsers(req: api.UserSearchRequest): ReturnType<api.SearchUsers> {
return await withPermission<
PageOf<api.UserSearchResult>,
KnownErrorsOf<api.SearchUsers>
>(
permissions.ensureReadUsersPermission(req.context),
async (): Promise<PageOf<api.UserSearchResult>> => {
const page = await userRepo.find<api.UserSearchResult>(
userSearch,
req.userSearch,
x => {
return {
id: x.id,
Expand All @@ -44,16 +34,4 @@ export function SearchUsers(
}
);
};
}

// Function to abstract parameter handling and filter building
function buildFilter(userSearch: api.UserSearchRequest['userSearch']): api.UserSearchRequest['userSearch'] {
const filter: api.UserSearchRequest['userSearch'] = {
nameOrContactTerm: userSearch.nameOrContactTerm,
pageSize: userSearch.pageSize || 250,
pageIndex: userSearch.pageIndex || 0,
includeTotalCount: userSearch.includeTotalCount,
};

return filter;
}
}

0 comments on commit aad61fb

Please sign in to comment.