Files
backend/src/public/public.controller.ts
T

88 lines
2.4 KiB
TypeScript

import { Body, Controller, Get, Param, ParseIntPipe, Post, Query } from '@nestjs/common';
import { SubscribeDto } from './dto/subscribe.dto';
import { PublicService } from './public.service';
@Controller('public')
export class PublicController {
constructor(private readonly publicService: PublicService) {}
@Get('stores')
listStores() {
return this.publicService.listStores();
}
@Get('products')
listProducts(
@Query('storeId') storeId?: string,
@Query('storeSlug') storeSlug?: string,
@Query('name') name?: string,
@Query('categoryId') categoryId?: string,
@Query('minPrice') minPrice?: string,
@Query('maxPrice') maxPrice?: string,
) {
const parsedCategoryId =
categoryId !== undefined && categoryId !== ''
? Number(categoryId)
: undefined;
const parsedMin =
minPrice !== undefined && minPrice !== '' ? Number(minPrice) : undefined;
const parsedMax =
maxPrice !== undefined && maxPrice !== '' ? Number(maxPrice) : undefined;
return this.publicService.listProducts({
storeId,
storeSlug,
name,
categoryId:
parsedCategoryId !== undefined && Number.isFinite(parsedCategoryId)
? parsedCategoryId
: undefined,
minPrice:
parsedMin !== undefined && Number.isFinite(parsedMin)
? parsedMin
: undefined,
maxPrice:
parsedMax !== undefined && Number.isFinite(parsedMax)
? parsedMax
: undefined,
});
}
@Get('products/:id')
findProduct(@Param('id', ParseIntPipe) id: number) {
return this.publicService.findProduct(id);
}
@Get('categories')
listCategories(@Query('storeSlug') storeSlug?: string) {
return this.publicService.listCategories(storeSlug);
}
@Get('search')
search(
@Query('q') q?: string,
@Query('storeSlug') storeSlug?: string,
@Query('limit') limit?: number,
) {
return this.publicService.search({
q,
storeSlug,
limit: limit !== undefined ? Number(limit) : undefined,
});
}
@Get('blogs')
listBlogs(@Query('storeSlug') storeSlug?: string) {
return this.publicService.listBlogs(storeSlug);
}
@Get('website-slots')
listWebsiteSlots(@Query('storeSlug') storeSlug?: string) {
return this.publicService.listWebsiteSlots(storeSlug);
}
@Post('subscribe')
subscribe(@Body() dto: SubscribeDto) {
return this.publicService.subscribe(dto.cellNumber);
}
}