jin-qu/jinqu-odata

Insert/Update/Delete operations

Closed this issue · 2 comments

jinqu-odata version

1.1.3

Proposed behavior

Insert/Update/Delete entity operations (POST/PUT/DELETE http requests respectively) on ODataService:

  1. setData(entity) query method for setting http request body;
  2. async query methods for each operation:
    a) insertAsync(true/false):
    • with optinal argument, true means returning an inserted entity (currently OData service returns it by default);
    • returns an inserted entity.
      b) insertAsync(true/false):
    • with optinal argument, true means returning an updated entity (appends 'prefer' http header);
    • returns an inserted entity if requested.
      c) insertAsync()

It should allow following scenarios:

// insert
const prod = new Product();
prod.productName = "Cherry";
prod.unitPrice = 10.35;
const insProd = await dataService.products
  .setData(prod)
  .insertAsync(true);
const id = insProd.productId;

// update
const prod = await dataService.products
  .byKey(5)
  .singleAsync();
prod.unitPrice = prod.unitPrice * 1.05;
const updProd = await dataService.products
  .byKey(5)
  .setData(prod)
  .updateAsync(true);

// delete
const prod = await dataService.products
  .byKey(5)
  .singleAsync();
await dataService.products
  .byKey(5)
  .deleteAsync();

Actual behavior

Not implemented

Again, already implemented in my repository

More propositions for updating entities:

  1. Setting "PATCH" as default HTTP method for updating entities
  2. Providing an ODataService option for specifying the preferred HTTP method for updating entities to override the default value
  3. IODataServiceOptions interface as an argument to ODataService constructor to specify all initialization options
    (old constructor signature preserved):
  export interface IODataServiceOptions<TResponse> {
    baseAddress?: string;
    ajaxProvider?: IAjaxProvider<TResponse>;
    updateMethod?: "PATCH" | "PUT";
  }
...
  constructor(baseAddress?: string | null, ajaxProvider?: IAjaxProvider<TResponse>);
  constructor(options?: IODataServiceOptions<TResponse>);
  1. User should be able to override the preferred update method for particular query with .withOptions() call

Updates are already merged into my repository.

PS. When passing "updateMethod" option from ODataService to ODataQuery.updateAsync method, I used "as any" twice, which was not elegant. It probably requires refactoring