
3 July 2025
Transformation: From string to integer
Validation: Evaluate input data if valid, otherwise throw exception
Interceptor(ExecutionContext, CallHandler), modify response P
Transform the result return from controller before send to client
Bind extra logic before/ after method execution
@Entity({ name: 'Brands' })
export class Brand {
@PrimaryGeneratedColumn()
id: number;
}
@Column()
category_id: number;
@ManyToOne(() => Category, (category) => category.brands, {
cascade: true,
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'category_id' })
category: Category;
Define ManyToOne is define foreign key constraint
Use @OneToMany, @ManyToOne is required
@ManyToOne(() => Category), this line will create column "categoryId“ in the table, to change change this name can specify the join column name @JoinColumn({ name: "category_id" })
nest g module --name for modules nest g controller --name for controller nest g service for --name for service
constructor (private readonly name: serviceName)
@Get() /items @Get('id') /item/id
getAll(@Param('id') id: string)
itemRepository extract item from tbale
fix metadata was not found => import typeorm module forFeature
Make with
by Nguyen Huu Dat
© 2025