diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 4b72865d..a38f0d19 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; -import axios, { AxiosInstance, AxiosResponse } from 'axios'; +import { AxiosInstance, AxiosResponse } from 'axios'; import { environment } from 'src/environments/environment'; import { Answer } from '../enums/answer.enum'; import { Poll } from '../models/poll.model'; import { HttpClient } from '@angular/common/http'; -import { Observable, Subscription } from 'rxjs'; +import { Subscription } from 'rxjs'; import { ToastService } from './toast.service'; import { LoaderService } from './loader.service'; import { Stack } from '../models/stack.model'; @@ -15,6 +15,7 @@ const currentApiRoutes = environment.api.version[apiVersion]; const apiBaseHref = environment.api.version[apiVersion].baseHref; const apiEndpoints = environment.api.endpoints; +let axios = require('axios'); class PollDTO {} @@ -67,7 +68,7 @@ export class ApiService { Charset: 'UTF-8', // 'Content-Type': 'application/json', // Accept: 'application/json', - 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Origin': '^https?://(localhost|127.0.0.1)(:[0-9]+)?$', 'Content-Type': 'application/json', // mode: 'no-cors', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', @@ -82,17 +83,23 @@ export class ApiService { } /** - * + * create a new poll * @param poll */ public async createPoll(poll: PollDTO): Promise { // this.loaderService.setStatus(true); + + let axiosConf = { + method: 'post', + url: `${this.baseHref}${currentApiRoutes['api_new_poll']}`, + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify(poll), + }; console.log('apiservice createPoll config', poll); - return this.axiosInstance.post( - `${this.baseHref}${currentApiRoutes['api_new_poll']}`, - poll - // ApiService.makeHeaders() - ); + + return this.axiosInstance.post(`${this.baseHref}${currentApiRoutes['api_new_poll']}`, poll); } /** @@ -243,9 +250,11 @@ export class ApiService { ApiService.handleError(error); } } + public findMyPollsByEmail(email: string): Promise { return this.axiosInstance.get(`${this.baseHref}/poll/owner/${email}`); } + public async updateAnswer(slug: string, choiceLabel: string, pseudo: string, answer: Answer): Promise { try { return await this.axiosInstance.patch(`${this.baseHref}/${slug}${this.answersEndpoint}`, { @@ -257,6 +266,7 @@ export class ApiService { ApiService.handleError(error); } } + //////////// // DELETE // @@ -317,6 +327,7 @@ export class ApiService { console.log(error.config); // this.loaderService.setStatus(false); } + public ousideHandleError(error) { // this.loaderService.setStatus(true); if (error.response) { diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index f36a1339..5680ec7f 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -608,10 +608,10 @@ export class PollService implements Resolve { if (this._poll && this._poll.getValue) { const polltemp = this._poll.getValue(); if (polltemp) { - url = `${environment.frontDomain}#/poll/${polltemp.custom_url}/consultation`; + url = `${environment.frontDomain}/#/poll/${polltemp.custom_url}/consultation`; } } else { - url = `${environment.frontDomain}#/poll/${this.form.value.custom_url}/consultation`; + url = `${environment.frontDomain}/#/poll/${this.form.value.custom_url}/consultation`; } // TODO handle pass access @@ -625,10 +625,10 @@ export class PollService implements Resolve { if (this._poll && this._poll.getValue) { const polltemp = this._poll.getValue(); if (polltemp) { - url = `${environment.frontDomain}#/admin/${polltemp.admin_key}`; + url = `${environment.frontDomain}/#/admin/${polltemp.admin_key}`; } } else { - url = `${environment.frontDomain}#/admin/${this.form.value.admin_key}`; + url = `${environment.frontDomain}/#/admin/${this.form.value.admin_key}`; } return url; } diff --git a/src/environments/endpoints.ts b/src/environments/endpoints.ts index 01f50335..775786bf 100644 --- a/src/environments/endpoints.ts +++ b/src/environments/endpoints.ts @@ -1,15 +1,18 @@ export const backendApiUrlsInDev = { // local: 'http://tktest.lan/api/v1', // remote: 'http://tktest.lan/api/v1', - local: 'http://localhost:8000/api/v1', + // local: 'http://localhost:8000/api/v1', + local: 'http://www.tk.lan/index.php/api/v1', // local: 'https://framadate-api.cipherbliss.com/api/v1', - remote: 'http://localhost:8000/api/v1', + // remote: 'http://localhost:8000/api/v1', + remote: 'http://www.tk.lan/index.php/api/v1', // remote: 'https://framadate-api.cipherbliss.com/api/v1', }; export const apiV1 = { - baseHref: 'http://localhost:8000/api/v1', + // baseHref: 'http://localhost:8000/api/v1', // local "symfony serve" live server + baseHref: 'http://www.tk.lan/index.php/api/v1', // local apache2 server // baseHref: 'http://tktest.lan/api/v1', - // baseHref: 'https://framadate-api.cipherbliss.com/api/v1', + // baseHref: 'https://framadate-api.cipherbliss.com/api/v1', // demo preprod api_new_poll: '/poll/', api_get_poll: '/poll/{id}', api_new_vote_stack: '/vote-stack', diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 123d0beb..6fc4397a 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,18 +1,21 @@ +const productionBaseUrl = 'https://framadate-api.cipherbliss.com'; // set this to your production domain +const apiVersion = 'v1'; + const backendApiUrlsInDev = { - local: '/api/v1', - remote: 'https://framadate-api.cipherbliss.com/api/v1', + local: `/api/${apiVersion}`, + remote: `${productionBaseUrl}/api/${apiVersion}`, }; const apiV1 = { - baseHref: 'https://framadate-api.cipherbliss.com/api/v1', + baseHref: `${productionBaseUrl}/api/${apiVersion}`, api_new_poll: '/poll/', api_get_poll: '/poll/{id}', api_new_vote_stack: '/vote-stack', - 'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}', + 'api_test-mail-poll': `/api/${apiVersion}/poll/mail/test-mail-poll/{emailChoice}`, 'app.swagger': '/api/doc.json', }; export const environment = { - frontDomain: 'https://framadate-api.cipherbliss.com', + frontDomain: productionBaseUrl, production: true, display_routes: false, showDemoWarning: false, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index dc948579..e92c29de 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -10,13 +10,13 @@ endpoints.baseHref = apiV1.baseHref; export const environment = { frontDomain: 'http://127.0.0.1:4200', production: false, - display_routes: true, // demo paths to test polls + display_routes: false, // demo paths to test polls autofill_creation: true, advanced_options_display: false, autofill_participation: false, showDemoWarning: false, - autoSendNewPoll: false, - showStepperShortcuts: false, + autoSendNewPoll: true, + showStepperShortcuts: true, interval_days_default: 7, expiresDaysDelay: 60, maxCountOfAnswers: 300,