SHARE
TWEET

Untitled

a guest Mar 31st, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Component, OnChanges, OnInit, SimpleChanges} from '@angular/core';
  2. import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms';
  3. import {StructureError} from '../../../utils/structure-error';
  4. import {Athlete} from "../../domain/athlete";
  5. import {Auth} from "aws-amplify";
  6. import {AthleteProfileService} from "../../services/athlete-profile.service";
  7. import {__await} from "tslib";
  8. import {APIService} from "../../API.service";
  9.  
  10. export class ErrorMessages {
  11.   dob: StructureError[];
  12.   email: StructureError[];
  13.   height: StructureError[];
  14.   weightCategory: StructureError[];
  15.   boatPreference: StructureError[];
  16.   side: StructureError[];
  17.   sex: StructureError[];
  18.   firstName: StructureError[];
  19.   lastName: StructureError[];
  20. }
  21.  
  22.  
  23. @Component({
  24.   selector: 'app-athlete-profile',
  25.   templateUrl: './athlete-profile.component.html',
  26.   styleUrls: ['./athlete-profile.component.css']
  27. })
  28.  
  29. export class AthleteProfileComponent implements OnInit {
  30.  
  31.   public profileForm: FormGroup;
  32.   public errorMessages: ErrorMessages;
  33.   public boats: [{id: 1, name: 'single'}];
  34.   public sides: [{id: 1, name: 'port'}];
  35.   public sex: [{id: 1, name: 'M'}];
  36.   public athlete = new Athlete();
  37.  
  38.  
  39.   constructor(private fb: FormBuilder, private service: AthleteProfileService, private api: APIService) {
  40.     Auth.currentAuthenticatedUser({
  41.       bypassCache: false
  42.     }).then(async user => {
  43.       this.athlete.id = user.attributes.sub;
  44.       this.athlete.email = user.attributes.email;
  45.  
  46.     })
  47.       .catch(err => console.log(err));
  48.   }
  49.  
  50.   ngOnInit() {
  51.  
  52.     this.getAthlete(this.athlete.id);
  53.     this.errorMessages = {
  54.       dob: [
  55.         {type: 'required', message: 'The date of birth is required.'}
  56.       ],
  57.       email: [
  58.         {type: 'required', message: 'The email is required.'}
  59.       ],
  60.       height: [
  61.         {type: 'required', message: 'The height is required.'}
  62.       ],
  63.       weightCategory: [
  64.         {type: 'required', message: 'The weight category is required.'}
  65.       ],
  66.       boatPreference: [
  67.         {type: 'required', message: 'The boat preference is required.'}
  68.       ],
  69.       side: [
  70.         {type: 'required', message: 'The side preference is required.'}
  71.       ],
  72.       sex: [
  73.         {type: 'required', message: 'The sex is required.'}
  74.       ],
  75.       firstName: [
  76.         {type: 'required', message: 'The firstname is required.'}
  77.       ],
  78.       lastName: [
  79.         {type: 'required', message: 'The lastname is required.'}
  80.       ]
  81.     };
  82.  
  83.     this.profileForm = this.fb.group({
  84.       // dob: new FormControl('', [Validators.required]),
  85.       // email: new FormControl('', [Validators.required]),
  86.       // weight: new FormControl(''),
  87.       // height: new FormControl('', [Validators.required]),
  88.       // weightCategory: new FormControl('', [Validators.required]),
  89.       // boatPreference: new FormControl('', [Validators.required]),
  90.       // side: new FormControl('', [Validators.required]),
  91.       // sex: new FormControl('', [Validators.required]),
  92.       // rcaNumber: new FormControl('', [Validators.required]),
  93.       // membershipType: new FormControl('', [Validators.required]),
  94.       // firstName: new FormControl('', [Validators.required]),
  95.       // lastName: new FormControl('', [Validators.required]),
  96.  
  97.       dob: new FormControl(''),
  98.       email: new FormControl(this.athlete.email),
  99.       weight: new FormControl(this.athlete.weight),
  100.       height: new FormControl(this.athlete.height),
  101.       weightCategory: new FormControl(this.athlete.weightCategory),
  102.       boatPreference: new FormControl(this.athlete.boatPreference),
  103.       side: new FormControl(this.athlete.side),
  104.       sex: new FormControl(this.athlete.sex),
  105.       membershipType: new FormControl(this.athlete.membershipType),
  106.       firstName: new FormControl(this.athlete.firstName),
  107.       lastName: new FormControl(this.athlete.lastName),
  108.     });
  109.   }
  110.  
  111.   getAthlete(athleteId: string){
  112.     // this.service.getAthlete(athleteId).then( test=>{
  113.     //   console.log(test);
  114.     // });
  115.     console.log(athleteId);
  116.     this.api.GetUser(athleteId)
  117.       .then(data=>{
  118.         this.athlete = data;
  119.         this.athlete.sex = data.sex;
  120.         this.athlete.firstName = data.firstName;
  121.         console.log(this.athlete);
  122.  
  123.       })
  124.       .catch(err => console.log(err));
  125.   };
  126.  
  127.  
  128.  
  129.   create() {
  130.     // if (this.profileForm.valid){
  131.       const profil = this.profileForm.value;
  132.       // const profilAthlete = new Athlete();
  133.       this.athlete.id = this.athlete.id
  134.       this.athlete.firstName = profil.firstName;
  135.       this.athlete.lastName = profil.lastName;
  136.       this.athlete.membershipType = profil.membershipType;
  137.       this.athlete.email = profil.email;
  138.       // this.athlete.dob = profil.dob;
  139.       this.athlete.weight = profil.weight;
  140.       this.athlete.height = profil.height;
  141.       this.athlete.weightCategory = profil.weightCategory;
  142.       this.athlete.boatPreference = profil.boatPreference;
  143.       this.athlete.side = profil.side;
  144.       this.athlete.sex = profil.sex;
  145.       this.athlete.status = profil.status;
  146.       this.athlete.membershipType = 3;
  147.  
  148.       this.service.save(this.athlete)
  149.     // }
  150.  
  151.   }
  152. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top