mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
76 lines
2.0 KiB
TypeScript
76 lines
2.0 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 {
|
|
AddCartItemDto,
|
|
CheckoutCartDto,
|
|
UpdateCartItemDto,
|
|
} from './dto/cart.dto';
|
|
import { CartService } from './cart.service';
|
|
|
|
@Controller('businesses/:businessId/cart')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class CartController {
|
|
constructor(private readonly service: CartService) {}
|
|
|
|
@Get()
|
|
getCart(@Param('businessId') businessId: string, @CurrentUser() user: AuthUser) {
|
|
return this.service.getCart(businessId, user);
|
|
}
|
|
|
|
@Post('items')
|
|
addItem(
|
|
@Param('businessId') businessId: string,
|
|
@Body() dto: AddCartItemDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.addItem(businessId, dto, user);
|
|
}
|
|
|
|
@Patch('items/:itemId')
|
|
updateItem(
|
|
@Param('businessId') businessId: string,
|
|
@Param('itemId') itemId: string,
|
|
@Body() dto: UpdateCartItemDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.updateItem(businessId, itemId, dto, user);
|
|
}
|
|
|
|
@Delete('items/:itemId')
|
|
removeItem(
|
|
@Param('businessId') businessId: string,
|
|
@Param('itemId') itemId: string,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.removeItem(businessId, itemId, user);
|
|
}
|
|
|
|
@Delete()
|
|
clear(@Param('businessId') businessId: string, @CurrentUser() user: AuthUser) {
|
|
return this.service.clear(businessId, user);
|
|
}
|
|
|
|
@Post('checkout')
|
|
checkout(
|
|
@Param('businessId') businessId: string,
|
|
@Body() dto: CheckoutCartDto,
|
|
@CurrentUser() user: AuthUser,
|
|
) {
|
|
return this.service.checkout(businessId, dto, user);
|
|
}
|
|
}
|