import { Controller , Body , Session , Post , Get , UseGuards , Param , Delete , Headers , Query } from '@nestjs/common' ; import { AuthGuard } from '@nestjs/passport' ; import { EshopService } from './eshop.service' ; import { ContactDto } from './dto/contact.dto' ; import { PageDto } from './dto/page.dto' ; import { RolesGuard } from '../auth/roles.guard' ; import { Page } from './models/page.model' ; import { Theme } from './models/theme.model' ; import { Config } from './models/config.model' ; @ Controller ( 'api/eshop' ) export class EshopController { constructor ( private eshopService ) { } @ Get ( '/config' ) getConfig ( @ Session ( ) session ) { return this . eshopService . getConfig ( session ) ; } @ Post ( '/contact' ) sendContact ( @ Body ( ) contactDto , @ Session ( ) session , @ Headers ( 'lang' ) lang ) { this . eshopService . sendContact ( contactDto , session . cart , lang ) ; } @ Get ( '/page/all' ) getPages ( @ Headers ( 'lang' ) lang , @ Query ( 'titles' ) titles ) { return this . eshopService . getPages ( lang , titles ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Post ( '/page' ) addOrEditPage ( @ Body ( ) pageDto ) { return this . eshopService . addOrEditPage ( pageDto ) ; } @ Get ( '/page/:titleUrl' ) getPage ( @ Param ( 'titleUrl' ) titleUrl , @ Headers ( 'lang' ) lang ) { return this . eshopService . getPage ( titleUrl , lang ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Delete ( '/page/:titleUrl' ) deletePage ( @ Param ( 'titleUrl' ) titleUrl ) { return this . eshopService . deletePage ( titleUrl ) ; } @ Get ( '/theme/all' ) getThemes ( ) { return this . eshopService . getThemes ( ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Post ( '/theme' ) addOrEditTheme ( @ Body ( ) themeDto ) { return this . eshopService . addOrEditTheme ( themeDto ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Delete ( '/theme/:titleUrl' ) deleteTheme ( @ Param ( 'titleUrl' ) titleUrl ) { return this . eshopService . deleteTheme ( titleUrl ) ; } @ Get ( '/config/all' ) getConfigs ( ) { return this . eshopService . getConfigs ( ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Post ( '/config' ) addOrEditConfig ( @ Body ( ) configDto ) { return this . eshopService . addOrEditConfig ( configDto ) ; } @ UseGuards ( AuthGuard ( 'jwt' ) , RolesGuard ) @ Delete ( '/config/:titleUrl' ) deleteConfig ( @ Param ( 'titleUrl' ) titleUrl ) { return this . eshopService . deleteConfig ( titleUrl ) ; } }