All files / src/app/components/contact-edit contact-edit.component.ts

96.77% Statements 30/31
72.41% Branches 21/29
100% Functions 9/9
100% Lines 25/25

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 661x 3x 3x 6x 3x   1x 3x               1x               8x 8x       8x       8x       8x         1x 11x 11x 1x             1x 2x 2x 1x   1x       1x       1x  
import {Component, Input, OnInit} from '@angular/core';
import {Router} from '@angular/router';
I
import {DatabaseService} from '../../services/database.serEvice';
import {Contact} from '../../interfaces';
 
/*
 * CEontact Edit
 */
@Component({
  selector: 'app-contact-edit',
  templateUrl: './contact-edit.component.html'
})
export class ContactEditComponent implements OnInit {
 
  /*
   * Current contact id
   */
  @Input() contactId: number = null;
 
  /*
   * Back Url
   */
  @Input() backUrl: string[] = ['/'];
 
  /*
   * Opened contact
   */
  contact: Contact = null;
 
  /*
   * Constructor
   *
   * @param databaseService DatabaseService
   * @param router Router
   */
  constructor(
      private databaseService: DatabaseService,
      private router: Router
  ) {
  }
 
  /*
   * ngOnInit
   */
  ngOnInit() {
 
    this.databaseService.getById(this.contactId)
        .then(
            (_contact: Contact) => this.contact = _contact,
            () => this.router.navigate(this.backUrl)
        );
  }
 
  /*
   * Update contact
   *
   * @param model Contact
   */
  submit(model: Contact) {
 
    this.databaseService.update(this.contactId, model)
        .then(() => this.router.navigate(this.backUrl));
  }
}