diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 3bf4faeb..6846365b 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -40,7 +40,6 @@ export class ApiService { this.axiosInstance.defaults.headers.post['Charset'] = 'UTF-8'; this.axiosInstance.defaults.headers.post['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'; this.axiosInstance.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; - console.log('this.axiosInstance.defaults.headers', this.axiosInstance.defaults.headers); } ////////////////////// @@ -117,7 +116,6 @@ export class ApiService { } public async getPollBySlug(slug: string): Promise { - // TODO: identifier should be decided according to backend : Id || Slug ? try { // TODO: this interceptor should be avoided if backends returns the good object const adapterInterceptor: number = this.axiosInstance.interceptors.response.use( @@ -148,6 +146,23 @@ export class ApiService { } } + public async getPollBySlugWithHash(slug: string, hash: string): Promise { + try { + const response: AxiosResponse = await this.axiosInstance.get( + `${this.pollsEndpoint}/${slug}/pass/${hash}` + ); + console.log('fetch API : asking for poll with slug=' + slug, { response }); + + return response && response.data && !Array.isArray(response.data) ? response.data : undefined; + } catch (error) { + if (error.response?.status === 404) { + return undefined; + } else { + ApiService.handleError(error); + } + } + } + public async getSlug(slug: string): Promise { try { // TODO: scenario should be : if we can get this slug, it exists. if not, it doesn't. It's just a GET. diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index e8d16e15..3526c125 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -76,6 +76,14 @@ export class PollService implements Resolve { this.updateCurrentPoll(poll); } } + public async loadPollBySlugWithPasswordHash(slug: string, hash: string): Promise { + console.log('slug', slug); + if (slug) { + const poll: Poll | undefined = await this.apiService.getPollBySlugWithHash(slug, hash); + console.log({ loadPollBySlugResponse: poll }); + this.updateCurrentPoll(poll); + } + } public updateCurrentPoll(poll: Poll): void { this._poll.next(poll);