Open History to see the last commit
1import { HttpResponse } from '@angular/common/http'
2import { delay, of } from 'rxjs'
3import type { Observable } from 'rxjs'
4import type { HttpEvent, HttpInterceptorFn } from '@angular/common/http'
5β
6export const projectsMockInterceptor: HttpInterceptorFn = (
7 req,
8 next,
9): Observable<HttpEvent<unknown>> => {
10 const { url } = req
11β
12 if (url.includes('/api/projects')) {
13 const page = parseInt(
14 new URLSearchParams(req.url.split('?')[1]).get('page') || '0',
15 10,
16 )
17 const pageSize = 10
18β
19 const projects = Array(pageSize)
20 .fill(0)
21 .map((_, i) => {
22 const id = page * pageSize + (i + 1)
23 return {
24 name: 'Project ' + id,
25 id,
26 }
27 })
28β
29 return of(
30 new HttpResponse({
31 status: 200,
32 body: {
33 projects,
34 hasMore: page < 9,
35 },
36 }),
37 ).pipe(delay(1000))
38 }
39 return next(req)
40}