-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathcustomPipe.ts
More file actions
50 lines (42 loc) · 1.58 KB
/
customPipe.ts
File metadata and controls
50 lines (42 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Get, Injectable, PipeTransform, Query, UsePipes } from '@nestjs/common';
@Injectable()
export class CustomSanitizingPipe implements PipeTransform {
transform(value: string): number | undefined {
if (value == null) return undefined;
return Number(value);
}
}
@Injectable()
export class CustomPropagatingPipe implements PipeTransform {
transform(value: string): string {
return value.toUpperCase() + '!';
}
}
export class Controller {
@Get()
sanitizingPipe1(@Query('x', CustomSanitizingPipe) sanitized: number): string {
return '' + sanitized; // $ responseSendArgument
} // $ routeHandler
@Get()
sanitizingPipe2(@Query('x', new CustomSanitizingPipe()) sanitized: number): string {
return '' + sanitized; // $ responseSendArgument
} // $ routeHandler
@Get()
@UsePipes(CustomSanitizingPipe)
sanitizingPipe3(@Query('x') sanitized: number): string {
return '' + sanitized; // $ responseSendArgument
} // $ routeHandler
@Get()
propagatingPipe1(@Query('x', CustomPropagatingPipe) unsanitized: string): string {
return '' + unsanitized; // $ Alert responseSendArgument
} // $ routeHandler
@Get()
propagatingPipe2(@Query('x', new CustomPropagatingPipe()) unsanitized: string): string {
return '' + unsanitized; // $ Alert responseSendArgument
} // $ routeHandler
@Get()
@UsePipes(CustomPropagatingPipe)
propagatingPipe3(@Query('x') unsanitized: string): string {
return '' + unsanitized; // $ Alert responseSendArgument
} // $ routeHandler
}