All files / src/entities assignment.ts

74.41% Statements 32/43
0% Branches 0/6
33.33% Functions 1/3
75% Lines 30/40

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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 1001x 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     1x     1x     1x                                       1x  
import { Entity } from '../entity.js';
import { Quote } from './quote.js';
import { MerchiFile } from './file.js';
import { Job } from './job.js';
import { Notification } from './notification.js';
import { ProductionComment } from './production_comment.js';
import { Reminder } from './reminder.js';
import { Shipment } from './shipment.js';
import { SupplyDomain } from './supply_domain.js';
import { User } from './user.js';
import { RequestOptions } from '../request.js';
 
interface GenerateInvoiceProps {
  addToInvoice? : number;
}
 
export class Assignment extends Entity {
  protected static resourceName = 'assignments';
  protected static singularName = 'assignment';
  protected static pluralName = 'assignments';
 
  @Assignment.property({type: Date})
  public archived?: Date | null;
 
  @Assignment.property()
  public id?: number;
 
  @Assignment.property({type: Date})
  public managerAccepts?: Date | null;
 
  @Assignment.property({type: Date})
  public supplierRefused?: Date | null;
 
  @Assignment.property()
  public needsDrafting?: boolean;
 
  @Assignment.property()
  public needsShipping?: boolean;
 
  @Assignment.property()
  public productionDeadline?: Date;
 
  @Assignment.property()
  public assignmentDeadline?: Date;
 
  @Assignment.property({type: String})
  public notes?: string | null;
 
  @Assignment.property({type: 'Job'})
  public job?: Job | null;
 
  @Assignment.property({type: 'Job'})
  public supplyJob?: Job | null;
 
  @Assignment.property({type: User})
  public supplier?: User | null;
 
  @Assignment.property({type: Quote})
  public quote?: Quote | null;
 
  @Assignment.property()
  public quoteTotalCost?: number;
 
  @Assignment.property({arrayType: 'ProductionComment'})
  public comments?: ProductionComment[];
 
  @Assignment.property({type: Shipment})
  public shipment?: Shipment | null;
 
  @Assignment.property({type: SupplyDomain})
  public supplyDomain?: SupplyDomain | null;
 
  @Assignment.property({arrayType: 'Notification'})
  public notifications?: Notification[];
 
  @Assignment.property({arrayType: 'Reminder'})
  public reminders?: Reminder[];
 
  @Assignment.property({arrayType: 'MerchiFile'})
  public productionFiles?: MerchiFile[];
 
  public generateInvoice = (props?: GenerateInvoiceProps) => {
    const resource = `/generate-invoice-for-assignment/${this.id}/`;
    const fetchOptions: RequestOptions = {method: 'POST'};
    fetchOptions.query = [];
 
    Iif (props && props.addToInvoice) {
      fetchOptions.query.push(['add_to_invoice', String(props.addToInvoice!)]);
    }
 
    return this.merchi.authenticatedFetch(resource, fetchOptions).
      then((data: any) => {
        const invoice = new this.merchi.Invoice();
        invoice.fromJson(data);
        return invoice;
      });
  };
 
}