Skip to content

Instantly share code, notes, and snippets.

View coderkan's full-sized avatar
🏠
Working from home

Erkan Güzeler coderkan

🏠
Working from home
View GitHub Profile
@coderkan
coderkan / axios-all-example.js
Created October 31, 2021 19:08
axios-all-example
let reqOne = axios.get('https://api.github.com/repos/stedolan/jq/commits');
let reqTwo = axios.get('https://api.github.com/repos/coderkan/spring-boot-redis-cache/commits');
axios.all([reqOne, reqTwo]).then(axios.spread((…res) => {
 console.log(res[0]);
 console.log(res[1]);
 // you can also set your states.
this.setState(
{
  reqOneCount: res[0].data.length,
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
</head>
<body>
<h1>Date Range Example</h1>

Git Commit Template

type : Refactor the coupon UI (Also you can mention related issues like #171)
	# Type can be
	# feat (new feature)
	# fix (bug fix)
	# refactor (refactoring production code)
	# style (formatting, missing semi colons, etc; no code change)
	# docs (changes to documentation)
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"],
providers: [EmployeeService],
})
export class AppComponent implements OnInit {
title = "http-interceptor-fakebackend";
employes: any[];
employeeName = "";
<div class="card-container">
<div class="card-container" style="display: block;">
<p *ngFor="let emp of employes" class="card">
<img src="{{ emp.emp_avatar }}" />
<span>{{ emp.full_name }} </span>
<span class="unit-name">{{ emp.unit }} </span>
<i (click)="onDeleteAction(emp.id)" class="fa fa-trash delete-icon tooltip"><span class="tooltiptext"> Delete
This Employee</span></i>
</p>
</div>
@Injectable({
providedIn: "root",
})
export class EmployeeService {
constructor(private http: HttpClient) {}
/**
* Get All Employee request.
*/
getAllEmployes(): Observable<any> {
return this.http
@NgModule({
declarations: [
AppComponent
],
imports: [
HttpClientModule,
FormsModule,
ReactiveFormsModule,
BrowserModule
],
@Injectable()
export class FakeBackendHttpInterceptor implements HttpInterceptor {
// default employes json path
private _employeeJsonPath = "assets/employes.json";
constructor(private http: HttpClient) {}
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
return this.handleRequests(req, next);
if (url.match(/\/employes\/.*/) && method === "DELETE") {
const empId = this.getEmployeeId(url);
return of(new HttpResponse({ status: 200, body: empId })).pipe(
delay(500)
);
}
getEmployeeId(url: any) {
const urlValues = url.split("/");
return urlValues[urlValues.length - 1];
}
if (url.endsWith("/employes") && method === "POST") {
const { body } = req.clone();
// assign a new uuid to new employee
body.id = uuidv4();
return of(new HttpResponse({ status: 200, body })).pipe(delay(500));
}