feat: complete admin panel and backend admin api migration
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import { Body, Controller, Delete, Get, HttpCode, Param, Post, Put } from '@nestjs/common';
|
||||
import { AdminPromotionsService } from './admin-promotions.service';
|
||||
import { TableQueryDto } from '../admin-table/table-query.dto';
|
||||
import { RequirePermission } from '../auth/guards';
|
||||
|
||||
/**
|
||||
* Legacy endpoints:
|
||||
* GET/POST/PUT/DELETE product/variant/promotion -> PromotionController
|
||||
* GET /autopromotion -> the auto-discount screen
|
||||
* GET/POST/DELETE /ignore -> views/offersIgnore
|
||||
*/
|
||||
@Controller('admin/promotions')
|
||||
export class AdminPromotionsController {
|
||||
constructor(private readonly promotions: AdminPromotionsService) {}
|
||||
|
||||
@Post('list')
|
||||
@HttpCode(200)
|
||||
@RequirePermission('offers.list')
|
||||
list(@Body() query: TableQueryDto) {
|
||||
return this.promotions.list(query);
|
||||
}
|
||||
|
||||
@Get('scope-options')
|
||||
@RequirePermission('offers.list')
|
||||
scopeOptions() {
|
||||
return this.promotions.scopeOptions();
|
||||
}
|
||||
|
||||
@Get('usage-options')
|
||||
@RequirePermission('offers.list')
|
||||
usageOptions() {
|
||||
return this.promotions.usageOptions();
|
||||
}
|
||||
|
||||
@Get('auto')
|
||||
@RequirePermission('offers.autopromotion')
|
||||
getAutoPromotion() {
|
||||
return this.promotions.getAutoPromotion();
|
||||
}
|
||||
|
||||
@Post('auto')
|
||||
@HttpCode(200)
|
||||
@RequirePermission('offers.autopromotion')
|
||||
setAutoPromotion(@Body() body: { state?: boolean; discount_percent?: number | string }) {
|
||||
return this.promotions.setAutoPromotion(body);
|
||||
}
|
||||
|
||||
// ── exclusions ────────────────────────────────────────────────────
|
||||
@Get('exclusions')
|
||||
@RequirePermission('offersIgnore')
|
||||
listExclusions() {
|
||||
return this.promotions.listExclusions();
|
||||
}
|
||||
|
||||
@Post('exclusions')
|
||||
@HttpCode(200)
|
||||
@RequirePermission('offersIgnore')
|
||||
createExclusion(@Body() body: { type: number; item_id?: string[] }) {
|
||||
return this.promotions.createExclusion(body);
|
||||
}
|
||||
|
||||
@Delete('exclusions/:id')
|
||||
@RequirePermission('offersIgnore')
|
||||
removeExclusion(@Param('id') id: string) {
|
||||
return this.promotions.removeExclusion(id);
|
||||
}
|
||||
|
||||
// ── promotions ────────────────────────────────────────────────────
|
||||
@Post()
|
||||
@HttpCode(200)
|
||||
@RequirePermission('offers.create')
|
||||
create(@Body() data: Record<string, unknown>) {
|
||||
return this.promotions.create(data);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@RequirePermission('offers.list')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.promotions.findOne(id);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@RequirePermission('offers.list.edit')
|
||||
update(@Param('id') id: string, @Body() data: Record<string, unknown>) {
|
||||
return this.promotions.update(id, data);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@RequirePermission('offers.list.edit')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.promotions.remove(id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user