async findAll()

in services/application/apps/user/src/users/users.service.ts [45:88]


  async findAll(userPoolId: string, tenantId: string) {
    console.log(
      'Finding all users for userpoolId:',
      userPoolId,
      'and tenantId:',
      tenantId,
    );
    try {
      const client = new CognitoIdentityProviderClient({
        region: process.env.AWS_REGION,
      });
      const cmd = new ListUsersCommand({
        UserPoolId: userPoolId,
      });
      const res = await client.send(cmd);
      const allUsers = res.Users;
      const users = allUsers
        .filter((user) => {
          user.Attributes.some(
            (attr) =>
              attr.Name === 'custom:tenant-id' && attr.Value === tenantId,
          );
        })
        .map((user) => {
          return {
            email: user.Attributes.find((a) => a.Name === 'email').Value,
            enabled: user.Enabled,
            createdDate: user.UserCreateDate,
            modifiedDate: user.UserLastModifiedDate,
            status: user.UserStatus,
          };
        });
      return users;
    } catch (error) {
      console.error(error);
      throw new HttpException(
        {
          status: HttpStatus.INTERNAL_SERVER_ERROR,
          error: error,
        },
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    }
  }