NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
90 lines
2.4 KiB
TypeScript
90 lines
2.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthUser } from '../auth/auth.types';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import { RequireBusinessPermission } from '../auth/decorators/require-business-permission.decorator';
|
|
import { BusinessPermissionGuard } from '../auth/guards/business-permission.guard';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import {
|
|
CreateStoreSpecialDto,
|
|
ListStoreSpecialsDto,
|
|
UpdateStoreSpecialDto,
|
|
} from './dto/store-specials.dto';
|
|
import { StoreSpecialsService } from './store-specials.service';
|
|
|
|
@Controller('tenants/:host/store-specials')
|
|
export class PublicStoreSpecialsController {
|
|
constructor(private readonly service: StoreSpecialsService) {}
|
|
|
|
@Get()
|
|
list(@Param('host') host: string) {
|
|
return this.service.listPublic(host);
|
|
}
|
|
}
|
|
|
|
@Controller('businesses/:businessId/store-specials')
|
|
@UseGuards(JwtAuthGuard, BusinessPermissionGuard)
|
|
export class StoreSpecialsController {
|
|
constructor(private readonly service: StoreSpecialsService) {}
|
|
|
|
@Get()
|
|
@RequireBusinessPermission('products.read')
|
|
list(
|
|
@Param('businessId') businessId: string,
|
|
@Query() query: ListStoreSpecialsDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.list(businessId, query, user);
|
|
}
|
|
|
|
@Get(':specialId')
|
|
@RequireBusinessPermission('products.read')
|
|
getOne(
|
|
@Param('businessId') businessId: string,
|
|
@Param('specialId') specialId: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.getOne(businessId, specialId, user);
|
|
}
|
|
|
|
@Post()
|
|
@RequireBusinessPermission('products.update')
|
|
create(
|
|
@Param('businessId') businessId: string,
|
|
@Body() dto: CreateStoreSpecialDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.create(businessId, dto, user);
|
|
}
|
|
|
|
@Patch(':specialId')
|
|
@RequireBusinessPermission('products.update')
|
|
update(
|
|
@Param('businessId') businessId: string,
|
|
@Param('specialId') specialId: string,
|
|
@Body() dto: UpdateStoreSpecialDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.update(businessId, specialId, dto, user);
|
|
}
|
|
|
|
@Delete(':specialId')
|
|
@RequireBusinessPermission('products.update')
|
|
remove(
|
|
@Param('businessId') businessId: string,
|
|
@Param('specialId') specialId: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.remove(businessId, specialId, user);
|
|
}
|
|
}
|