LP1936233 Solidify pcrud parameters
authorBill Erickson <berickxx@gmail.com>
Mon, 21 Jun 2021 21:49:54 +0000 (17:49 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 14 Jul 2021 15:24:02 +0000 (11:24 -0400)
Define the query options users pass into a pcrud call (order_by, limit,
etc.) as an interface to enforce correct use.

And fix a few incorrect pcrud requests that snuck in along the way.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/pcrud.service.ts
Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts
Open-ILS/src/eg2/src/app/staff/share/course.service.ts
Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts

index 7fb0c7c..1443718 100644 (file)
@@ -8,6 +8,16 @@ import {AuthService} from './auth.service';
 declare var js2JSON: (jsThing: any) => string;
 declare var OpenSRF: any; // creating sessions
 
+export interface PcrudQueryOps {
+    order_by?: any;
+    limit?: number;
+    offset?: number;
+    flesh?: number;
+    flesh_fields?: any;
+    select?: any;
+    join?: any;
+}
+
 interface PcrudReqOps {
     authoritative?: boolean;
     anonymous?: boolean;
@@ -140,7 +150,7 @@ export class PcrudContext {
     }
 
     retrieve(fmClass: string, pkey: Number | string,
-            pcrudOps?: any, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
+            pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         reqOps = reqOps || {};
         this.authoritative = reqOps.authoritative || false;
         if (reqOps.fleshSelectors) {
@@ -151,7 +161,7 @@ export class PcrudContext {
              [this.token(reqOps), pkey, pcrudOps]);
     }
 
-    retrieveAll(fmClass: string, pcrudOps?: any,
+    retrieveAll(fmClass: string, pcrudOps?: PcrudQueryOps,
             reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         const search = {};
         search[this.idl.classes[fmClass].pkey] = {'!=' : null};
@@ -159,7 +169,7 @@ export class PcrudContext {
     }
 
     search(fmClass: string, search: any,
-            pcrudOps?: any, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
+            pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         reqOps = reqOps || {};
         this.authoritative = reqOps.authoritative || false;
 
@@ -334,17 +344,17 @@ export class PcrudService {
     }
 
     retrieve(fmClass: string, pkey: Number | string,
-        pcrudOps?: any, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
+        pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         return this.newContext().retrieve(fmClass, pkey, pcrudOps, reqOps);
     }
 
-    retrieveAll(fmClass: string, pcrudOps?: any,
+    retrieveAll(fmClass: string, pcrudOps?: PcrudQueryOps,
         reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         return this.newContext().retrieveAll(fmClass, pcrudOps, reqOps);
     }
 
     search(fmClass: string, search: any,
-        pcrudOps?: any, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
+        pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable<PcrudResponse> {
         return this.newContext().search(fmClass, search, pcrudOps, reqOps);
     }
 
index cd52d44..f2c4e47 100644 (file)
@@ -196,7 +196,7 @@ export class VandelayService {
 
         return this.pcrud.search('vibtg',
             {always_apply : 'f', owner: owners},
-            {vibtg : ['label']},
+            {order_by: {vibtg : 'label'}},
             {atomic: true}
         ).toPromise().then(groups => {
             this.bibTrashGroups = groups;
index 080626b..28ef814 100644 (file)
@@ -89,7 +89,7 @@ export class CourseService {
     fetchCoursesForRecord(recordId) {
         const courseIds = new Set<number>();
         return this.pcrud.search(
-            'acmcm', {record: recordId}, {atomic: false}
+            'acmcm', {record: recordId}
         ).pipe(tap(material => {
             courseIds.add(material.course());
         })).toPromise()
index dfd2044..371a36a 100644 (file)
@@ -107,10 +107,10 @@ export class CopyAlertsDialogComponent
         if (this.alertTypes) {
             return Promise.resolve();
         }
-        return this.pcrud.retrieveAll('ccat',
-        {   active: true,
+        return this.pcrud.search('ccat',
+        {   active: 't',
             scope_org: this.org.ancestors(this.auth.user().ws_ou(), true)
-        }, {atomic: true}
+        }, {}, {atomic: true}
         ).toPromise().then(alerts => {
             this.alertTypes = alerts.map(a => ({id: a.id(), label: a.name()}));
         });
@@ -133,6 +133,7 @@ export class CopyAlertsDialogComponent
     getCopyAlerts(): Promise<any> {
         const copyIds = this.copies.map(c => c.id());
         const typeIds = this.alertTypes.map(a => a.id);
+        if (typeIds.length === 0) { return Promise.resolve(null); }
 
         return this.pcrud.search('aca',
             {copy: copyIds, ack_time: null, alert_type: typeIds},