@@ -28,7 +28,7 @@ export const useItemsStore = defineStore('items', {
2828 ordering : undefined ,
2929 } ) ,
3030 actions : {
31- async retrieveItems ( $axios , apiUrl = undefined , params = { } , cache = true ) {
31+ async retrieveItems ( $axios , apiUrl = undefined , params = { } , cache = true , one = false ) {
3232 const cacheName = apiCacheName ( apiUrl , params )
3333 // Would be nice to amke ordering dynamic as a parameter, perhaps one day
3434 if ( ! ( "limit" in params ) )
@@ -49,10 +49,17 @@ export const useItemsStore = defineStore('items', {
4949 if ( Array . isArray ( res ) ) { // When the endpoint is not paginated
5050 res = { results : res }
5151 }
52- if ( ! cache )
52+ if ( ! cache ) {
53+ if ( one ) {
54+ return res . results [ 0 ]
55+ }
5356 return res
57+ }
5458
5559 this . items [ cacheName ] = res
60+ if ( one ) {
61+ return this . items [ cacheName ] [ 0 ]
62+ }
5663 return this . items [ cacheName ]
5764 } ,
5865 async deleteItem ( $axios , apiUrl , id ) {
@@ -75,38 +82,6 @@ export const useItemsStore = defineStore('items', {
7582 return await this . resolveRefs ( $axios , this . schema [ schemaName ] )
7683 return this . schema [ schemaName ]
7784 } ,
78- async requestOrGetItem ( $axios , apiUrl , filter , params = { } , force = false ) {
79- const cacheName = apiCacheName ( apiUrl , params )
80-
81- if ( force || ! this . items [ cacheName ] ) {
82- await this . retrieveItems ( $axios , apiUrl , params )
83- }
84- return this . items [ cacheName ] . results . find ( item => {
85- for ( const [ key , val ] of Object . entries ( filter ) ) {
86- if ( item [ key ] === null && val === null )
87- continue
88- if ( item [ key ] !== null && item [ key ] . toString ( ) !== val . toString ( ) )
89- return false
90- }
91- return true
92- } )
93- } ,
94- async requestOrGetItems ( $axios , apiUrl , filter , params = { } , force = false ) {
95- const cacheName = apiCacheName ( apiUrl , params )
96-
97- if ( force || ! this . items [ cacheName ] ) {
98- await this . retrieveItems ( $axios , apiUrl , params )
99- }
100- return this . items [ cacheName ] . results . filter ( item => {
101- for ( const [ key , val ] of Object . entries ( filter ) ) {
102- if ( item [ key ] === null && val === null )
103- continue
104- if ( item [ key ] !== null && val !== null && item [ key ] . toString ( ) !== val . toString ( ) )
105- return false
106- }
107- return true
108- } )
109- } ,
11085 async getNextItem ( $axios , apiUrl , itemId , direction = 1 , params = { } , force = false ) {
11186 const cacheName = apiCacheName ( apiUrl , params )
11287
0 commit comments