title: Node.js and sequelize-typescript - data access objects and business objects
body: <p>I am using the <a href="https://github.com/RobinBuschmann/sequelize-typescript" rel="nofollow noreferrer">sequelize-typescript</a> in my Node.js service</p>
  
  <p>I have the <code>Category</code> class which maps to category table</p>
  
  <pre class="lang-ts prettyprint-override"><code>import { Model, Table, Column } from "sequelize-typescript";
  
  @Table
  export class Category extends Model&lt;Category&gt;{
  
      @Column
      name: string
  }
  </code></pre>
  
  <p>I also have <code>CategoryController</code> and <code>CategoryService</code></p>
  
  <pre class="lang-ts prettyprint-override"><code>export class CategoryController {
  
      ...
  
      async getAll(request: Request, response: Response) {
          let categories = await this.categoryService.getCatergories(); 
          response.json(categories)
      }
  }
  
  export class CategoryService {
  
      async getCatergories(): Promise&lt;Category[]&gt; {
          let categories = await Category.findAll&lt;Category&gt;()
          return categories
      }
  
  }
  </code></pre>
  
  <p>And everything is as it should be.</p>
  
  <p>But returning a <code>Category</code> to the controller allows it to use the use the <strong>inherited methods</strong> from the model class like:</p>
  
  <pre class="lang-ts prettyprint-override"><code>export class CategoryController {
  
      ...
  
      async getAll(request: Request, response: Response) {
           let categories = await this.categoryService.getCatergories();
  
          // Remove associated row in the database
          categories[0].destroy()
  
          response.json(categories)
      }
  }
  </code></pre>
  
  <p>I was thinking to create a <code>CategoryModel</code> class like this:</p>
  
  <pre class="lang-ts prettyprint-override"><code>export class CategoryModel {
      id : number 
      name : string
  }
  </code></pre>
  
  <p>And modify all methods in <code>CategoryService</code> to return <code>CategoryModel</code> instances instead of <code>Category</code> and rename <code>Category</code> to <code>CategoryEntity</code></p>
  
  <p>What is the best way to deal with such a problem?</p>