User Tools

Site Tools


newdevs:angular_making_calls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
newdevs:angular_making_calls [2023/12/12 19:26] – add a netservice retrieve example sandbergjanewdevs:angular_making_calls [2024/03/28 23:08] – [Deleting data in the database] add examples sandbergja
Line 137: Line 137:
  
 ===== Updating data in the database ===== ===== Updating data in the database =====
 +==== PcrudService example ====
  
-Examples coming soon+The basic workflow for updating data in the database is to:
  
 +  - Retrieve the object you wish to change.
 +  - Make your changes in memory.
 +  - Use the Pcrud service's ''update'' method to save the change to the database.
  
 +
 +The following example retrieves the item with ID #1, changes its barcode to 1234567 in memory, then saves the updated barcode to the database:
 +
 +    this.pcrud.retrieve('acp', 1)
 +        .pipe(switchMap((item) => {
 +            item.barcode('1234567');
 +            return this.pcrud.update(item);
 +    })).subscribe();
 +
 +Notice that we use the rxjs ''switchMap'' operator to switch our observable halfway through, from a `retrieve` call to an `update` call.  This helps us to avoid nesting RxJs subscriptions within each other, which can get very complicated to troubleshoot.
 +
 +
 +==== NetService example ====
 +
 +coming soon
 ===== Deleting data in the database ===== ===== Deleting data in the database =====
  
-Examples coming soon+==== PcrudService example ==== 
 + 
 +As with updating objects, you will need to retrieve an object and have a copy in memory before you can delete it.  The following example searches for all shelving locations called "Microfilm" and then deletes them, one by one: 
 + 
 +  this.pcrud.search('acpl', 
 +                     {name: 'Microfilm'}) 
 +       .pipe(switchMap((location) => { 
 +           return this.pcrud.remove(location); 
 +       })).subscribe(); 
 + 
 + 
 +==== NetService example ==== 
 + 
 +Here's an example of deleting record bucket #13 from the database, along with all its bucket entries (assuming the currently logged in user has the DELETE_CONTAINER permission):
  
 +   this.net.request('open-ils.actor',
 +                    'open-ils.actor.container.full_delete',
 +                    this.auth.token(),
 +                    'biblio',
 +                    13).subscribe(() => {
 +        alert('Your bucket is gone!');
 +    });
 ===== Troublsehooting OpenSRF calls in your browser ===== ===== Troublsehooting OpenSRF calls in your browser =====
  
newdevs/angular_making_calls.txt · Last modified: 2024/03/28 23:16 by sandbergja

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.