{"id":342998,"date":"2022-12-22T09:00:23","date_gmt":"2022-12-22T09:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=342998"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2022-12-22T09:00:23","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=342998","title":{"rendered":"<span>\u041f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0439 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c React, Nest \u0438 NX. \u0427\u0430\u0441\u0442\u044c 3: \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/8f2\/9db\/285\/8f29db2854324b25385204f36c5a991f.jpeg\" width=\"1560\" height=\"1039\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8f2\/9db\/285\/8f29db2854324b25385204f36c5a991f.jpeg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c \u041a\u0430\u0440\u0435\u043b\u0438\u043d, \u044f frontend-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0414\u043e\u043c\u043a\u043b\u0438\u043a. \u0412\u00a0<a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/687106\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a>\u00a0\u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0<a href=\"https:\/\/github.com\/jaredhanson\/passport\">Passport<\/a>, \u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c HTTP \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0438\u043f\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<h2>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e HTTP \u0438 \u0442\u0438\u043f\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p><strong>HTTP<\/strong> (\u0430\u043d\u0433\u043b.\u00a0<em>HyperText Transfer Protocol<\/em>, \u00ab\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438\u00a0\u0433\u0438\u043f\u0435\u0440\u0442\u0435\u043a\u0441\u0442\u0430\u00bb)\u00a0\u2014\u00a0\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u00a0\u2014 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0438\u043f\u0435\u0440\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML, \u0430 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 HTTP<\/strong> \u2014 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043b\u044e\u0431\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u0440\u043e\u043c\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0434 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c. \u0414\u043b\u044f \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>GET \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>POST \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>PUT \u2014 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>DELETE \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0421 \u043f\u043e\u043b\u043d\u044b\u043c \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e HTTP \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/HTTP#%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c Docker \u0438 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 Nest CLI.<\/p>\n<pre><code class=\"bash\">$ nx run-many --parallel --target=serve --projects=backend,frontend \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 $ nest g module tasks \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u043e\u0434\u0443\u043b\u044c tasks $ nest g service tasks --no-spec \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u0435\u0437 \u0444\u0430\u0439\u043b\u0430 \u0442\u0435\u0441\u0442\u043e\u0432 $ nest g controller tasks --no-spec \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0435\u0437 \u0444\u0430\u0439\u043b\u0430 \u0442\u0435\u0441\u0442\u043e\u0432<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 Nest CLI \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u0438, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e. \u0414\u0430\u043b\u0435\u0435 \u0440\u0443\u043a\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432: <code>task.dto.ts<\/code>, <code>task.interface.ts<\/code> \u0438 <code>task.model.ts<\/code><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c mongoose-\u0441\u0445\u0435\u043c\u0443<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0435, \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0445\u0435\u043c\u0443. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c, \u0434\u0430\u0442\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0438\u0448\u0435\u043c interface. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<pre><code class=\"typescript\">export interface TaskInterface {   title: string;   description: string; }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u044b \u043f\u0438\u0448\u0435\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0445\u0435\u043c\u0443 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>task.model.ts<\/code>.<\/p>\n<pre><code class=\"typescript\">import { Prop, Schema, SchemaFactory } from '@nestjs\/mongoose'; import { Document } from 'mongoose'; import { TaskInterface } from '..\/interfaces\/task.interface';  @Schema({ collection: 'tasks', timestamps: true }) export class TaskModel extends Document implements TaskInterface {      @Prop({ required: true })   title: string;      @Prop({ required: true })   description: string;    }  export const TaskSchema = SchemaFactory.createForClass(TaskModel); <\/code><\/pre>\n<p>\u0412 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 <code>@Schema<\/code> \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c <code>timestamps: true<\/code> , \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u0442\u044b. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u0434\u0430\u0447\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{     \"description\": \"description\",     \"title\": \"title\",     \"_id\": \"63a37f9566316dec1d2b131f\",     \"createdAt\": \"2022-12-21T21:50:13.569Z\",     \"updatedAt\": \"2022-12-21T21:50:13.569Z\",     \"__v\": 0 }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 <code>TaskModel<\/code>  \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>TaskInterface<\/code>, \u0441\u043e\u0437\u0434\u0430\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>SchemaFactory.createForClass<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>TaskModel<\/code>, \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>task.module.ts<\/code>.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h2>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/687106\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u043c\u0443 \u043f\u0443\u0442\u044c <code>\/api\/tasks<\/code>. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b: <\/p>\n<ul>\n<li>\n<p>POST \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>PUT \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>DELETE \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>GET \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 NestJs \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0434 \u0441\u0432\u043e\u0435\u0439 \u0443\u0447\u0451\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e.<\/p>\n<details class=\"spoiler\">\n<summary>tasks.controller.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import {   Body,   Controller,   Delete,   Get,   Param,   Post,   Put,   Req,   UseGuards,   UsePipes,   ValidationPipe, } from '@nestjs\/common'; import { TasksService } from '.\/tasks.service'; import { AuthGuard } from '@nestjs\/passport'; import { TaskDto } from '.\/dto\/task.dto'; import { UsersService } from '..\/users\/users.service';  @Controller('tasks') export class TasksController {   constructor(     private readonly tasksService: TasksService,     private readonly usersService: UsersService   ) {}   @UsePipes(new ValidationPipe())   @UseGuards(AuthGuard('jwt'))   @Post()   async createTask(@Req() req, @Body() tasksDto: TaskDto) {     return await this.tasksService.createTask(req.user._id, tasksDto);   }    @UseGuards(AuthGuard('jwt'))   @Get()   async getAllTasks(@Req() req) {     return await this.tasksService.getAllTasks(req.user.tasks);   }    @UseGuards(AuthGuard('jwt'))   @Get(':id')   async getTask(@Req() req, @Param('id') id) {     return await this.tasksService.getTask(req.user.tasks, id);   }    @UseGuards(AuthGuard('jwt'))   @Delete()   async deleteTask(@Req() req, @Body() body) {     return await this.tasksService.deleteTask(req.user, body.id);   }    @UsePipes(new ValidationPipe())   @UseGuards(AuthGuard('jwt'))   @Put()   async updateTask(@Req() req, @Body() tasksDto: TaskDto) {     return await this.tasksService.updateTask(req.user, tasksDto);   } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u043d\u0435\u0435. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b <code>@UseGuards(AuthGuard('jwt'))<\/code>  \u0438 <code>@Req() req<\/code>: \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0443. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u0434\u0430\u0447\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435.<\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/h2>\n<p>\u0412 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u0443 \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 CRUD-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u0430\u0434\u0430\u0447, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>\u0412 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439<code>UserModel<\/code> \u0432 17 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043e\u0434\u043d\u0438 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441 \u043b\u0451\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<details class=\"spoiler\">\n<summary>user.model.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { Prop, Schema, SchemaFactory } from '@nestjs\/mongoose'; import { Document, Types } from 'mongoose'; import { IUser } from '..\/interfaces\/user.interface'; import { TaskModel } from '..\/..\/tasks\/models\/task.model';  @Schema({ collection: 'users', timestamps: true }) export class UserModel extends Document implements IUser {   @Prop({ required: true })   username: string;    @Prop({ required: true })   password: string;    @Prop({ required: true })   email: string;    @Prop({ type: [Types.ObjectId], ref: TaskModel.name }) \/\/ \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.   tasks: TaskModel[]; }  export const UserSchema = SchemaFactory.createForClass(UserModel);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c ID \u0437\u0430\u0434\u0430\u0447, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043d\u0435\u043c\u0443. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a: <\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{     \"_id\": \"63a37ed666316dec1d2b131b\",     \"username\": \"admin\",     \"email\": \"example@mail.com\",     \"tasks\": [         \"63a37f9566316dec1d2b131f\",         \"63a39099609d041ff6cd62ab\",         \"63a3909a609d041ff6cd62af\"     ] }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043b\u0438 <code>UsersService<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f ID \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 65 \u0438 69 \u0441\u0442\u0440\u043e\u043a\u0430\u0445.<\/p>\n<details class=\"spoiler\">\n<summary>users.service.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { Injectable, HttpException, HttpStatus } from '@nestjs\/common'; import { UserDto } from '.\/dto\/user.dto'; import { CreateUserDto } from '.\/dto\/user.create.dto'; import { LoginUserDto } from '.\/dto\/user-login.dto'; import { toUserDto } from '..\/shared\/mapper'; import { InjectModel } from '@nestjs\/mongoose'; import { UserModel } from '.\/models\/user.model'; import { Model } from 'mongoose'; import { genSalt, hash, compare } from 'bcrypt';  @Injectable() export class UsersService {   constructor(     @InjectModel(UserModel.name)     private readonly userModel: Model&lt;UserModel>   ) {}    async findOne(options?: object): Promise&lt;UserDto> {     const user = await this.userModel.findOne(options).exec();     return toUserDto(user);   }    async findByLogin({ username, password }: LoginUserDto): Promise&lt;UserDto> {     const user = await this.userModel.findOne({ username }).exec();      if (!user) {       throw new HttpException('User not found', HttpStatus.UNAUTHORIZED);     }      const areEqual = await compare(password, user.password);      if (!areEqual) {       throw new HttpException('Invalid credentials', HttpStatus.UNAUTHORIZED);     }      return toUserDto(user);   }    async findByPayload({ username }: any): Promise&lt;UserDto> {     return await this.findOne({ username });   }    async create(userDto: CreateUserDto): Promise&lt;UserDto> {     const { username, password, email } = userDto;      const userInDb = await this.userModel.findOne({ username }).exec();     if (userInDb) {       throw new HttpException('User already exists', HttpStatus.BAD_REQUEST);     }      const salt = await genSalt(10);     const hashPassword = await hash(password, salt);      const user: UserModel = await new this.userModel({       username,       password: hashPassword,       email,     });      await user.save();      return toUserDto(user);   }    async setTaskToCurrentUser(_id, taskId) {     await this.userModel.updateOne({ _id }, { $push: { tasks: taskId } });   }    async deleteTaskToCurrentUser(_id, taskId) {     await this.userModel.updateOne({ _id }, { $pull: { tasks: taskId } });   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<details class=\"spoiler\">\n<summary>tasks.service.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { HttpException, HttpStatus, Injectable } from '@nestjs\/common'; import { InjectModel } from '@nestjs\/mongoose'; import { Model } from 'mongoose'; import { TaskDto } from '.\/dto\/task.dto'; import { TaskModel } from '.\/models\/task.model'; import { UsersService } from '..\/users\/users.service';  @Injectable() export class TasksService {   constructor(     @InjectModel(TaskModel.name)     private readonly taskModel: Model&lt;TaskModel>,     private readonly userService: UsersService   ) {}   async createTask(userId, taskDto: TaskDto) {     const task = await this.taskModel.create(taskDto);     await this.userService.setTaskToCurrentUser(userId, task._id);     return task;   }    async getAllTasks(tasksId) {     return await this.taskModel.find().where('_id').in(tasksId).exec();   }    async getTask(tasks, id: string) {     if (this.taskExistence(tasks, id)) {       return await this.taskModel.findOne({ _id: id }).exec();     }   }    async deleteTask(user, id) {     if (this.taskExistence(user.tasks, id)) {       await this.userService.deleteTaskToCurrentUser(user._id, id);       return await this.taskModel.deleteOne({ _id: id }).exec();     }      throw new HttpException('Task not found', HttpStatus.NOT_FOUND);   }    async updateTask(user, body) {     if (this.taskExistence(user.tasks, body._id)) {       return await this.taskModel.updateOne(body).exec();     }     throw new HttpException('Task not found', HttpStatus.NOT_FOUND);   }    private taskExistence(userTasks, taskId) {     return userTasks.find((id) => taskId === id.toString());   } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u042f \u043e\u043f\u0438\u0448\u0443 \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. <\/p>\n<p><code>createTask<\/code> \u2014 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u0434\u0430\u0447\u0443 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c, \u0434\u0430\u043b\u0435\u0435 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0431\u0430\u0437\u0443 \u0438 \u0432 \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 ID \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 <code>setTaskToCurrentUser<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f ID \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 ID \u0437\u0430\u0434\u0430\u0447\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0449\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e ID \u0438 \u0437\u0430\u043f\u0438\u0441\u044c ID \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. <\/p>\n<p><code>getAllTasks<\/code> \u2014 \u0442\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e: \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043f\u0438\u0441\u043e\u043a ID \u0437\u0430\u0434\u0430\u0447 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0435 \u0438\u0445 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p><code>getTask<\/code> \u2014 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u043e\u043d\u0430 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u0432\u0435\u0440\u043d\u0451\u043c \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p><code>deleteTask<\/code> \u2014 \u043a\u0430\u043a \u0438 \u0432 <code>getTask<\/code>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0435\u0441\u0442\u044c \u043b\u0438 \u043e\u043d\u0430 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u2014 \u0443\u0434\u0430\u043b\u044f\u0435\u043c ID \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0441\u0430\u043c\u0443 \u0437\u0430\u0434\u0430\u0447\u0443, \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p><code>updateTask<\/code> \u2014 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0415\u0441\u043b\u0438 \u043e\u043d\u0430 \u0435\u0441\u0442\u044c, \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0451 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e, \u0438\u043d\u0430\u0447\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u0430.<\/p>\n<p><code>taskExistence<\/code> \u2014 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0435\u0441\u0442\u044c \u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 ID \u0437\u0430\u0434\u0430\u0447\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043c\u043e\u0434\u0443\u043b\u044c<\/h2>\n<p>\u041d\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u044c. <\/p>\n<details class=\"spoiler\">\n<summary>tasks.module.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { Module } from '@nestjs\/common'; import { TasksService } from '.\/tasks.service'; import { TasksController } from '.\/tasks.controller'; import { MongooseModule } from '@nestjs\/mongoose'; import { TaskModel, TaskSchema } from '.\/models\/task.model'; import { UsersModule } from '..\/users\/users.module';  @Module({   imports: [     UsersModule,     MongooseModule.forFeature([       {         name: TaskModel.name,         schema: TaskSchema,       },     ]),   ],   providers: [TasksService],   controllers: [TasksController], }) export class TasksModule {} <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u043c\u044b \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 <code>UsersModule<\/code> \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>UsersService<\/code> \u0432 <code>TasksService<\/code>. \u0414\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0437\u0430\u0434\u0430\u0447 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e <code>TasksModule<\/code> \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 <code>AppModule<\/code>.<\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u043e\u043a\u0430 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f. \u041c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e HTTP \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0437\u0430\u0434\u0430\u0447\u0430\u043c\u0438. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439, \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0432\u0435\u0441\u044c \u0444\u0440\u043e\u043d\u0442\u0435\u043d\u0434. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043f\u043e\u00a0<a href=\"https:\/\/github.com\/Igoryas\/nx-react-nest\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<\/p>\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\/company\/domclick\/blog\/706964\/\"> https:\/\/habr.com\/ru\/company\/domclick\/blog\/706964\/<\/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<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0433\u043e\u0440\u044c \u041a\u0430\u0440\u0435\u043b\u0438\u043d, \u044f frontend-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0432 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0414\u043e\u043c\u043a\u043b\u0438\u043a. \u0412\u00a0<a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/687106\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a>\u00a0\u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438\u00a0<a href=\"https:\/\/github.com\/jaredhanson\/passport\">Passport<\/a>, \u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c HTTP \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0438\u043f\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/p>\n<h2>\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e HTTP \u0438 \u0442\u0438\u043f\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432<\/h2>\n<p><strong>HTTP<\/strong> (\u0430\u043d\u0433\u043b.\u00a0<em>HyperText Transfer Protocol<\/em>, \u00ab\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438\u00a0\u0433\u0438\u043f\u0435\u0440\u0442\u0435\u043a\u0441\u0442\u0430\u00bb)\u00a0\u2014\u00a0\u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f\u00a0\u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u00a0\u2014 \u0432 \u0432\u0438\u0434\u0435 \u0433\u0438\u043f\u0435\u0440\u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HTML, \u0430 \u0432 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u041c\u0435\u0442\u043e\u0434 HTTP<\/strong> \u2014 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438\u0437 \u043b\u044e\u0431\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u043a\u0440\u043e\u043c\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0435\u0439, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0430\u0434 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c. \u0414\u043b\u044f \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u043c\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 HTTP-\u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0431\u044b\u043b\u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b:<\/p>\n<ul>\n<li>\n<p>GET \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>POST \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>PUT \u2014 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430;<\/p>\n<\/li>\n<li>\n<p>DELETE \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u0421 \u043f\u043e\u043b\u043d\u044b\u043c \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e HTTP \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/HTTP#%D0%9C%D0%B5%D1%82%D0%BE%D0%B4%D1%8B\">\u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432<\/h2>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c Docker \u0438 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434 Nest CLI.<\/p>\n<pre><code class=\"bash\">$ nx run-many --parallel --target=serve --projects=backend,frontend \/\/ \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 $ nest g module tasks \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u043e\u0434\u0443\u043b\u044c tasks $ nest g service tasks --no-spec \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u0435\u0437 \u0444\u0430\u0439\u043b\u0430 \u0442\u0435\u0441\u0442\u043e\u0432 $ nest g controller tasks --no-spec \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0431\u0435\u0437 \u0444\u0430\u0439\u043b\u0430 \u0442\u0435\u0441\u0442\u043e\u0432<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 Nest CLI \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u0438, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e. \u0414\u0430\u043b\u0435\u0435 \u0440\u0443\u043a\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0430\u0439\u043b\u043e\u0432: <code>task.dto.ts<\/code>, <code>task.interface.ts<\/code> \u0438 <code>task.model.ts<\/code><\/p>\n<h3>\u0421\u043e\u0437\u0434\u0430\u0435\u043c mongoose-\u0441\u0445\u0435\u043c\u0443<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u043e\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0435, \u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0445\u0435\u043c\u0443. \u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c, \u0434\u0430\u0442\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0438\u0448\u0435\u043c interface. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<pre><code class=\"typescript\">export interface TaskInterface {   title: string;   description: string; }<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u043c\u044b \u043f\u0438\u0448\u0435\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435. \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0441\u0445\u0435\u043c\u0443 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>task.model.ts<\/code>.<\/p>\n<pre><code class=\"typescript\">import { Prop, Schema, SchemaFactory } from '@nestjs\/mongoose'; import { Document } from 'mongoose'; import { TaskInterface } from '..\/interfaces\/task.interface';  @Schema({ collection: 'tasks', timestamps: true }) export class TaskModel extends Document implements TaskInterface {      @Prop({ required: true })   title: string;      @Prop({ required: true })   description: string;    }  export const TaskSchema = SchemaFactory.createForClass(TaskModel); <\/code><\/pre>\n<p>\u0412 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u0435 <code>@Schema<\/code> \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c <code>timestamps: true<\/code> , \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0443\u0442 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u0442\u044b. \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u044a\u0435\u043a\u0442 \u0437\u0430\u0434\u0430\u0447\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{     \"description\": \"description\",     \"title\": \"title\",     \"_id\": \"63a37f9566316dec1d2b131f\",     \"createdAt\": \"2022-12-21T21:50:13.569Z\",     \"updatedAt\": \"2022-12-21T21:50:13.569Z\",     \"__v\": 0 }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043b\u0430\u0441\u0441 <code>TaskModel<\/code>  \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>TaskInterface<\/code>, \u0441\u043e\u0437\u0434\u0430\u0432 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u043e\u043c \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>SchemaFactory.createForClass<\/code>, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>TaskModel<\/code>, \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043c\u043e\u0434\u0443\u043b\u044c <code>task.module.ts<\/code>.<\/p>\n<h2>\u041e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440<\/h2>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/domclick\/blog\/687106\/\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u044b \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441 \u043a\u043e\u0440\u043d\u0435\u0432\u044b\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0437\u0430\u0434\u0430\u0434\u0438\u043c \u0435\u043c\u0443 \u043f\u0443\u0442\u044c <code>\/api\/tasks<\/code>. \u041d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b: <\/p>\n<ul>\n<li>\n<p>POST \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>PUT \u2014 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>DELETE \u2014 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438;<\/p>\n<\/li>\n<li>\n<p>GET \u2014 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0439 \u0438\u043b\u0438 \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 NestJs \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432, \u0447\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e.<\/p>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u043d\u0435\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0438 \u0441\u043e\u0437\u0434\u0430\u043b \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e\u0434 \u0441\u0432\u043e\u0435\u0439 \u0443\u0447\u0451\u0442\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u044c\u044e.<\/p>\n<details class=\"spoiler\">\n<summary>tasks.controller.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import {   Body,   Controller,   Delete,   Get,   Param,   Post,   Put,   Req,   UseGuards,   UsePipes,   ValidationPipe, } from '@nestjs\/common'; import { TasksService } from '.\/tasks.service'; import { AuthGuard } from '@nestjs\/passport'; import { TaskDto } from '.\/dto\/task.dto'; import { UsersService } from '..\/users\/users.service';  @Controller('tasks') export class TasksController {   constructor(     private readonly tasksService: TasksService,     private readonly usersService: UsersService   ) {}   @UsePipes(new ValidationPipe())   @UseGuards(AuthGuard('jwt'))   @Post()   async createTask(@Req() req, @Body() tasksDto: TaskDto) {     return await this.tasksService.createTask(req.user._id, tasksDto);   }    @UseGuards(AuthGuard('jwt'))   @Get()   async getAllTasks(@Req() req) {     return await this.tasksService.getAllTasks(req.user.tasks);   }    @UseGuards(AuthGuard('jwt'))   @Get(':id')   async getTask(@Req() req, @Param('id') id) {     return await this.tasksService.getTask(req.user.tasks, id);   }    @UseGuards(AuthGuard('jwt'))   @Delete()   async deleteTask(@Req() req, @Body() body) {     return await this.tasksService.deleteTask(req.user, body.id);   }    @UsePipes(new ValidationPipe())   @UseGuards(AuthGuard('jwt'))   @Put()   async updateTask(@Req() req, @Body() tasksDto: TaskDto) {     return await this.tasksService.updateTask(req.user, tasksDto);   } } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432, \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u043e\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0440\u0430\u043d\u0435\u0435. \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b <code>@UseGuards(AuthGuard('jwt'))<\/code>  \u0438 <code>@Req() req<\/code>: \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0439 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0443. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u0434\u0430\u0447\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435.<\/p>\n<h2>\u041f\u0438\u0448\u0435\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/h2>\n<p>\u0412 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445 \u0443 \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 CRUD-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u0430\u0434\u0430\u0447, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0441\u044f \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u043e\u043d \u043d\u0443\u0436\u0435\u043d.<\/p>\n<p>\u0412 \u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439<code>UserModel<\/code> \u0432 17 \u0441\u0442\u0440\u043e\u043a\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043e\u0434\u043d\u0438 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441 \u043b\u0451\u0433\u043a\u043e\u0441\u0442\u044c\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<details class=\"spoiler\">\n<summary>user.model.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { Prop, Schema, SchemaFactory } from '@nestjs\/mongoose'; import { Document, Types } from 'mongoose'; import { IUser } from '..\/interfaces\/user.interface'; import { TaskModel } from '..\/..\/tasks\/models\/task.model';  @Schema({ collection: 'users', timestamps: true }) export class UserModel extends Document implements IUser {   @Prop({ required: true })   username: string;    @Prop({ required: true })   password: string;    @Prop({ required: true })   email: string;    @Prop({ type: [Types.ObjectId], ref: TaskModel.name }) \/\/ \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u043c\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.   tasks: TaskModel[]; }  export const UserSchema = SchemaFactory.createForClass(UserModel);<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c ID \u0437\u0430\u0434\u0430\u0447, \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043d\u0435\u043c\u0443. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a: <\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{     \"_id\": \"63a37ed666316dec1d2b131b\",     \"username\": \"admin\",     \"email\": \"example@mail.com\",     \"tasks\": [         \"63a37f9566316dec1d2b131f\",         \"63a39099609d041ff6cd62ab\",         \"63a3909a609d041ff6cd62af\"     ] }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u043b\u0438 <code>UsersService<\/code> \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f ID \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 65 \u0438 69 \u0441\u0442\u0440\u043e\u043a\u0430\u0445.<\/p>\n<details class=\"spoiler\">\n<summary>users.service.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { Injectable, HttpException, HttpStatus } from '@nestjs\/common'; import { UserDto } from '.\/dto\/user.dto'; import { CreateUserDto } from '.\/dto\/user.create.dto'; import { LoginUserDto } from '.\/dto\/user-login.dto'; import { toUserDto } from '..\/shared\/mapper'; import { InjectModel } from '@nestjs\/mongoose'; import { UserModel } from '.\/models\/user.model'; import { Model } from 'mongoose'; import { genSalt, hash, compare } from 'bcrypt';  @Injectable() export class UsersService {   constructor(     @InjectModel(UserModel.name)     private readonly userModel: Model&lt;UserModel>   ) {}    async findOne(options?: object): Promise&lt;UserDto> {     const user = await this.userModel.findOne(options).exec();     return toUserDto(user);   }    async findByLogin({ username, password }: LoginUserDto): Promise&lt;UserDto> {     const user = await this.userModel.findOne({ username }).exec();      if (!user) {       throw new HttpException('User not found', HttpStatus.UNAUTHORIZED);     }      const areEqual = await compare(password, user.password);      if (!areEqual) {       throw new HttpException('Invalid credentials', HttpStatus.UNAUTHORIZED);     }      return toUserDto(user);   }    async findByPayload({ username }: any): Promise&lt;UserDto> {     return await this.findOne({ username });   }    async create(userDto: CreateUserDto): Promise&lt;UserDto> {     const { username, password, email } = userDto;      const userInDb = await this.userModel.findOne({ username }).exec();     if (userInDb) {       throw new HttpException('User already exists', HttpStatus.BAD_REQUEST);     }      const salt = await genSalt(10);     const hashPassword = await hash(password, salt);      const user: UserModel = await new this.userModel({       username,       password: hashPassword,       email,     });      await user.save();      return toUserDto(user);   }    async setTaskToCurrentUser(_id, taskId) {     await this.userModel.updateOne({ _id }, { $push: { tasks: taskId } });   }    async deleteTaskToCurrentUser(_id, taskId) {     await this.userModel.updateOne({ _id }, { $pull: { tasks: taskId } });   } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u0435\u0440\u0432\u0438\u0441\u0443 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<details class=\"spoiler\">\n<summary>tasks.service.ts<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">import { HttpException, HttpStatus, Injectable } from '@nestjs\/common'; import { InjectModel } from '@nestjs\/mongoose'; import { Model } from 'mongoose'; import { TaskDto } from '.\/dto\/task.dto'; import { TaskModel } from '.\/models\/task.model'; import { UsersService } from '..\/users\/users.service';  @Injectable() export class TasksService {   constructor(     @InjectModel(TaskModel.name)     private readonly taskModel: Model&lt;TaskModel>,     private readonly userService: UsersService   ) {}   async createTask(userId, taskDto: TaskDto) {     const task = await<\/code><\/pre>\n<\/div>\n<\/details>\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-342998","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342998","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=342998"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342998\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}