UNPKG

angular-t9n

Version:
2 lines (1 loc) 1.32 kB
import{a as _}from"./chunk-QTUSJNUZ.js";import{a as d}from"./chunk-DK3NDEDW.js";import{$ as p,C as h,D as m,Ic as f,P as a,W as l,k as o,o as s,u as c}from"./chunk-KWXDDR2S.js";var S=(()=>{class n{constructor(){this._translationService=p(d),this._http=p(f)}orphan(e){return this._translationService.root.pipe(h(1),s(t=>t._links.orphan.href.replace("{id}",e)),a(t=>this._http.get(t)))}orphans(e){let t=_(e);return this._translationService.root.pipe(h(1),s(r=>r._links.orphans.href),a(r=>this._http.get(r,{params:t})))}deleteOrphan(e){return this._http.delete(e._links.self.href)}migrateOrphan(e,t){return this._http.request("DELETE",e._links.self.href,{body:t})}autoMigrateOrphans(e){return this._fetchOrphans().pipe(a(t=>{let r=t.filter(i=>this._canMigrate(i,e)).map(i=>this.migrateOrphan(i,i._embedded.similar[0]).pipe(m(i)));return r.length?c(r):o([])}))}_fetchOrphans(e=0){return this.orphans({page:e,entriesPerPage:250}).pipe(a(t=>t._links.next?this._fetchOrphans(++e).pipe(s(r=>t._embedded.entries.concat(r))):o(t._embedded.entries)))}_canMigrate(e,t){let r=e._embedded?.similar;return r&&r[0].distance<=t&&r.filter(i=>i.distance===r[0].distance).length===1}static{this.\u0275fac=function(t){return new(t||n)}}static{this.\u0275prov=l({token:n,factory:n.\u0275fac,providedIn:"root"})}}return n})();export{S as a};