async initialSet()

in front-end/src/app/shared/services/viewer.service.ts [88:123]


  async initialSet(userID) {
    try {
      const status = await this.authService.isLoggedIn();
      if (status.role === 'viewer') {
        this.user = await this.userService.getUser(status.user);
        this.reports = await this.reportService.getReportByUser(status.user);
      } else if (status.role === 'admin') {
        this.user = await this.userService.getUser(userID);
        this.adminUser = await this.userService.getUser(this.authService.userID);
        this.reports = await this.reportService.getReportByUser(userID);
      }
      this.reports = this.reports.filter(report => {
        let temp = false;
        for (const org of this.user.organizations) {
          temp = temp || report.organization._id === org._id;
        }
        return temp;
      });
      const orgs = [];
      for (const rep of await this.reports) {
        if (orgs.findIndex(x => x._id === rep.organization._id) === -1) {
          const temp = {
            _id: rep.organization._id,
            name: rep.organization.name,
            reportsCount: null
          };
          orgs.push(temp);
        }
      }
      this.organizations = await orgs;
      for (const org of this.organizations) {
        org.reportsCount = await this.reportsCountByOrg(org._id);
      }
      this.initialized.next(true);
    } catch (error) {}
  }