From: Bill Erickson Date: Mon, 21 Jun 2021 21:49:54 +0000 (-0400) Subject: LP1936233 Solidify pcrud parameters X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5a0cd60d41c5135bffdbebe837edb3cd4c1924ed;p=working%2FEvergreen.git 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 --- 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 7fb0c7ccf6..1443718aff 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 cd52d44e1f..f2c4e476ec 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 @@ -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; 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 080626b8ef..28ef814be9 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 @@ -89,7 +89,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 dfd20449c3..371a36ae7f 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 @@ -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 { 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},