title: Object TypeScript
body: <p>I want to send data from a form in VueJS with Axios.
  But i don't know how to write my object before send it</p>
  
  <p><strong>View :</strong></p>
  
  <pre><code>    methods: {
      createPost() {
        let autorData = {
          nom: this.nom,
        }
        let postData = {
          titre: this.titre,
          auteur: autorData,
          contenu: this.contenu,
        };
        this.__submitToServer(postData);
      },
      __submitToServer(data) {
        axios.post(`${server.baseURL}/post/create`, data).then(data =&gt; {
          router.push({ name: "home" });
        });
      }
    }
  </code></pre>
  
  <p><strong>Controller :</strong></p>
  
  <pre><code>
      import { Controller, Get, Res, HttpStatus, Param, Post, Body, NotFoundException } from '@nestjs/common';
      import { PostService } from './post.service';
      import { CreatePostDTO } from './dto/create-post.dto';
  
      @Controller('post')
      export class PostController {
          constructor(private readonly postService: PostService) { }
  
          ...
  
          @Post('/create')
          async addPost(@Res() res, @Body() createPostDTO: CreatePostDTO) {
              const post = await this.postService.addPost(createPostDTO);
              return res.status(HttpStatus.OK).json({
                  message: "Post has been created successfully",
                  post
              })
          }
      }
  
  </code></pre>
  
  <p><strong>Model : CreatePostDTO</strong></p>
  
  <pre><code>
      import { User } from 'src/user/interfaces/user.interface';
  
      export class CreatePostDTO {
          readonly titre: string;
          readonly auteur: User;
          readonly contenu: string;
      }
  
  </code></pre>
  
  <p><strong>Model : interface User</strong></p>
  
  <pre><code>    export interface User extends Document {
          readonly nom: string;
      }
  
  </code></pre>
  
  <p>How can I make it understand that's the "author" data is a sub-object of my "post" ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>Error from the server</strong></p>
  
  <pre><code>
  
  
      ValidationError: Post validation failed: auteur: Cast to ObjectID failed for value "{}" at path "autor"
                    ...
                    at PostService.addPost (C:\Users\me\Desktop\Try\VueJS_NestJS_MongoDB\diy\customer-list-app-backend\src\post\post.s          at C:\Users\yann.surzur\Desktop\Try\VueJS_NestJS_MongoDB\diy\customer-list-app-backend\src\post\post.controller.ts:19:71
                  message: 'Cast to ObjectID failed for value "{}" at path "autor"',        name: 'CastError',
                  stringValue: '"{}"',
                  kind: 'ObjectID',
                  value: {},
                  path: 'autor',
                  reason: [MongooseError] } },
            _message: 'Post validation failed',
            name: 'ValidationError' 
  
  
  </code></pre>
  
  <p>The problem is there : 'Cast to ObjectID failed for value "{}" at path "autor"'.
  That's why i think i made a mistake when i wrote the data before sent it.</p>