cdc4b82931
HQ 指定一张活动图为勾选主合伙人合成 PNG/zip;城市合伙人页增加快链与单下/导出。 Co-authored-by: Cursor <cursoragent@cursor.com>
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, Put, Query, Res, UseGuards, BadRequestException } from '@nestjs/common';
|
|
import type { Response } from 'express';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import { HqPermissionGuard, RequireHqPermissions } from '../../common/guards/hq-permission.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { ActivityPosterService } from './activity-poster.service';
|
|
import {
|
|
ActivityPosterPackDto,
|
|
ActivityPosterQueryDto,
|
|
UpdateActivityPosterStatusDto,
|
|
UpsertActivityPosterDto,
|
|
} from './dto/activity-poster.dto';
|
|
|
|
@Controller('admin/activity-posters')
|
|
@UseGuards(HqAuthGuard, HqPermissionGuard)
|
|
@RequireHqPermissions('activity_posters')
|
|
export class AdminActivityPostersController {
|
|
constructor(private readonly service: ActivityPosterService) {}
|
|
|
|
@Get()
|
|
list(@Query() query: ActivityPosterQueryDto) {
|
|
return this.service.adminList(query);
|
|
}
|
|
|
|
@Get(':id/image')
|
|
async image(
|
|
@Param('id') id: string,
|
|
@Query('partnerId') partnerId: string,
|
|
@Res() res: Response,
|
|
) {
|
|
if (!partnerId || !/^\d+$/.test(partnerId.trim())) {
|
|
throw new BadRequestException('请指定合伙人');
|
|
}
|
|
const { buffer, fileName } = await this.service.composeForHqPartner(BigInt(partnerId.trim()), BigInt(id));
|
|
res.setHeader('Content-Type', 'image/png');
|
|
res.setHeader(
|
|
'Content-Disposition',
|
|
`attachment; filename="activity-poster.png"; filename*=UTF-8''${encodeURIComponent(fileName)}`,
|
|
);
|
|
res.send(buffer);
|
|
}
|
|
|
|
@Post(':id/partner-pack')
|
|
@HqOperation({
|
|
action: HqOperationAction.ACTIVITY_POSTER_PACK,
|
|
refType: 'ACTIVITY_POSTER',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
includeResponse: false,
|
|
})
|
|
async pack(@Param('id') id: string, @Body() dto: ActivityPosterPackDto, @Res() res: Response) {
|
|
await this.service.packForPartners(BigInt(id), dto.partnerIds, res);
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.adminDetail(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.ACTIVITY_POSTER_CREATE,
|
|
refType: 'ACTIVITY_POSTER',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() dto: UpsertActivityPosterDto) {
|
|
return this.service.create(dto);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.ACTIVITY_POSTER_UPDATE,
|
|
refType: 'ACTIVITY_POSTER',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() dto: UpsertActivityPosterDto) {
|
|
return this.service.update(BigInt(id), dto);
|
|
}
|
|
|
|
@Put(':id/status')
|
|
@HqOperation({
|
|
action: HqOperationAction.ACTIVITY_POSTER_UPDATE_STATUS,
|
|
refType: 'ACTIVITY_POSTER',
|
|
refIdParam: 'id',
|
|
includeBody: true,
|
|
})
|
|
updateStatus(@Param('id') id: string, @Body() dto: UpdateActivityPosterStatusDto) {
|
|
return this.service.updateStatus(BigInt(id), dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.ACTIVITY_POSTER_DELETE,
|
|
refType: 'ACTIVITY_POSTER',
|
|
refIdParam: 'id',
|
|
})
|
|
remove(@Param('id') id: string) {
|
|
return this.service.remove(BigInt(id));
|
|
}
|
|
}
|