📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
new route to get categories
Yevhenii Ka28d5ed41974
diff --git a/src/marketplace/categories/categories.controller.ts b/src/marketplace/categories/categories.controller.tsindex 965d167fc..864cbc2f1 100644--- a/src/marketplace/categories/categories.controller.ts+++ b/src/marketplace/categories/categories.controller.ts@@ -8,12 +8,14 @@ import {Param,Patch,Post,+ Query,} from '@nestjs/common'import { ApiTags } from '@nestjs/swagger'import { CategoriesService } from './categories.service'import { Category } from './category.entity'import { CreateCategory } from './dtos/create-category.dto'import { DeleteCategoryParams } from './dtos/delete-category-params.dto'+import { GetCategoriesQueries } from './dtos/get-categories-queries.dto'import { GetCategoryParams } from './dtos/get-category-params.dto'import { UpdateCategoryParams } from './dtos/update-category-params.dto'import { UpdateCategory } from './dtos/update-category.dto'@@ -24,6 +26,19 @@ import { ISaveCategory } from './interfaces/save-category.interface'export class CategoriesController {constructor(private readonly categoriesService: CategoriesService) {}+ @Get()+ async getCategories(@Query() queries: GetCategoriesQueries): Promise<{+ categories: Category[]+ count: number+ }> {+ const [categories, count] = await this.categoriesService.findAndCount({+ skip: queries.offset || 0,+ take: queries.limit > 100 ? 25 : queries.limit || 25,+ })++ return { categories, count }+ }+@Get(':categoryId')async getCategory(@Param() params: GetCategoryParams): Promise<Category> {const category = await this.categoriesService.findById(params.categoryId)diff --git a/src/marketplace/categories/categories.service.ts b/src/marketplace/categories/categories.service.tsindex 5e282698b..3dedafd51 100644--- a/src/marketplace/categories/categories.service.ts+++ b/src/marketplace/categories/categories.service.ts@@ -1,6 +1,6 @@import { Injectable } from '@nestjs/common'import { InjectRepository } from '@nestjs/typeorm'-import { FindOneOptions, Repository } from 'typeorm'+import { FindManyOptions, FindOneOptions, Repository } from 'typeorm'import { Category } from './category.entity'import { ICreateCategory } from './interfaces/create-category.interface'import { ISaveCategory } from './interfaces/save-category.interface'@@ -40,4 +40,10 @@ export class CategoriesService {async delete(id: number): Promise<void> {await this.categoryRepository.delete({ id })}++ async findAndCount(+ options: FindManyOptions<Category>,+ ): Promise<[Category[], number]> {+ return await this.categoryRepository.findAndCount({ ...options })+ }}diff --git a/src/marketplace/categories/dtos/get-categories-queries.dto.ts b/src/marketplace/categories/dtos/get-categories-queries.dto.tsnew file mode 100644index 000000000..8f604366e--- /dev/null+++ b/src/marketplace/categories/dtos/get-categories-queries.dto.ts@@ -0,0 +1,4 @@+export class GetCategoriesQueries {+ readonly offset?: number+ readonly limit?: number+}