forked from tykayn/funky-framadate-front
use pollservice proxy to create poll and store the result in storage service
This commit is contained in:
parent
6796d6e39f
commit
fc1859719a
@ -3,7 +3,7 @@ import { RouterModule } from '@angular/router';
|
||||
import { routes } from './routes-framadate';
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true })],
|
||||
imports: [RouterModule.forRoot(routes, { useHash: true })],
|
||||
exports: [RouterModule],
|
||||
})
|
||||
export class AppRoutingModule {}
|
||||
|
@ -80,9 +80,13 @@ export class ApiService {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param poll
|
||||
*/
|
||||
public async createPoll(poll: PollDTO): Promise<Subscription> {
|
||||
// this.loaderService.setStatus(true);
|
||||
console.log('createPoll config', poll);
|
||||
console.log('apiservice createPoll config', poll);
|
||||
return this.axiosInstance.post(
|
||||
`${this.baseHref}${currentApiRoutes['api_new_poll']}`,
|
||||
poll,
|
||||
|
@ -89,7 +89,7 @@ export class PollService implements Resolve<Poll> {
|
||||
this.addChoice('abricot');
|
||||
|
||||
this.form.patchValue({
|
||||
title: 'mon titre',
|
||||
title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()),
|
||||
description: 'répondez SVP <3 ! *-* ',
|
||||
custom_url: this.uuidService.getUUID(),
|
||||
creatorPseudo: 'Chuck Norris',
|
||||
@ -115,7 +115,7 @@ export class PollService implements Resolve<Poll> {
|
||||
public createFormGroup() {
|
||||
let minlengthValidation = environment.production ? 12 : 0;
|
||||
let form = this.fb.group({
|
||||
title: ['', [Validators.required, Validators.minLength(minlengthValidation)]],
|
||||
title: ['mon titre de sondage', [Validators.required, Validators.minLength(minlengthValidation)]],
|
||||
creatorPseudo: ['', [Validators.required]],
|
||||
created_at: [new Date(), [Validators.required]],
|
||||
creatorEmail: ['', [Validators.required]],
|
||||
@ -385,9 +385,12 @@ export class PollService implements Resolve<Poll> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert form data to DTO to create a new poll, and store the admin key
|
||||
*/
|
||||
public createPoll(): Promise<any> {
|
||||
this.toastService.display('sending...');
|
||||
console.log('this.form', this.form);
|
||||
console.log('createPoll this.form', this.form);
|
||||
const newpoll = this.newPollFromForm();
|
||||
return this.apiService.createPoll(newpoll).then(
|
||||
(resp: any) => {
|
||||
@ -395,8 +398,12 @@ export class PollService implements Resolve<Poll> {
|
||||
console.log('TODO fill admin_key');
|
||||
console.log('resp', resp);
|
||||
this.admin_key = resp.data.poll.admin_key;
|
||||
this.storageService.userPolls.push(resp.data.poll);
|
||||
},
|
||||
(error) => this.apiService.ousideHandleError(error)
|
||||
(error) => {
|
||||
this.toastService.display('BOOM, the createPoll went wrong');
|
||||
this.apiService.ousideHandleError(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ export class StorageService {
|
||||
|
||||
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
|
||||
if (environment.autofill_participation) {
|
||||
this.toastService.display('autofill des sondages utilisateur');
|
||||
// this.toastService.display('autofill des sondages utilisateur');
|
||||
this.userPolls.push(new Poll(new Owner(), 'Démo: Anniversaire de tonton Patrick', 'aujourdhui-ou-demain'));
|
||||
this.userPolls.push(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
|
||||
this.userPolls.push(
|
||||
|
@ -21,8 +21,7 @@ export class StepFourComponent implements OnInit {
|
||||
ngOnInit(): void {}
|
||||
|
||||
createPoll() {
|
||||
let apiData = this.pollService.newPollFromForm();
|
||||
this.apiService.createPoll(apiData).then((resp) => {
|
||||
this.pollService.createPoll().then((resp) => {
|
||||
this.router.navigate(['administration/success']);
|
||||
});
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ endpoints.baseHref = apiV1.baseHref;
|
||||
export const environment = {
|
||||
frontDomain: 'http://127.0.0.1:4200',
|
||||
production: false,
|
||||
display_routes: false, // demo paths to test polls
|
||||
display_routes: true, // demo paths to test polls
|
||||
autofill_creation: true,
|
||||
advanced_options_display: true,
|
||||
autofill_participation: true,
|
||||
|
Loading…
Reference in New Issue
Block a user