mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
add fetching a poll with a pass hash
This commit is contained in:
parent
2562b21d2f
commit
3850f3811c
@ -40,7 +40,6 @@ export class ApiService {
|
|||||||
this.axiosInstance.defaults.headers.post['Charset'] = 'UTF-8';
|
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-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS';
|
||||||
this.axiosInstance.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
|
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<Poll | undefined> {
|
public async getPollBySlug(slug: string): Promise<Poll | undefined> {
|
||||||
// TODO: identifier should be decided according to backend : Id || Slug ?
|
|
||||||
try {
|
try {
|
||||||
// TODO: this interceptor should be avoided if backends returns the good object
|
// TODO: this interceptor should be avoided if backends returns the good object
|
||||||
const adapterInterceptor: number = this.axiosInstance.interceptors.response.use(
|
const adapterInterceptor: number = this.axiosInstance.interceptors.response.use(
|
||||||
@ -148,6 +146,23 @@ export class ApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getPollBySlugWithHash(slug: string, hash: string): Promise<Poll | undefined> {
|
||||||
|
try {
|
||||||
|
const response: AxiosResponse<Poll> = await this.axiosInstance.get<Poll>(
|
||||||
|
`${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<boolean> {
|
public async getSlug(slug: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
// TODO: scenario should be : if we can get this slug, it exists. if not, it doesn't. It's just a GET.
|
// TODO: scenario should be : if we can get this slug, it exists. if not, it doesn't. It's just a GET.
|
||||||
|
@ -76,6 +76,14 @@ export class PollService implements Resolve<Poll> {
|
|||||||
this.updateCurrentPoll(poll);
|
this.updateCurrentPoll(poll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async loadPollBySlugWithPasswordHash(slug: string, hash: string): Promise<void> {
|
||||||
|
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 {
|
public updateCurrentPoll(poll: Poll): void {
|
||||||
this._poll.next(poll);
|
this._poll.next(poll);
|
||||||
|
Loading…
Reference in New Issue
Block a user