Skip to content

Instantly share code, notes, and snippets.

View udara94's full-sized avatar
🎯
Focusing

Udara Abeythilake udara94

🎯
Focusing
View GitHub Profile
import { Module } from '@nestjs/common';
import { APP_PIPE } from '@nestjs/core';
@Module({
providers: [
{
provide: APP_PIPE,
useClass: CustomeValidationPipe,
},
],
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new CustomeValidationPipe ());
await app.listen(3000);
}
bootstrap();
import { PipeTransform, Injectable, ArgumentMetadata } from '@nestjs/common';
@Injectable()
export class CustomeValidationPipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
return value;
}
}
@Get(':id')
@UsePipes(ParseUUIDPipe)
getBookById(@Param('id') id: string){
return this.bookService.findBookById();
}
@Get(':id')
getBookById(@Param('id', ParseUUIDPipe) id: string){
return this.bookService.findBookById();
}
Method Name  Description 
concat()  Joins arrays and returns an array with the joined arrays 
copyWithin()  Copies array elements within the array, to and from specified positions 
every()  Checks if every element in an array passes a test 
fill()  Fill the elements in an array with a static value 
filter()  Creates a new array with every element in an array that passes a test 
find()  Returns the value of the first element in an array that passed a test 
findIndex()  Returns the index of the first element in an array that passed a test 
flat()  creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. 
flatMap()  returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. 
import { Module } from "@nestjs/common";
import { FuelStationController } from "src/controllers";
import { APP_FILTER } from '@nestjs/core';
import { HttpExceptionFilter } from "src/exceptions";
@Module({
controllers: [FuelStationController],
providers: [
{
async function bootstrap() {
const app = await NestFactory.create(FuelStationModule);
app.useGlobalFilters(new HttpExceptionFilter());
await app.listen(3000);
}
bootstrap();
@Controller('stations')
@UseFilters(new HttpExceptionFilter())
export class FuelStationController {
}
@Get()
@UseFilters(HttpExceptionFilter)
getFuelForTokenHolders(){
throw new CustomFuelStationException('Fuel token is not valid', HttpStatus.UNAUTHORIZED)
}