Skip to content

Commit faec3cf

Browse files
committed
docs: notion.service
1 parent 9f33100 commit faec3cf

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

projects/ngx-notion-cms/src/lib/services/notion.service.ts

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { inject, Injectable } from '@angular/core';
2-
import { map } from 'rxjs';
2+
import { map, tap } from 'rxjs';
33
import { NotionBlock, NotionDatabaseItem } from './../types';
44
import { NotionHttpService } from './http-notion.service';
55

@@ -9,12 +9,32 @@ import { NotionHttpService } from './http-notion.service';
99
export class NgxNotionService {
1010
private http = inject(NotionHttpService);
1111

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+
*/
1222
public getDatabaseItemsById(id: string) {
13-
return this.http.get<NotionDatabaseItem[]>(
23+
return this.http.get<any[]>(
1424
`https://notion-api.splitbee.io/v1/table/${id}`
15-
);
25+
)
1626
}
1727

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+
*/
1838
public getPageBlocks(id: string) {
1939
return this.http
2040
.get<NotionBlock[]>(`https://notion-api.splitbee.io/v1/page/${id}`)
@@ -25,6 +45,7 @@ export class NgxNotionService {
2545
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2646
Object.values(response.data).forEach((key: any) => {
2747
if (key.value) {
48+
console.log(key.value);
2849
blocks.push(key.value);
2950
}
3051
});

0 commit comments

Comments
 (0)