All files / src/entities enrolled_domain.ts

76% Statements 19/25
0% Branches 0/4
50% Functions 1/2
73.91% Lines 17/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x 1x 1x   1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x                   1x  
import { Domain } from './domain.js';
import { Entity } from '../entity.js';
import { User } from './user.js';
import { Role } from '../constants/roles.js';
import { DomainType } from '../constants/domain_types.js';
 
export class EnrolledDomain extends Entity {
  protected static resourceName = 'enrolled_domains';
  protected static singularName = 'enrolledDomain';
  protected static pluralName = 'enrolledDomains';
 
  @EnrolledDomain.property({type: Date})
  public archived?: Date | null;
 
  @EnrolledDomain.property()
  public id?: number;
 
  @EnrolledDomain.property()
  public isJobsAssignee?: boolean;
 
  @EnrolledDomain.property()
  public role?: Role;
 
  @EnrolledDomain.property()
  public user?: User;
 
  @EnrolledDomain.property()
  public domain?: Domain;
 
  public getRole(): Role {
    Iif (this.domain === undefined) {
      const err = 'domain is undefined, did you forget to embed it?';
      throw new Error(err);
    }
    Iif (this.domain.domainType === DomainType.DOMAIN_SUPPLIER) {
      return Role.SUPPLIER;
    }
    return this.role ? this.role : Role.PUBLIC;
  }
}