1
1
import { inject , Injectable } from '@angular/core' ;
2
- import { map } from 'rxjs' ;
2
+ import { map , tap } from 'rxjs' ;
3
3
import { NotionBlock , NotionDatabaseItem } from './../types' ;
4
4
import { NotionHttpService } from './http-notion.service' ;
5
5
@@ -9,12 +9,32 @@ import { NotionHttpService } from './http-notion.service';
9
9
export class NgxNotionService {
10
10
private http = inject ( NotionHttpService ) ;
11
11
12
+ /**
13
+ * Fetches the items of a Notion database by its ID.
14
+ *
15
+ * @param {string } id - The ID of the Notion database to fetch the items for.
16
+ * @returns {Observable<{ data: NotionDatabaseItem[] | null, error: string | null, isPending: boolean }> }
17
+ * An observable that emits an object containing the database items data, an error message, and a pending status.
18
+ * The database items data is an array of NotionDatabaseItem if available, otherwise null.
19
+ * The error is null if no error occurred, otherwise a string describing the error.
20
+ * The isPending indicates if the request is still in progress.
21
+ */
12
22
public getDatabaseItemsById ( id : string ) {
13
- return this . http . get < NotionDatabaseItem [ ] > (
23
+ return this . http . get < any [ ] > (
14
24
`https://notion-api.splitbee.io/v1/table/${ id } `
15
- ) ;
25
+ )
16
26
}
17
27
28
+ /**
29
+ * Fetches and processes the blocks of a Notion page by its ID.
30
+ *
31
+ * @param {string } id - The ID of the Notion page to fetch the blocks for.
32
+ * @returns {Observable<{ data: NotionBlock[] | null, error: string | null, isPending: boolean }> }
33
+ * An observable that emits an object containing the blocks data, an error message, and a pending status.
34
+ * The blocks data is an array of NotionBlock if available, otherwise null.
35
+ * The error is null if no error occurred, otherwise a string describing the error.
36
+ * The isPending indicates if the request is still in progress.
37
+ */
18
38
public getPageBlocks ( id : string ) {
19
39
return this . http
20
40
. get < NotionBlock [ ] > ( `https://notion-api.splitbee.io/v1/page/${ id } ` )
@@ -25,6 +45,7 @@ export class NgxNotionService {
25
45
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26
46
Object . values ( response . data ) . forEach ( ( key : any ) => {
27
47
if ( key . value ) {
48
+ console . log ( key . value ) ;
28
49
blocks . push ( key . value ) ;
29
50
}
30
51
} ) ;
0 commit comments