All files / src/entities draft.ts

77.14% Statements 27/35
0% Branches 0/7
33.33% Functions 1/3
78.12% Lines 25/32

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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77  1x   1x   1x     1x 1x 1x 1x   1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x     1x                           1x  
import { DraftComment } from './draft_comment.js';
import { Entity } from '../entity.js';
import { MerchiFile } from './file.js';
import { Job } from './job.js';
import { Notification } from './notification.js';
import { User } from './user.js';
import { DraftTemplate } from './draft_template.js';
 
export class Draft extends Entity {
  protected static resourceName = 'drafts';
  protected static singularName = 'draft';
  protected static pluralName = 'drafts';
 
  @Draft.property({type: Date})
  public archived?: Date | null;
 
  @Draft.property()
  public id?: number;
 
  @Draft.property({type: Date})
  public date?: Date | null;
 
  @Draft.property({type: Date})
  public accepted?: Date | null;
 
  @Draft.property({type: Date})
  public resendDate?: Date | null;
 
  @Draft.property()
  public viewed?: boolean;
 
  @Draft.property()
  public sendSms?: boolean;
 
  @Draft.property()
  public sendEmail?: boolean;
 
  @Draft.property({arrayType: 'DraftComment'})
  public comments?: DraftComment[];
 
  @Draft.property({arrayType: 'DraftTemplate'})
  public draftTemplates?: DraftTemplate[];
 
  @Draft.property()
  public commentsCount?: number;
 
  @Draft.property()
  public changesRequested?: boolean;
 
  @Draft.property()
  public designer?: User;
 
  @Draft.property({arrayType: 'MerchiFile'})
  public images?: MerchiFile[];
 
  @Draft.property({arrayType: 'Notification'})
  public notification?: Notification[];
 
  @Draft.property()
  public job?: Job;
 
  @Draft.property({arrayType: 'Job'})
  public sharedWithJobs?: Job[];
 
  public commentsYoungestToEldest = () => {
    Iif (this.comments === undefined) {
      throw 'comments is undefined. did you forget to embed it?';
    }
    return this.comments.sort((a, b) => {
      Iif (a.id === undefined || b.id === undefined) {
        throw 'comment id is undefined. did you forget to embed it?';
      }
      return a.id - b.id;
    });
  };
}