11import {
2- Body ,
3- Controller ,
4- Param ,
5- Put ,
6- Get ,
7- Header ,
8- Delete ,
9- Query ,
2+ Body ,
3+ Controller ,
4+ Param ,
5+ Put ,
6+ Get ,
7+ Header ,
8+ Delete ,
9+ Query ,
1010} from "@nestjs/common" ;
1111import { Public , AdminOnly } from "../auth/decorators/auth.decorator" ;
1212import { CaptchaService } from "../captcha/captcha.service" ;
@@ -16,89 +16,89 @@ import { HistoryService } from "../history/history.service";
1616import { TargetModel } from "../history/schema/history.schema" ;
1717import { GetClaimReviewsDTO } from "./dto/get-claim-reviews.dto" ;
1818import { NameSpaceEnum } from "../auth/name-space/schemas/name-space.schema" ;
19+ import { listAllResponse } from "./types/claim-review.interfaces" ;
1920
2021@Controller ( )
2122export class ClaimReviewController {
22- constructor (
23- private claimReviewService : ClaimReviewService ,
24- private captchaService : CaptchaService ,
25- private historyService : HistoryService
26- ) { }
23+ constructor (
24+ private claimReviewService : ClaimReviewService ,
25+ private captchaService : CaptchaService ,
26+ private historyService : HistoryService
27+ ) { }
2728
28- @Public ( )
29- @ApiTags ( "claim-review" )
30- @Get ( "api/review" )
31- @Header ( "Cache-Control" , "max-age=60, must-revalidate" )
32- listAll ( @Query ( ) getClaimReviewsDto : GetClaimReviewsDTO ) {
33- const {
34- page = 0 ,
35- pageSize = 10 ,
36- order = "asc" ,
37- isHidden = false ,
38- latest = false ,
39- nameSpace = NameSpaceEnum . Main ,
40- } = getClaimReviewsDto ;
29+ @Public ( )
30+ @ApiTags ( "claim-review" )
31+ @Get ( "api/review" )
32+ @Header ( "Cache-Control" , "max-age=60, must-revalidate" )
33+ async listAll ( @Query ( ) getClaimReviewsDto : GetClaimReviewsDTO ) : Promise < listAllResponse > {
34+ const {
35+ page = 0 ,
36+ pageSize = 10 ,
37+ order = "asc" ,
38+ isHidden = false ,
39+ latest = false ,
40+ nameSpace = NameSpaceEnum . Main ,
41+ } = getClaimReviewsDto ;
4142
42- return Promise . all ( [
43- this . claimReviewService . listAll ( {
44- page ,
45- pageSize ,
46- order ,
47- query : { isHidden, isDeleted : false , nameSpace } ,
48- latest ,
49- } ) ,
50- this . claimReviewService . count ( { isHidden , isDeleted : false } ) ,
51- ] ) . then ( ( [ reviews , totalReviews ] ) => {
52- const totalPages = Math . ceil ( totalReviews / pageSize ) ;
43+ const reviews = await this . claimReviewService . listAll ( {
44+ page ,
45+ pageSize ,
46+ order ,
47+ query : {
48+ isHidden,
49+ nameSpace ,
50+ isDeleted : false
51+ } ,
52+ latest ,
53+ } ) ;
5354
54- return {
55- reviews,
56- totalReviews,
57- totalPages,
58- page,
59- pageSize,
60- } ;
61- } ) ;
62- }
55+ return {
56+ reviews : reviews . data ,
57+ totalReviews : reviews . total ,
58+ totalPages : Math . ceil ( reviews . total / pageSize ) ,
59+ page : page ,
60+ pageSize : pageSize ,
61+ } ;
62+ }
6363
64- @AdminOnly ( )
65- @ApiTags ( "claim-review" )
66- @Put ( "api/review/:id" )
67- async update ( @Param ( "id" ) reviewId , @Body ( ) body ) {
68- const validateCaptcha = await this . captchaService . validate (
69- body . recaptcha
70- ) ;
71- if ( ! validateCaptcha ) {
72- throw new Error ( "Error validating captcha" ) ;
73- }
74- return this . claimReviewService . hideOrUnhideReview (
75- reviewId ,
76- body . isHidden ,
77- body . description
78- ) ;
64+ @AdminOnly ( )
65+ @ApiTags ( "claim-review" )
66+ @Put ( "api/review/:id" )
67+ async update ( @Param ( "id" ) reviewId , @Body ( ) body ) {
68+ const validateCaptcha = await this . captchaService . validate (
69+ body . recaptcha
70+ ) ;
71+ if ( ! validateCaptcha ) {
72+ throw new Error ( "Error validating captcha" ) ;
7973 }
74+ return this . claimReviewService . hideOrUnhideReview (
75+ reviewId ,
76+ body . isHidden ,
77+ body . description
78+ ) ;
79+ }
8080
81- @AdminOnly ( )
82- @ApiTags ( "claim-review" )
83- @Delete ( "api/review/:id" )
84- async delete ( @Param ( "id" ) reviewId ) {
85- return this . claimReviewService . delete ( reviewId ) ;
86- }
81+ @AdminOnly ( )
82+ @ApiTags ( "claim-review" )
83+ @Delete ( "api/review/:id" )
84+ async delete ( @Param ( "id" ) reviewId ) {
85+ return this . claimReviewService . delete ( reviewId ) ;
86+ }
8787
88- @Public ( )
89- @ApiTags ( "claim-review" )
90- @Get ( "api/review/:data_hash" )
91- @Header ( "Cache-Control" , "max-age=60, must-revalidate" )
92- async getReviewByDataHash ( @Param ( "data_hash" ) data_hash ) {
93- const review = await this . claimReviewService . getReviewByDataHash (
94- data_hash
95- ) ;
88+ @Public ( )
89+ @ApiTags ( "claim-review" )
90+ @Get ( "api/review/:data_hash" )
91+ @Header ( "Cache-Control" , "max-age=60, must-revalidate" )
92+ async getReviewByDataHash ( @Param ( "data_hash" ) data_hash ) {
93+ const review = await this . claimReviewService . getReviewByDataHash (
94+ data_hash
95+ ) ;
9696
97- const descriptionForHide =
98- await this . historyService . getDescriptionForHide (
99- review ,
100- TargetModel . ClaimReview
101- ) ;
102- return { review, descriptionForHide } ;
103- }
97+ const descriptionForHide =
98+ await this . historyService . getDescriptionForHide (
99+ review ,
100+ TargetModel . ClaimReview
101+ ) ;
102+ return { review, descriptionForHide } ;
103+ }
104104}
0 commit comments