{"id":443908,"date":"2025-01-02T15:04:59","date_gmt":"2025-01-02T15:04:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=443908"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2025-01-02T15:04:59","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=443908","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 REST API \u0441 NestJS \u0438 TypeORM<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h3>\n<ol>\n<li>\n<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<\/ol>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p><strong>NestJS<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 Node.js. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 JavaScript \u0438 TypeScript, \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 Angular \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b.<\/p>\n<p><strong>TypeORM<\/strong> \u2014 \u044d\u0442\u043e ORM (Object-Relational Mapping) \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0421\u0423\u0411\u0414, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a PostgreSQL, MySQL, SQLite \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u0421\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 NestJS \u0438 TypeORM \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 REST API, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 NestJS CLI<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c NestJS CLI \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0432\u0430\u0448\u0443 \u043c\u0430\u0448\u0438\u043d\u0443:<\/p>\n<pre><code class=\"javascript\">npm install -g @nestjs\/cli<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 NestJS \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>my-nestjs-api<\/code>:<\/p>\n<pre><code class=\"javascript\">nest new my-nestjs-api<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b CLI \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 (npm \u0438\u043b\u0438 yarn). \u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 TypeORM \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 TypeORM \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PostgreSQL:<\/p>\n<pre><code class=\"javascript\">cd my-nestjs-api npm install --save @nestjs\/typeorm typeorm pg<\/code><\/pre>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 TypeORM<\/h4>\n<p>\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>src\/app.module.ts<\/code> \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"javascript\">import { Module } from '@nestjs\/common'; import { TypeOrmModule } from '@nestjs\/typeorm'; import { UsersModule } from '.\/users\/users.module';  @Module({   imports: [     TypeOrmModule.forRoot({       type: 'postgres',       host: 'localhost',       port: 5432,       username: 'your_username',        password: 'your_password',        database: 'your_database',        entities: [__dirname + '\/**\/*.entity{.ts,.js}'],       synchronize: true,      }),     UsersModule,   ], }) export class AppModule {}<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>synchronize: true<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h3>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f Users<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c CLI NestJS \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"javascript\">nest generate module users nest generate service users nest generate controller users<\/code><\/pre>\n<h4>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>user.entity.ts<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/users\/<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/user.entity.ts import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';  @Entity() export class User {   @PrimaryGeneratedColumn()   id: number;    @Column({ length: 100 })   name: string;    @Column({ unique: true })   email: string;    @Column()   password: string; }<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><code>@Entity()<\/code> \u2014 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>@PrimaryGeneratedColumn()<\/code> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<\/li>\n<li>\n<p><code>@Column()<\/code> \u2014 \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>length<\/code> \u0438 <code>unique<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a \u043c\u043e\u0434\u0443\u043b\u044e<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u0444\u0430\u0439\u043b <code>users.module.ts<\/code> \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.module.ts import { Module } from '@nestjs\/common'; import { TypeOrmModule } from '@nestjs\/typeorm'; import { UsersService } from '.\/users.service'; import { UsersController } from '.\/users.controller'; import { User } from '.\/user.entity';  @Module({   imports: [TypeOrmModule.forFeature([User])],   providers: [UsersService],   controllers: [UsersController], }) export class UsersModule {}<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/h3>\n<p><strong>DTO (Data Transfer Object)<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 API. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h4>\n<p>NestJS \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>class-validator<\/code> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0435\u0451 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>class-transformer<\/code>:<\/p>\n<pre><code class=\"javascript\">npm install --save class-validator class-transformer<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>create-user.dto.ts<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/users\/<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/create-user.dto.ts import { IsString, IsEmail, MinLength } from 'class-validator';  export class CreateUserDto {   @IsString()   readonly name: string;    @IsEmail()   readonly email: string;    @IsString()   @MinLength(6)   readonly password: string; }<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>update-user.dto.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/update-user.dto.ts import { PartialType } from '@nestjs\/mapped-types'; import { CreateUserDto } from '.\/create-user.dto';  export class UpdateUserDto extends PartialType(CreateUserDto) {}<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><code>PartialType<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c DTO, \u0433\u0434\u0435 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b, \u0447\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 DTO \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <code>users.controller.ts<\/code> \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.controller.ts import { Controller, Get, Post, Body, Param, Delete, Put, ParseIntPipe } from '@nestjs\/common'; import { UsersService } from '.\/users.service'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Controller('users') export class UsersController {   constructor(private readonly usersService: UsersService) {}    @Post()   create(@Body() createUserDto: CreateUserDto) {     return this.usersService.create(createUserDto);   }    @Get()   findAll() {     return this.usersService.findAll();   }    @Get(':id')   findOne(@Param('id', ParseIntPipe) id: number) {     return this.usersService.findOne(id);   }    @Put(':id')   update(     @Param('id', ParseIntPipe) id: number,     @Body() updateUserDto: UpdateUserDto,   ) {     return this.usersService.update(id, updateUserDto);   }    @Delete(':id')   remove(@Param('id', ParseIntPipe) id: number) {     return this.usersService.remove(id);   } }<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>ParseIntPipe<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>id<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u0432 \u0447\u0438\u0441\u043b\u043e \u0438 \u0432\u0430\u043b\u0438\u0434\u0435\u043d.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/h3>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f UsersService<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u0444\u0430\u0439\u043b <code>users.service.ts<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.service.ts import { Injectable, NotFoundException } from '@nestjs\/common'; import { InjectRepository } from '@nestjs\/typeorm'; import { Repository } from 'typeorm'; import { User } from '.\/user.entity'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Injectable() export class UsersService {   constructor(     @InjectRepository(User)     private usersRepository: Repository&lt;User&gt;,   ) {}    async create(createUserDto: CreateUserDto): Promise&lt;User&gt; {     const user = this.usersRepository.create(createUserDto);     return this.usersRepository.save(user);   }    async findAll(): Promise&lt;User[]&gt; {     return this.usersRepository.find();   }    async findOne(id: number): Promise&lt;User&gt; {     const user = await this.usersRepository.findOneBy({ id });     if (!user) {       throw new NotFoundException(`User with ID ${id} not found`);     }     return user;   }    async update(id: number, updateUserDto: UpdateUserDto): Promise&lt;User&gt; {     await this.usersRepository.update(id, updateUserDto);     return this.findOne(id);   }    async remove(id: number): Promise&lt;void&gt; {     const result = await this.usersRepository.delete(id);     if (result.affected === 0) {       throw new NotFoundException(`User with ID ${id} not found`);     }   } }<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>create<\/code>: \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>findAll<\/code>: \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>findOne<\/code>: \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>NotFoundException<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>update<\/code>: \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>remove<\/code>: \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>NotFoundException<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h4>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0443\u0436\u0435 \u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.controller.ts import { Controller, Get, Post, Body, Param, Delete, Put, ParseIntPipe } from '@nestjs\/common'; import { UsersService } from '.\/users.service'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Controller('users') export class UsersController {   constructor(private readonly usersService: UsersService) {}    @Post()   create(@Body() createUserDto: CreateUserDto) {     return this.usersService.create(createUserDto);   }    @Get()   findAll() {     return this.usersService.findAll();   }    @Get(':id')   findOne(@Param('id', ParseIntPipe) id: number) {     return this.usersService.findOne(id);   }    @Put(':id')   update(     @Param('id', ParseIntPipe) id: number,     @Body() updateUserDto: UpdateUserDto,   ) {     return this.usersService.update(id, updateUserDto);   }    @Delete(':id')   remove(@Param('id', ParseIntPipe) id: number) {     return this.usersService.remove(id);   } }<\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CRUD (Create, Read, Update, Delete) \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0448\u0435 API.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Create)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> POST<br \/><strong>URL:<\/strong> <code>\/users<\/code><br \/><strong>\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl -X POST http:\/\/localhost:3000\/users \\ -H \"Content-Type: application\/json\" \\ -d '{\"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\", \"email\": \"ivan@example.com\", \"password\": \"securepassword\"}'<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"id\": 1,   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (Read All)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> GET<br \/><strong>URL:<\/strong> <code>\/users<\/code><\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl http:\/\/localhost:3000\/users<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">[   {     \"id\": 1,     \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",     \"email\": \"ivan@example.com\",     \"password\": \"securepassword\"   } ]<\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID (Read One)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> GET<br \/><strong>URL:<\/strong> <code>\/users\/1<\/code><\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl http:\/\/localhost:3000\/users\/1<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"id\": 1,   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Update)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> PUT<br \/><strong>URL:<\/strong> <code>\/users\/1<\/code><br \/><strong>\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"name\": \"\u0418\u0432\u0430\u043d \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 \u0418\u0432\u0430\u043d\u043e\u0432\" }<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl -X PUT http:\/\/localhost:3000\/users\/1 \\ -H \"Content-Type: application\/json\" \\ -d '{\"name\": \"\u0418\u0432\u0430\u043d \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 \u0418\u0432\u0430\u043d\u043e\u0432\"}'<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"id\": 1,   \"name\": \"\u0418\u0432\u0430\u043d \u0421\u0435\u0440\u0433\u0435\u0435\u0432\u0438\u0447 \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<h4>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Delete)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> DELETE<br \/><strong>URL:<\/strong> <code>\/users\/1<\/code><\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl -X DELETE http:\/\/localhost:3000\/users\/1<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong> (\u0421\u0442\u0430\u0442\u0443\u0441 200 OK \u0431\u0435\u0437 \u0442\u0435\u043b\u0430)<\/p>\n<h3>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API<\/h3>\n<h4>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Postman<\/h4>\n<p>Postman \u2014 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f API. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0432\u0430\u0448\u0435\u043c\u0443 API \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e<\/strong> \u0432 Postman \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/strong> \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439:<\/p>\n<ul>\n<li>\n<p><strong>POST \/users<\/strong> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>GET \/users<\/strong> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>GET \/users\/:id<\/strong> \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID.<\/p>\n<\/li>\n<li>\n<p><strong>PUT \/users\/:id<\/strong> \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>DELETE \/users\/:id<\/strong> \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b<\/strong> \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0439\u0442\u0435 \u043e\u0442\u0432\u0435\u0442\u044b, \u0443\u0431\u0435\u0436\u0434\u0430\u044f\u0441\u044c, \u0447\u0442\u043e API \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e.<\/p>\n<\/li>\n<\/ol>\n<h4>\u041d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 e2e \u0442\u0435\u0441\u0442\u043e\u0432<\/h4>\n<p>NestJS \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 e2e (end-to-end) \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>supertest<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0442\u0435\u0441\u0442 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p><strong>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439:<\/strong><\/p>\n<pre><code class=\"javascript\">npm install --save-dev supertest<\/code><\/pre>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 e2e \u0442\u0435\u0441\u0442\u0430:<\/strong><\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>users.e2e-spec.ts<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>test\/<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ test\/users.e2e-spec.ts import { Test, TestingModule } from '@nestjs\/testing'; import { INestApplication, ValidationPipe } from '@nestjs\/common'; import * as request from 'supertest'; import { AppModule } from '.\/..\/src\/app.module';  describe('UsersController (e2e)', () =&gt; {   let app: INestApplication;    beforeAll(async () =&gt; {     const moduleFixture: TestingModule = await Test.createTestingModule({       imports: [AppModule],     }).compile();      app = moduleFixture.createNestApplication();     \/\/ \u0412\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e DTO     app.useGlobalPipes(new ValidationPipe({       whitelist: true,       forbidNonWhitelisted: true,       transform: true,     }));     await app.init();   });    it('\/users (POST)', () =&gt; {     return request(app.getHttpServer())       .post('\/users')       .send({ name: '\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c', email: 'test@example.com', password: 'test123' })       .expect(201)       .then((response) =&gt; {         expect(response.body).toHaveProperty('id');         expect(response.body.name).toBe('\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c');         expect(response.body.email).toBe('test@example.com');       });   });    it('\/users (GET)', () =&gt; {     return request(app.getHttpServer())       .get('\/users')       .expect(200)       .then((response) =&gt; {         expect(Array.isArray(response.body)).toBeTruthy();         expect(response.body.length).toBeGreaterThan(0);       });   });    it('\/users\/:id (GET)', () =&gt; {     return request(app.getHttpServer())       .get('\/users\/1')       .expect(200)       .then((response) =&gt; {         expect(response.body).toHaveProperty('id', 1);       });   });    it('\/users\/:id (PUT)', () =&gt; {     return request(app.getHttpServer())       .put('\/users\/1')       .send({ name: '\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0418\u043c\u044f' })       .expect(200)       .then((response) =&gt; {         expect(response.body).toHaveProperty('name', '\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0418\u043c\u044f');       });   });    it('\/users\/:id (DELETE)', () =&gt; {     return request(app.getHttpServer())       .delete('\/users\/1')       .expect(200);   });    afterAll(async () =&gt; {     await app.close();   }); });<\/code><\/pre>\n<p><strong>\u0417\u0430\u043f\u0443\u0441\u043a \u0442\u0435\u0441\u0442\u043e\u0432:<\/strong><\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <code>package.json<\/code> \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f e2e \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d:<\/p>\n<pre><code class=\"javascript\">\"scripts\": {   \/\/ ... \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438   \"test:e2e\": \"jest --config .\/test\/jest-e2e.json\" } <\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:<\/p>\n<pre><code class=\"javascript\">npm run test:e2e<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0423\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c, \u0447\u0442\u043e \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0430.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c REST API \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c NestJS \u0438 TypeORM. \u041c\u044b \u043f\u0440\u043e\u0448\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439, \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, DTO, \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448\u0435 API.<\/p>\n<h4>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0448\u0430\u0433\u0438 \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438<\/h4>\n<ol>\n<li>\n<p><strong>\u0410\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0438 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c JWT.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u044c\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430\u043c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0423\u043b\u0443\u0447\u0448\u0438\u0442\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u041c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 TypeORM \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0445\u0435\u043c\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f API:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u0443\u0439\u0442\u0435 Swagger \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u0430\u0448\u0435\u0433\u043e API.<\/p>\n<\/li>\n<\/ul>\n<pre><code>npm install --save @nestjs\/swagger swagger-ui-express<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0432 <code>main.ts<\/code>:<\/p>\n<pre><code>import { SwaggerModule, DocumentBuilder } from '@nestjs\/swagger';  const config = new DocumentBuilder()   .setTitle('Users API')   .setDescription('API \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438')   .setVersion('1.0')   .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api', app, document);<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0438\u0442\u0435 \u043d\u0430\u0433\u0440\u0443\u0437\u043e\u0447\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0430\u0448\u0435\u0433\u043e API, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0432\u0440\u043e\u0434\u0435 Artillery \u0438\u043b\u0438 JMeter.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u0435:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0437\u0432\u0435\u0440\u043d\u0438\u0442\u0435 \u0432\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a AWS, Google Cloud, Heroku \u0438\u043b\u0438 DigitalOcean.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 CI\/CD \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c:<br \/><\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 HTTPS \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0442\u0440\u0430\u043d\u0437\u0438\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0439\u0442\u0435 \u0437\u0430\u0449\u0438\u0442\u0443 \u043e\u0442 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u044b\u0445 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0435\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a XSS, CSRF \u0438 SQL-\u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 REST API \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c NestJS \u0438 TypeORM \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u043c\u043e\u0449\u043d\u044b\u0439 \u0438 \u0433\u0438\u0431\u043a\u0438\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0421\u043b\u0435\u0434\u0443\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u043c \u0448\u0430\u0433\u0430\u043c \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f\u043c, \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0435 \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0435 API, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0439\u0442\u0435 \u0438\u0445 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u043d\u0438\u0436\u0435!<\/p>\n<p><strong>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438:<\/strong><\/p>\n<ul>\n<li>\n<p><a href=\"https:\/\/docs.nestjs.com\/\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f NestJS<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/typeorm.io\/\" rel=\"noopener noreferrer nofollow\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f TypeORM<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.nestjs.com\/openapi\/introduction\" rel=\"noopener noreferrer nofollow\">Swagger \u0434\u043b\u044f NestJS<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/870988\/\"> https:\/\/habr.com\/ru\/articles\/870988\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h3>\n<ol>\n<li>\n<p>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 API<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/p>\n<\/li>\n<\/ol>\n<h3>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<p><strong>NestJS<\/strong> \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0435\u0441\u0441\u0438\u0432\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043d\u0430 Node.js. \u041e\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 JavaScript \u0438 TypeScript, \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u0435\u043d \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u043c\u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430\u043c\u0438 Angular \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b.<\/p>\n<p><strong>TypeORM<\/strong> \u2014 \u044d\u0442\u043e ORM (Object-Relational Mapping) \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043a\u043b\u0430\u0441\u0441\u044b, \u0447\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0421\u0423\u0411\u0414, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a PostgreSQL, MySQL, SQLite \u0438 \u0434\u0440\u0443\u0433\u0438\u0435.<\/p>\n<p>\u0421\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 NestJS \u0438 TypeORM \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 REST API, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043c\u043e\u0434\u0443\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043a\u043e\u0434\u0430.<\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 NestJS CLI<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c NestJS CLI \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0432\u0430\u0448\u0443 \u043c\u0430\u0448\u0438\u043d\u0443:<\/p>\n<pre><code class=\"javascript\">npm install -g @nestjs\/cli<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0435\u043a\u0442 NestJS \u0441 \u0438\u043c\u0435\u043d\u0435\u043c <code>my-nestjs-api<\/code>:<\/p>\n<pre><code class=\"javascript\">nest new my-nestjs-api<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b CLI \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440 (npm \u0438\u043b\u0438 yarn). \u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 TypeORM \u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439<\/h4>\n<p>\u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0435 TypeORM \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c \u0434\u0440\u0430\u0439\u0432\u0435\u0440\u043e\u043c \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c PostgreSQL:<\/p>\n<pre><code class=\"javascript\">cd my-nestjs-api npm install --save @nestjs\/typeorm typeorm pg<\/code><\/pre>\n<h4>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 TypeORM<\/h4>\n<p>\u041e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>src\/app.module.ts<\/code> \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"javascript\">import { Module } from '@nestjs\/common'; import { TypeOrmModule } from '@nestjs\/typeorm'; import { UsersModule } from '.\/users\/users.module';  @Module({   imports: [     TypeOrmModule.forRoot({       type: 'postgres',       host: 'localhost',       port: 5432,       username: 'your_username',        password: 'your_password',        database: 'your_database',        entities: [__dirname + '\/**\/*.entity{.ts,.js}'],       synchronize: true,      }),     UsersModule,   ], }) export class AppModule {}<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>synchronize: true<\/code> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438. \u0414\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d-\u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f \u0438 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/h3>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u044f Users<\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c CLI NestJS \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/p>\n<pre><code class=\"javascript\">nest generate module users nest generate service users nest generate controller users<\/code><\/pre>\n<h4>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 User<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>user.entity.ts<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/users\/<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/user.entity.ts import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';  @Entity() export class User {   @PrimaryGeneratedColumn()   id: number;    @Column({ length: 100 })   name: string;    @Column({ unique: true })   email: string;    @Column()   password: string; }<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><code>@Entity()<\/code> \u2014 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><code>@PrimaryGeneratedColumn()<\/code> \u2014 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447.<\/p>\n<\/li>\n<li>\n<p><code>@Column()<\/code> \u2014 \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u043f\u0446\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <code>length<\/code> \u0438 <code>unique<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043a \u043c\u043e\u0434\u0443\u043b\u044e<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u0435 \u0444\u0430\u0439\u043b <code>users.module.ts<\/code> \u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.module.ts import { Module } from '@nestjs\/common'; import { TypeOrmModule } from '@nestjs\/typeorm'; import { UsersService } from '.\/users.service'; import { UsersController } from '.\/users.controller'; import { User } from '.\/user.entity';  @Module({   imports: [TypeOrmModule.forFeature([User])],   providers: [UsersService],   controllers: [UsersController], }) export class UsersModule {}<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/h3>\n<p><strong>DTO (Data Transfer Object)<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 API. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044e \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h4>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438<\/h4>\n<p>NestJS \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>class-validator<\/code> \u0434\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0435\u0451 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 <code>class-transformer<\/code>:<\/p>\n<pre><code class=\"javascript\">npm install --save class-validator class-transformer<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>create-user.dto.ts<\/code> \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>src\/users\/<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/create-user.dto.ts import { IsString, IsEmail, MinLength } from 'class-validator';  export class CreateUserDto {   @IsString()   readonly name: string;    @IsEmail()   readonly email: string;    @IsString()   @MinLength(6)   readonly password: string; }<\/code><\/pre>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 DTO \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b <code>update-user.dto.ts<\/code>:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/update-user.dto.ts import { PartialType } from '@nestjs\/mapped-types'; import { CreateUserDto } from '.\/create-user.dto';  export class UpdateUserDto extends PartialType(CreateUserDto) {}<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><code>PartialType<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c DTO, \u0433\u0434\u0435 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b, \u0447\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 DTO \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0435<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 <code>users.controller.ts<\/code> \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f DTO \u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.controller.ts import { Controller, Get, Post, Body, Param, Delete, Put, ParseIntPipe } from '@nestjs\/common'; import { UsersService } from '.\/users.service'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Controller('users') export class UsersController {   constructor(private readonly usersService: UsersService) {}    @Post()   create(@Body() createUserDto: CreateUserDto) {     return this.usersService.create(createUserDto);   }    @Get()   findAll() {     return this.usersService.findAll();   }    @Get(':id')   findOne(@Param('id', ParseIntPipe) id: number) {     return this.usersService.findOne(id);   }    @Put(':id')   update(     @Param('id', ParseIntPipe) id: number,     @Body() updateUserDto: UpdateUserDto,   ) {     return this.usersService.update(id, updateUserDto);   }    @Delete(':id')   remove(@Param('id', ParseIntPipe) id: number) {     return this.usersService.remove(id);   } }<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>ParseIntPipe<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>id<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d \u0432 \u0447\u0438\u0441\u043b\u043e \u0438 \u0432\u0430\u043b\u0438\u0434\u0435\u043d.<\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u0430 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430<\/h3>\n<h4>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f UsersService<\/h4>\n<p>\u041e\u0431\u043d\u043e\u0432\u0438\u043c \u0444\u0430\u0439\u043b <code>users.service.ts<\/code> \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.service.ts import { Injectable, NotFoundException } from '@nestjs\/common'; import { InjectRepository } from '@nestjs\/typeorm'; import { Repository } from 'typeorm'; import { User } from '.\/user.entity'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Injectable() export class UsersService {   constructor(     @InjectRepository(User)     private usersRepository: Repository&lt;User&gt;,   ) {}    async create(createUserDto: CreateUserDto): Promise&lt;User&gt; {     const user = this.usersRepository.create(createUserDto);     return this.usersRepository.save(user);   }    async findAll(): Promise&lt;User[]&gt; {     return this.usersRepository.find();   }    async findOne(id: number): Promise&lt;User&gt; {     const user = await this.usersRepository.findOneBy({ id });     if (!user) {       throw new NotFoundException(`User with ID ${id} not found`);     }     return user;   }    async update(id: number, updateUserDto: UpdateUserDto): Promise&lt;User&gt; {     await this.usersRepository.update(id, updateUserDto);     return this.findOne(id);   }    async remove(id: number): Promise&lt;void&gt; {     const result = await this.usersRepository.delete(id);     if (result.affected === 0) {       throw new NotFoundException(`User with ID ${id} not found`);     }   } }<\/code><\/pre>\n<p><strong>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>create<\/code>: \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>findAll<\/code>: \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>findOne<\/code>: \u041d\u0430\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>NotFoundException<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>update<\/code>: \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 <\/strong><code>remove<\/code>: \u0423\u0434\u0430\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID. \u0415\u0441\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d, \u0432\u044b\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u0435\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 <code>NotFoundException<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430<\/h4>\n<p>\u041a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0443\u0436\u0435 \u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d \u0440\u0430\u043d\u0435\u0435 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e:<\/p>\n<pre><code class=\"javascript\">\/\/ src\/users\/users.controller.ts import { Controller, Get, Post, Body, Param, Delete, Put, ParseIntPipe } from '@nestjs\/common'; import { UsersService } from '.\/users.service'; import { CreateUserDto } from '.\/create-user.dto'; import { UpdateUserDto } from '.\/update-user.dto';  @Controller('users') export class UsersController {   constructor(private readonly usersService: UsersService) {}    @Post()   create(@Body() createUserDto: CreateUserDto) {     return this.usersService.create(createUserDto);   }    @Get()   findAll() {     return this.usersService.findAll();   }    @Get(':id')   findOne(@Param('id', ParseIntPipe) id: number) {     return this.usersService.findOne(id);   }    @Put(':id')   update(     @Param('id', ParseIntPipe) id: number,     @Body() updateUserDto: UpdateUserDto,   ) {     return this.usersService.update(id, updateUserDto);   }    @Delete(':id')   remove(@Param('id', ParseIntPipe) id: number) {     return this.usersService.remove(id);   } }<\/code><\/pre>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f CRUD \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 CRUD (Create, Read, Update, Delete) \u0447\u0435\u0440\u0435\u0437 \u043d\u0430\u0448\u0435 API.<\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (Create)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> POST<br \/><strong>URL:<\/strong> <code>\/users<\/code><br \/><strong>\u0422\u0435\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl -X POST http:\/\/localhost:3000\/users \\ -H \"Content-Type: application\/json\" \\ -d '{\"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\", \"email\": \"ivan@example.com\", \"password\": \"securepassword\"}'<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"id\": 1,   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\": \"ivan@example.com\",   \"password\": \"securepassword\" }<\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (Read All)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> GET<br \/><strong>URL:<\/strong> <code>\/users<\/code><\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl http:\/\/localhost:3000\/users<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">[   {     \"id\": 1,     \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",     \"email\": \"ivan@example.com\",     \"password\": \"securepassword\"   } ]<\/code><\/pre>\n<h4>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u043e ID (Read One)<\/h4>\n<p><strong>HTTP \u041c\u0435\u0442\u043e\u0434:<\/strong> GET<br \/><strong>URL:<\/strong> <code>\/users\/1<\/code><\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c cURL:<\/strong><\/p>\n<pre><code class=\"javascript\">curl http:\/\/localhost:3000\/users\/1<\/code><\/pre>\n<p><strong>\u041e\u0442\u0432\u0435\u0442:<\/strong><\/p>\n<pre><code class=\"javascript\">{   \"id\": 1,   \"name\": \"\u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u043e\u0432\",   \"email\":<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-443908","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=443908"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/443908\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=443908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=443908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=443908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}