返回 AiToEarn
adminBanner.controller.ts
根目录 / project / aitoearn-electron / server / src / modules / operate / adminBanner.controller.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-06-17 19:19:20
4 * @LastEditTime: 2025-03-03 18:45:45
5 * @LastEditors: nevin
6 * @Description: banner Banner
7 */
8 import {
9 Body,
10 Controller,
11 Delete,
12 Get,
13 Param,
14 Post,
15 Put,
16 Query,
17 } from '@nestjs/common';
18 import { ApiOperation } from '@nestjs/swagger';
19 import { ParamsValidationPipe } from 'src/validation.pipe';
20 import { BannerService } from './banner.service';
21 import { AppHttpException } from 'src/filters/http-exception.filter';
22 import { ErrHttpBack } from 'src/filters/http-exception.back-code';
23 import { TableDto } from 'src/global/dto/table.dto';
24 import {
25 ActionBannerDto,
26 BannerIdDto,
27 GetBannerListDto,
28 } from './dto/banner.dto';
29 import { ONOFF } from 'src/global/enum/all.enum';
30 import { Banner } from 'src/db/schema/banner.schema';
31 import { Manager } from 'src/auth/manager.guard';
32
33 @Manager()
34 @Controller('admin/banner')
35 export class AdminBannerController {
36 constructor(private readonly bannerService: BannerService) {}
37
38 @ApiOperation({
39 description: '创建',
40 summary: '创建',
41 })
42 @Post()
43 async create(@Body(new ParamsValidationPipe()) body: ActionBannerDto) {
44 const newData = new Banner();
45 newData.dataId = body.dataId;
46 newData.desc = body.desc;
47 newData.url = body.url;
48 newData.imgUrl = body.imgUrl;
49 newData.tag = body.tag;
50 newData.isPublish = ONOFF.ON;
51
52 const res = await this.bannerService.create(newData);
53 return res;
54 }
55
56 @ApiOperation({
57 description: '获取信息',
58 summary: '获取信息',
59 })
60 @Get('info/:id')
61 async getBannerInfoById(
62 @Param(new ParamsValidationPipe()) param: BannerIdDto,
63 ) {
64 const res = await this.bannerService.getBannerInfo(param.id);
65 return res;
66 }
67
68 // 获取列表
69 @Get('list/:pageNo/:pageSize')
70 getMineBannerList(
71 @Param(new ParamsValidationPipe()) param: TableDto,
72 @Query(new ParamsValidationPipe()) query: GetBannerListDto,
73 ) {
74 return this.bannerService.getBannerList(param, query);
75 }
76
77 @ApiOperation({
78 description: '更新',
79 summary: '更新',
80 })
81 @Put('info/:id')
82 async update(
83 @Param(new ParamsValidationPipe()) param: BannerIdDto,
84 @Body(new ParamsValidationPipe()) body: ActionBannerDto,
85 ) {
86 const oldData = await this.bannerService.getBannerInfo(param.id);
87 if (!oldData) throw new AppHttpException(ErrHttpBack.fail);
88
89 oldData.dataId = body.dataId;
90 oldData.desc = body.desc;
91 oldData.url = body.url;
92 oldData.imgUrl = body.imgUrl;
93 oldData.tag = body.tag;
94
95 const res = await this.bannerService.updateBannerInfo(param.id, oldData);
96 return res;
97 }
98
99 @ApiOperation({
100 description: '更新发布状态',
101 summary: '更新发布状态',
102 })
103 @Put('publish/:id')
104 async updateBannerPublishStatus(
105 @Param(new ParamsValidationPipe()) param: BannerIdDto,
106 @Body(new ParamsValidationPipe()) body: any,
107 ) {
108 const bannerInfo = await this.bannerService.getBannerInfo(param.id);
109 if (!bannerInfo) throw new AppHttpException(ErrHttpBack.fail);
110
111 const res = await this.bannerService.updateBannerPublish(
112 param.id,
113 body.checkStatus,
114 );
115 return res;
116 }
117
118 @ApiOperation({
119 description: '删除',
120 summary: '删除',
121 })
122 @Delete(':id')
123 async delete(@Param(new ParamsValidationPipe()) param: BannerIdDto) {
124 const bannerInfo = await this.bannerService.getBannerInfo(param.id);
125 if (!bannerInfo) throw new AppHttpException(ErrHttpBack.fail);
126
127 const res = await this.bannerService.deleteBanner(param.id);
128 return res;
129 }
130 }
131
131 lines TYPESCRIPT