This repository was archived by the owner on May 27, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +54
-36
lines changed
Expand file tree Collapse file tree 5 files changed +54
-36
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ import {
6767 Svg ,
6868 SvgSet ,
6969 Tag ,
70+ TagType ,
7071 User ,
7172} from './resources' ;
7273import ResourceBase from './resources/base/ResourceBase' ;
@@ -336,6 +337,15 @@ export default class Maps4News extends mix(null, Injectable) {
336337 return this . static ( Tag ) ;
337338 }
338339
340+ /**
341+ * Tag accessor
342+ * @see {@link Tag }
343+ * @returns {ResourceProxy } - A proxy for accessing the resource
344+ */
345+ get tagTypes ( ) {
346+ return this . static ( TagType ) ;
347+ }
348+
339349 /**
340350 * Contract accessor
341351 * @see {@link Contract }
Original file line number Diff line number Diff line change 3030 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131 */
3232
33- import CrudBase from './base/CrudBase' ;
3433import OwnableResource from '../traits/OwnableResource' ;
3534import { mix } from '../utils/reflection' ;
35+ import CrudSetItemBase from './base/CrudSetItemBase' ;
3636
3737/**
3838 * Tag resource
39- * @extends CrudBase
39+ * @extends CrudSetItemBase
4040 * @mixes OwnableResource
4141 */
42- export default class Tag extends mix ( CrudBase , OwnableResource ) {
42+ export default class Tag extends mix ( CrudSetItemBase , OwnableResource ) {
4343 static get resourceName ( ) {
4444 return 'tags' ;
4545 }
46+
47+ static get parentKey ( ) {
48+ return 'tag_type_id' ;
49+ }
4650}
Original file line number Diff line number Diff line change 3030 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131 */
3232
33+ import CrudSetBase from './base/CrudSetBase' ;
34+ import Tag from './Tag' ;
3335
34- import moxios from 'moxios' ;
35- import Maps4News from '../../src/Maps4News' ;
36-
37- const api = new Maps4News ( 'token' , 'https://example.com' ) ;
38-
39- test ( 'lister update should stop if it gets a 500' , async ( ) => {
40- moxios . wait ( ( ) => {
41- const request = moxios . requests . mostRecent ( ) ;
42-
43- request . respondWith ( {
44- status : 500 ,
45- response : {
46- success : false ,
47- error : {
48- type : 'ServerError' ,
49- message : 'Something broke' ,
50- } ,
51- } ,
52- } ) ;
53- } ) ;
36+ /**
37+ * TagType resource
38+ * @mixes CrudSetBase
39+ */
40+ export default class TagType extends CrudSetBase {
41+ static get resourcePath ( ) {
42+ return '/tags/types/{id}' ;
43+ }
5444
55- const lister = api . users . lister ( { } , 0 ) ;
45+ static get resourceName ( ) {
46+ return 'tag-types' ;
47+ }
5648
57- lister . autoUpdate = false ;
49+ get _Child ( ) {
50+ return Tag ;
51+ }
5852
59- lister . maxRows = 50 ;
53+ /**
54+ * Get items associated with the set
55+ * @returns {SimpleResourceProxy } - A proxy for accessing the resource
56+ */
57+ get items ( ) {
58+ const data = { [ this . constructor . foreignKeyName ] : this . id } ;
6059
61- try {
62- await lister . update ( ) ;
63- } catch ( error ) {
64- expect ( error . type ) . toEqual ( 'ServerError' ) ;
65- expect ( error . message ) . toEqual ( 'Something broke' ) ;
60+ return this . _proxyResourceList ( this . _Child , `${ this . url } /tags` , data ) ;
6661 }
67- } ) ;
68-
62+ }
Original file line number Diff line number Diff line change 3232
3333import { AbstractClassError } from '../../errors/AbstractError' ;
3434import CrudBase from './CrudBase' ;
35+ import { camel as camelCase } from 'case' ;
3536
3637/**
3738 * Items that are part of a set
@@ -50,16 +51,24 @@ export default class CrudSetItemBase extends CrudBase {
5051 }
5152 }
5253
54+ get hasParent ( ) {
55+ const parentKey = camelCase ( this . constructor . parentKey ) ;
56+
57+ return this . hasOwnProperty ( parentKey ) ;
58+ }
59+
5360 /**
5461 * Get the parent id
55- * @returns {? number|undefined } - Parent number
62+ * @returns {number|undefined } - Parent number
5663 */
5764 get parentId ( ) {
5865 if ( this . hasParent ) {
59- return Number ( this [ this . constructor . parentKey ] ) ;
66+ const parentKey = camelCase ( this . constructor . parentKey ) ;
67+
68+ return Number ( this [ parentKey ] ) ;
6069 }
6170
62- return [ ] [ 0 ] ; // same as "undefined"
71+ return void 0 ;
6372 }
6473
6574 /**
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ export Role from './Role';
6060export Svg from './Svg' ;
6161export SvgSet from './SvgSet' ;
6262export Tag from './Tag' ;
63+ export TagType from './TagType' ;
6364export User from './User' ;
6465
6566import CrudBase from './base/CrudBase' ;
You can’t perform that action at this time.
0 commit comments