@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
22import { FormGroup , FormBuilder , Validators } from '@angular/forms' ;
33import { AuthService } from '../../services/auth.service' ;
44import { Router } from '@angular/router' ;
5+ import { ContestService } from '../../services/contest.service' ;
56
67@Component ( {
78 selector : 'app-add-contest' ,
@@ -11,27 +12,46 @@ import { Router } from '@angular/router';
1112export class AddContestComponent implements OnInit {
1213
1314 form : FormGroup ;
15+ username : string ;
1416
1517 constructor (
1618 private authService : AuthService ,
1719 private router : Router ,
18- private formBuilder : FormBuilder
20+ private formBuilder : FormBuilder ,
21+ private contestService : ContestService
1922 ) { }
2023
2124 ngOnInit ( ) {
2225 this . createForm ( ) ;
26+ this . authService . getProfile ( ) . subscribe ( profile => {
27+ this . username = profile . msg . username ; // Used when creating new blog posts and comments
28+ } ) ;
2329 }
2430 createForm ( ) {
2531 this . form = this . formBuilder . group ( {
2632 name : [ '' , Validators . required ] ,
2733 id : [ '' , Validators . required ] ,
28- startdate : [ '' , Validators . required ] ,
29- enddate : [ '' , Validators . required ] ,
34+ startTime : [ '' , Validators . required ] ,
35+ endTime : [ '' , Validators . required ] ,
3036 description : [ '' , Validators . required ]
3137 } ) ;
3238 }
3339
3440 onAddContestSubmit ( ) {
35-
41+ const contest = {
42+ // username: this.username,
43+ name : this . form . get ( 'name' ) . value ,
44+ id : this . form . get ( 'id' ) . value ,
45+ startTime : this . form . get ( 'startTime' ) . value ,
46+ endTime : this . form . get ( 'endTime' ) . value ,
47+ description : this . form . get ( 'description' ) . value
48+ } ;
49+ this . contestService . addContest ( contest ) . subscribe ( data => {
50+ if ( ! data . success ) {
51+ console . log ( data . msg ) ;
52+ } else {
53+ this . router . navigate ( [ '/contest' ] ) ;
54+ }
55+ } ) ;
3656 }
3757}
0 commit comments