From d02cef22fe48703c6569d0705bac50cbeb149318 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 21 Jun 2021 17:49:54 -0400 Subject: [PATCH] LP1936233 Solidify pcrud parameters 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 --- Open-ILS/src/eg2/src/app/core/pcrud.service.ts | 22 ++++++++++++++++------ .../src/app/staff/cat/vandelay/vandelay.service.ts | 2 +- .../src/eg2/src/app/staff/share/course.service.ts | 2 +- .../share/holdings/copy-alerts-dialog.component.ts | 5 +++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/core/pcrud.service.ts b/Open-ILS/src/eg2/src/app/core/pcrud.service.ts index d95869edd7..d2f8d7db8e 100644 --- a/Open-ILS/src/eg2/src/app/core/pcrud.service.ts +++ b/Open-ILS/src/eg2/src/app/core/pcrud.service.ts @@ -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 { + pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable { 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 { 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 { + pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable { 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 { + pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable { return this.newContext().retrieve(fmClass, pkey, pcrudOps, reqOps); } - retrieveAll(fmClass: string, pcrudOps?: any, + retrieveAll(fmClass: string, pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable { return this.newContext().retrieveAll(fmClass, pcrudOps, reqOps); } search(fmClass: string, search: any, - pcrudOps?: any, reqOps?: PcrudReqOps): Observable { + pcrudOps?: PcrudQueryOps, reqOps?: PcrudReqOps): Observable { return this.newContext().search(fmClass, search, pcrudOps, reqOps); } diff --git a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts index 7b228b48a3..eeb3af46b6 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/vandelay/vandelay.service.ts @@ -195,7 +195,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; diff --git a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts index 12a030382d..0db6c311e0 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -102,7 +102,7 @@ export class CourseService { fetchCoursesForRecord(recordId) { const courseIds = new Set(); return this.pcrud.search( - 'acmcm', {record: recordId}, {atomic: false} + 'acmcm', {record: recordId} ).pipe(tap(material => { courseIds.add(material.course()); })).toPromise() diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts index 4cfce2bdc0..bbb1ca975d 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/copy-alerts-dialog.component.ts @@ -103,10 +103,10 @@ export class CopyAlertsDialogComponent getAlertTypes(): Promise { if (this.alertTypes) { return Promise.resolve(); } - return this.pcrud.retrieveAll('ccat', + return this.pcrud.search('ccat', { active: true, 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 // the alert type. getCopyAlerts(): Promise { const typeIds = this.alertTypes.map(a => a.id); + if (typeIds.length === 0) { return Promise.resolve(null); } return this.pcrud.search('aca', {copy: this.copyIds, ack_time: null, alert_type: typeIds}, -- 2.11.0