Initial commit: Meshkee CMS API
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, 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 {
|
||||
BatchCreateStoreItemsDto,
|
||||
BatchUpdateStoreItemDiscountsDto,
|
||||
BatchUpdateFestivalRewardsDto,
|
||||
ListPublicStoreItemsDto,
|
||||
ListStoreItemsDto,
|
||||
SyncProductStoreItemVariantsDto,
|
||||
UpdateStoreItemVariantDto,
|
||||
} from './dto/store-items.dto';
|
||||
import { StoreItemsService } from './store-items.service';
|
||||
|
||||
@Controller('businesses/:businessId/store-items')
|
||||
@UseGuards(JwtAuthGuard, BusinessPermissionGuard)
|
||||
export class StoreItemsController {
|
||||
constructor(private readonly service: StoreItemsService) {}
|
||||
|
||||
@Get()
|
||||
@RequireBusinessPermission('products.read')
|
||||
list(
|
||||
@Param('businessId') businessId: string,
|
||||
@Query() query: ListStoreItemsDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.list(businessId, query, user);
|
||||
}
|
||||
|
||||
@Get('by-product/:productId')
|
||||
@RequireBusinessPermission('products.read')
|
||||
getByProduct(
|
||||
@Param('businessId') businessId: string,
|
||||
@Param('productId') productId: string,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.getByProduct(businessId, productId, user);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@RequireBusinessPermission('products.update')
|
||||
batchCreateVariants(
|
||||
@Param('businessId') businessId: string,
|
||||
@Body() dto: BatchCreateStoreItemsDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.batchCreateVariants(businessId, dto, user);
|
||||
}
|
||||
|
||||
@Put('discounts')
|
||||
@RequireBusinessPermission('products.update')
|
||||
updateDiscounts(
|
||||
@Param('businessId') businessId: string,
|
||||
@Body() dto: BatchUpdateStoreItemDiscountsDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.updateDiscounts(businessId, dto, user);
|
||||
}
|
||||
|
||||
@Put('sync')
|
||||
@RequireBusinessPermission('products.update')
|
||||
syncProductVariants(
|
||||
@Param('businessId') businessId: string,
|
||||
@Body() dto: SyncProductStoreItemVariantsDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.syncProductVariants(businessId, dto, user);
|
||||
}
|
||||
|
||||
@Put('festival-rewards')
|
||||
@RequireBusinessPermission('products.update')
|
||||
updateFestivalRewards(
|
||||
@Param('businessId') businessId: string,
|
||||
@Body() dto: BatchUpdateFestivalRewardsDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.updateFestivalRewards(businessId, dto, user);
|
||||
}
|
||||
|
||||
@Patch('variants/:variantId')
|
||||
@RequireBusinessPermission('products.update')
|
||||
updateVariant(
|
||||
@Param('businessId') businessId: string,
|
||||
@Param('variantId') variantId: string,
|
||||
@Body() dto: UpdateStoreItemVariantDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.updateVariant(businessId, variantId, dto, user);
|
||||
}
|
||||
|
||||
@Delete('variants/:variantId')
|
||||
@RequireBusinessPermission('products.update')
|
||||
removeVariant(
|
||||
@Param('businessId') businessId: string,
|
||||
@Param('variantId') variantId: string,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.removeVariant(businessId, variantId, user);
|
||||
}
|
||||
|
||||
@Delete('by-product/:productId')
|
||||
@RequireBusinessPermission('products.update')
|
||||
removeByProduct(
|
||||
@Param('businessId') businessId: string,
|
||||
@Param('productId') productId: string,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.service.removeByProduct(businessId, productId, user);
|
||||
}
|
||||
}
|
||||
|
||||
@Controller('tenants/:host/store-items')
|
||||
export class PublicStoreItemsController {
|
||||
constructor(private readonly service: StoreItemsService) {}
|
||||
|
||||
@Get()
|
||||
list(@Param('host') host: string, @Query() query: ListPublicStoreItemsDto) {
|
||||
return this.service.listPublic(host, query);
|
||||
}
|
||||
|
||||
@Get('by-product/:productId')
|
||||
getByProduct(@Param('host') host: string, @Param('productId') productId: string) {
|
||||
return this.service.getPublicByProduct(host, productId);
|
||||
}
|
||||
|
||||
@Get(':variantId')
|
||||
getVariant(@Param('host') host: string, @Param('variantId') variantId: string) {
|
||||
return this.service.getPublicVariant(host, variantId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user