Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typeorm decrement

 /**Follow the example below**/
import { Product } from './../entities/product.entity';
import { EntityRepository, Repository, getManager } from 'typeorm';
import { Sales } from './../entities/sales.entity';
import { CreateSaleDto } from './../sales/dto/create-sale.dto';

@EntityRepository(Sales)
export class SalesRepository extends Repository<Sales> {
  
  private dataSource = getManager(); // EntityManager
    /**
   * This function will reduce the inventory of a product by a given quantity.
   * @param {number} id - number - the id of the product
   * @param {any} qty - number
   */
  private async reduceInventoryProduct(id: number, qty: any) {
    //inventory_min: It is the existing inventory of products and we are going to decrease as products are sold.
    // inventory_min: It is the field found in the products table in the database
    await this.dataSource.decrement(Product, { id: id }, 'inventory_min', qty);
  }
  	
}	

Source by github.com #
 
PREVIOUS NEXT
Tagged: #typeorm #decrement
ADD COMMENT
Topic
Name
1+8 =