Problem with Custom Object Types

Hi.
By this docs Type Annotations - Developing Backendless Server Code with node.js and
Service Development - Developing Backendless Server Code with node.js
I’m trying to use Custom Object Types

 /**
  * @property {string} text
  * @property {string} restaurant
  * @property {FileParameter} preview
  * @property {string} title
  */
 export class CreatePostDTO extends Backendless.ServerCode.PersistenceItem {
  constructor(public text: string, public restaurant: string, public preview: FileParameter, public title: string) {
    super();
    this.text = text;
    this.restaurant = restaurant;
    this.preview = preview;
    this.title = title;
  }
}
module.exports = Backendless.ServerCode.addType(CreatePostDTO);

  /**
  * @property {string} data
  * @property {string} name
  */
export class FileParameter extends Backendless.ServerCode.PersistenceItem {
  constructor(public data: string, public name: string) {
    super();
    this.data = data;
    this.name = name;
  }
};
module.exports = Backendless.ServerCode.addType(FileParameter);

/**
   * @route POST /restaurant/post
   * @param {CreatePostDTO} post
   */
  @AuthGuard({ roles: [UserRole.Restaurant] })
  async createRestaurantPost(post: CreatePostDTO): Promise<PostById> {
.....

Fine, I have the schema
image

But I can’t use this API because of this error

400 - Class constructor CreatePostDTO cannot be invoked without 'new'
Body:
{
    "code": 0,
    "message": "Class constructor CreatePostDTO cannot be invoked without 'new'",
    "errorData": {}
}
 "compilerOptions": {
        "incremental": true,
        "composite": true,
        "target": "es2016",

Any idea how to solve this? Or may be you have working sample with Custom Object Types?

Hi @Alex2

Welcome to the Backendless community!

The PersistenceItem class expects the first argument as an object of the data of the instance

So, if you remove constructors it resolve all instances automatically

/*Created on 12/21/2023 12:39:10.*/

/**
  * @property {string} text
  * @property {string} restaurant
  * @property {FileParameter} preview
  * @property {string} title
  */
 class CreatePostDTO extends Backendless.ServerCode.PersistenceItem {

}

Backendless.ServerCode.addType(CreatePostDTO);

  /**
  * @property {string} data
  * @property {string} name
  */
class FileParameter extends Backendless.ServerCode.PersistenceItem {
  getName(){
    return this.name
  }
};

Backendless.ServerCode.addType(FileParameter);

class MyService{
  

/**
   * @route POST /restaurant/post
   * @param {CreatePostDTO} post
   */
  async createRestaurantPost(post) {
    console.log('post', post)
    console.log('post.preview.getName', post.preview.getName())
    
    return post
  }
  
}  
  
Backendless.ServerCode.addService(MyService)
13:16:41.504 | SERVER_CODE | INFO | [35982] post CreatePostDTO { ___class: 'CreatePostDTO', preview: FileParameter { ___class: 'FileParameter', data: 'string', name: 'string' }, restaurant: 'string', text: 'string', title: 'string' }
13:16:41.504 | SERVER_CODE | INFO | [35982] post.preview.getName string

Thanks. Solved!