/
Gronik4
/
Basic_RxJs_methods_and_operators
Обзор
Документация
Войти
/
Gronik4
/
Basic_RxJs_methods_and_operators
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/data/data.service.ts
48 строк
1 KB
Gronik4
Fixed small error
04 ноя 2025, 10:41
04 ноя 2025, 10:41
1389f17
Код
Авторство
О чём код?
import { Injectable } from '@nestjs/common'; import axios from 'axios'; import { firstValueFrom, from, map, Observable, take, toArray } from 'rxjs'; import * as dataParam from './interfaces/data-param'; export enum URepo { GH = 'gh', GL = 'gl', } @Injectable() export class DataService { private readonly ghUrl = 'https://api.github.com/search/repositories?q='; private readonly glUrl = 'https://gitlab.com/api/v4/projects?search='; private getGitRepo( text: string, count: number, flag: URepo, ): Observable<any> { const url = flag === URepo.GH ? this.ghUrl : this.glUrl; return from(axios.get(`${url}${text}`)) .pipe( // eslint-disable-next-line @typescript-eslint/no-unsafe-argument map((res: any) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access const items = res.data.items || []; // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access return items.slice(0, count) as dataParam.GitHubRepoBase[]; }), ) .pipe(take(count)); } async searchRepo( text: string, count: number, flag: URepo, ): Promise<dataParam.GitHubRepoBase[]> { console.log('nub= ', count); const data$ = this.getGitRepo(text, count, flag).pipe( toArray(), ) as Observable<dataParam.GitHubRepoBase[]>; data$.subscribe(() => {}); return await firstValueFrom(data$); } }