use pollservice proxy to create poll and store the result in storage service

This commit is contained in:
Tykayn 2021-11-14 17:02:20 +01:00 committed by tykayn
parent 6796d6e39f
commit fc1859719a
6 changed files with 20 additions and 10 deletions

View File

@ -3,7 +3,7 @@ import { RouterModule } from '@angular/router';
import { routes } from './routes-framadate'; import { routes } from './routes-framadate';
@NgModule({ @NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: true })], imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule], exports: [RouterModule],
}) })
export class AppRoutingModule {} export class AppRoutingModule {}

View File

@ -80,9 +80,13 @@ export class ApiService {
}; };
} }
/**
*
* @param poll
*/
public async createPoll(poll: PollDTO): Promise<Subscription> { public async createPoll(poll: PollDTO): Promise<Subscription> {
// this.loaderService.setStatus(true); // this.loaderService.setStatus(true);
console.log('createPoll config', poll); console.log('apiservice createPoll config', poll);
return this.axiosInstance.post( return this.axiosInstance.post(
`${this.baseHref}${currentApiRoutes['api_new_poll']}`, `${this.baseHref}${currentApiRoutes['api_new_poll']}`,
poll, poll,

View File

@ -89,7 +89,7 @@ export class PollService implements Resolve<Poll> {
this.addChoice('abricot'); this.addChoice('abricot');
this.form.patchValue({ this.form.patchValue({
title: 'mon titre', title: 'mon titre de sondage du ' + this.DateUtilitiesService.formateDateToInputStringNg(new Date()),
description: 'répondez SVP <3 ! *-* ', description: 'répondez SVP <3 ! *-* ',
custom_url: this.uuidService.getUUID(), custom_url: this.uuidService.getUUID(),
creatorPseudo: 'Chuck Norris', creatorPseudo: 'Chuck Norris',
@ -115,7 +115,7 @@ export class PollService implements Resolve<Poll> {
public createFormGroup() { public createFormGroup() {
let minlengthValidation = environment.production ? 12 : 0; let minlengthValidation = environment.production ? 12 : 0;
let form = this.fb.group({ let form = this.fb.group({
title: ['', [Validators.required, Validators.minLength(minlengthValidation)]], title: ['mon titre de sondage', [Validators.required, Validators.minLength(minlengthValidation)]],
creatorPseudo: ['', [Validators.required]], creatorPseudo: ['', [Validators.required]],
created_at: [new Date(), [Validators.required]], created_at: [new Date(), [Validators.required]],
creatorEmail: ['', [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> { public createPoll(): Promise<any> {
this.toastService.display('sending...'); this.toastService.display('sending...');
console.log('this.form', this.form); console.log('createPoll this.form', this.form);
const newpoll = this.newPollFromForm(); const newpoll = this.newPollFromForm();
return this.apiService.createPoll(newpoll).then( return this.apiService.createPoll(newpoll).then(
(resp: any) => { (resp: any) => {
@ -395,8 +398,12 @@ export class PollService implements Resolve<Poll> {
console.log('TODO fill admin_key'); console.log('TODO fill admin_key');
console.log('resp', resp); console.log('resp', resp);
this.admin_key = resp.data.poll.admin_key; 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);
}
); );
} }

View File

@ -47,7 +47,7 @@ export class StorageService {
constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) { constructor(public dateUtilities: DateUtilitiesService, private toastService: ToastService) {
if (environment.autofill_participation) { 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: 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(new Poll(new Owner(), 'Démo: Atelier cuisine du quartier', 'aujourdhui-ou-demain'));
this.userPolls.push( this.userPolls.push(

View File

@ -21,8 +21,7 @@ export class StepFourComponent implements OnInit {
ngOnInit(): void {} ngOnInit(): void {}
createPoll() { createPoll() {
let apiData = this.pollService.newPollFromForm(); this.pollService.createPoll().then((resp) => {
this.apiService.createPoll(apiData).then((resp) => {
this.router.navigate(['administration/success']); this.router.navigate(['administration/success']);
}); });
} }

View File

@ -10,7 +10,7 @@ endpoints.baseHref = apiV1.baseHref;
export const environment = { export const environment = {
frontDomain: 'http://127.0.0.1:4200', frontDomain: 'http://127.0.0.1:4200',
production: false, production: false,
display_routes: false, // demo paths to test polls display_routes: true, // demo paths to test polls
autofill_creation: true, autofill_creation: true,
advanced_options_display: true, advanced_options_display: true,
autofill_participation: true, autofill_participation: true,