|
|
|
@ -6,22 +6,28 @@ import { Answer } from '../enums/answer.enum';
|
|
|
|
|
import { Poll } from '../models/poll.model';
|
|
|
|
|
import { HttpHeaders } from '@angular/common/http';
|
|
|
|
|
|
|
|
|
|
const apiVersion = environment.api.versionToUse;
|
|
|
|
|
const currentApiRoutes = environment.api.version[apiVersion];
|
|
|
|
|
const apiBaseHref = environment.api.version[apiVersion].baseHref;
|
|
|
|
|
|
|
|
|
|
const apiEndpoints = environment.api.endpoints;
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root',
|
|
|
|
|
})
|
|
|
|
|
export class ApiService {
|
|
|
|
|
private axiosInstance: AxiosInstance;
|
|
|
|
|
|
|
|
|
|
private readonly pollsEndpoint = environment.api.endpoints.polls.name;
|
|
|
|
|
private readonly answersEndpoint = environment.api.endpoints.polls.answers.name;
|
|
|
|
|
private readonly commentsEndpoint = environment.api.endpoints.polls.comments.name;
|
|
|
|
|
private readonly slugsEndpoint = environment.api.endpoints.polls.slugs.name;
|
|
|
|
|
private readonly usersEndpoint = environment.api.endpoints.users.name;
|
|
|
|
|
private readonly usersPollsEndpoint = environment.api.endpoints.users.polls.name;
|
|
|
|
|
private readonly usersPollsSendEmailEndpoint = environment.api.endpoints.users.polls.sendEmail.name;
|
|
|
|
|
private readonly pollsEndpoint = apiEndpoints.polls.name;
|
|
|
|
|
private readonly answersEndpoint = apiEndpoints.polls.answers.name;
|
|
|
|
|
private readonly commentsEndpoint = apiEndpoints.polls.comments.name;
|
|
|
|
|
private readonly slugsEndpoint = apiEndpoints.polls.slugs.name;
|
|
|
|
|
private readonly usersEndpoint = apiEndpoints.users.name;
|
|
|
|
|
private readonly usersPollsEndpoint = apiEndpoints.users.polls.name;
|
|
|
|
|
private readonly usersPollsSendEmailEndpoint = apiEndpoints.users.polls.sendEmail.name;
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.axiosInstance = axios.create({ baseURL: environment.api.baseHref });
|
|
|
|
|
this.axiosInstance = axios.create({ baseURL: apiBaseHref });
|
|
|
|
|
this.axiosInstance.defaults.timeout = 2500;
|
|
|
|
|
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
|
|
|
|
|
}
|
|
|
|
@ -31,7 +37,8 @@ export class ApiService {
|
|
|
|
|
//////////////////////
|
|
|
|
|
public async createPoll(poll: Poll): Promise<string> {
|
|
|
|
|
try {
|
|
|
|
|
return await this.axiosInstance.post(`${this.pollsEndpoint}`, poll);
|
|
|
|
|
console.log('currentApiRoutes', currentApiRoutes);
|
|
|
|
|
return await this.axiosInstance.post(`${apiBaseHref}${currentApiRoutes['api_new_poll']}`, poll);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
ApiService.handleError(error);
|
|
|
|
|
}
|
|
|
|
|