refactor: use object RequestData
This commit is contained in:
@ -11,57 +11,44 @@ export interface RequestData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class RequestBuilder {
|
export class RequestBuilder {
|
||||||
private endpoint: string = '';
|
private result: RequestData = Object.create({});
|
||||||
private queryParams: Record<string, string | number | boolean | Array<any> | null> | null = null;
|
|
||||||
private httpHeaders: HttpHeaders = new HttpHeaders();
|
|
||||||
private data: any = null;
|
|
||||||
private silenceMode: boolean = false;
|
|
||||||
private withCredentials: boolean = false;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public setEndpoint(endpoint: string): this {
|
public setEndpoint(endpoint: string): this {
|
||||||
this.endpoint = endpoint;
|
this.result.endpoint = endpoint;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setQueryParams(queryParams: Record<string, string | number | boolean | Array<any> | null>): RequestBuilder {
|
public setQueryParams(queryParams: Record<string, string | number | boolean | Array<any> | null>): RequestBuilder {
|
||||||
this.queryParams = queryParams;
|
this.result.queryParams = queryParams;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addHeaders(headers: Record<string, string>): RequestBuilder {
|
public addHeaders(headers: Record<string, string>): RequestBuilder {
|
||||||
Object.keys(headers).forEach(key => {
|
Object.keys(headers).forEach(key => {
|
||||||
this.httpHeaders = this.httpHeaders.set(key, headers[key]);
|
this.result.httpHeaders = this.result.httpHeaders.set(key, headers[key]);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setData(data: any): RequestBuilder {
|
public setData(data: any): RequestBuilder {
|
||||||
this.data = data;
|
this.result.data = data;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setSilenceMode(silence: boolean = true): RequestBuilder {
|
public setSilenceMode(silence: boolean = true): RequestBuilder {
|
||||||
this.silenceMode = silence;
|
this.result.silenceMode = silence;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setWithCredentials(credentials: boolean = true): RequestBuilder {
|
public setWithCredentials(credentials: boolean = true): RequestBuilder {
|
||||||
this.withCredentials = credentials;
|
this.result.withCredentials = credentials;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get build(): RequestData {
|
public get build(): RequestData {
|
||||||
return {
|
return this.result;
|
||||||
endpoint: this.endpoint,
|
|
||||||
queryParams: this.queryParams,
|
|
||||||
httpHeaders: this.httpHeaders,
|
|
||||||
data: this.data,
|
|
||||||
silenceMode: this.silenceMode,
|
|
||||||
withCredentials: this.withCredentials,
|
|
||||||
needAuth: false
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user