sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Support Transaction Decorator like Java Spring

Open yeongjet opened this issue 4 years ago • 3 comments

  @Transactional
  public void update(CategoryUpdateParam param){
    
    if(! Strings.isNullOrEmpty(param.getName())) {
      changeName(param.getShopId(), param.getId(), param.getName());
    }else if(param.getParentId()!=null) {
      changeParent(param.getShopId(), param.getId(), param.getParentId());
    }
  }
  
  @Transactional
  public void changeName(Long shopId, Long categoryId, String name){
    Category category = findById(shopId,categoryId);
    category.changeName(name);
    categoryRepo.save(category);
  }

  @Transactional
  public void changeParent(Long shopId, Long categoryId, Long parentId){
    
    Category category = findById(shopId,categoryId)
        .loadParent()
        .loadDescendants();
    
    Category parent = findById(shopId,parentId);
    
    category.changeParent(parent);
    
    categoryRepo.save(category);
}

That will be convenient if support this feature

yeongjet avatar Jan 17 '20 03:01 yeongjet