update shared objects among models
- add optional defaultKey, defaultValue to meta data - move REST _links object to model shared - add _links collection to coupons
This commit is contained in:
parent
a106807c51
commit
7a892f61d2
|
@ -12,6 +12,7 @@ import {
|
||||||
import {
|
import {
|
||||||
CouponUpdateParams,
|
CouponUpdateParams,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
import { ObjectLinks } from '../shared-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The parameters embedded in this generic can be used in the ModelRepository in order to give
|
* The parameters embedded in this generic can be used in the ModelRepository in order to give
|
||||||
|
@ -222,6 +223,16 @@ export class Coupon extends Model {
|
||||||
*/
|
*/
|
||||||
public readonly usedBy: Array<string> = [];
|
public readonly usedBy: Array<string> = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The coupon's links.
|
||||||
|
*
|
||||||
|
* @type {ReadonlyArray.<ObjectLinks>}
|
||||||
|
*/
|
||||||
|
public readonly links: ObjectLinks = {
|
||||||
|
collection: [ { href: '' } ],
|
||||||
|
self: [ { href: '' } ],
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new coupon instance with the given properties
|
* Creates a new coupon instance with the given properties
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,9 +3,9 @@ import { ModelID } from '../../model';
|
||||||
import {
|
import {
|
||||||
CatalogVisibility,
|
CatalogVisibility,
|
||||||
ProductTerm,
|
ProductTerm,
|
||||||
ProductLinks,
|
|
||||||
ProductAttribute,
|
ProductAttribute,
|
||||||
} from '../shared';
|
} from '../shared';
|
||||||
|
import { ObjectLinks } from '../../shared-types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The common parameters that all products can use in search.
|
* The common parameters that all products can use in search.
|
||||||
|
@ -137,11 +137,11 @@ export abstract class AbstractProduct extends AbstractProductData {
|
||||||
public readonly attributes: readonly ProductAttribute[] = [];
|
public readonly attributes: readonly ProductAttribute[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The products links.
|
* The product's links.
|
||||||
*
|
*
|
||||||
* @type {ReadonlyArray.<ProductLinks>}
|
* @type {ReadonlyArray.<ObjectLinks>}
|
||||||
*/
|
*/
|
||||||
public readonly links: ProductLinks = {
|
public readonly links: ObjectLinks = {
|
||||||
collection: [ { href: '' } ],
|
collection: [ { href: '' } ],
|
||||||
self: [ { href: '' } ],
|
self: [ { href: '' } ],
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Model } from '../../model';
|
import { Model } from '../../model';
|
||||||
import { MetaData, PostStatus } from '../../shared-types';
|
import { MetaData, PostStatus, ObjectLinks } from '../../shared-types';
|
||||||
import { ProductImage, ProductLinks } from '../shared';
|
import { ProductImage } from '../shared';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base product data.
|
* Base product data.
|
||||||
|
@ -93,9 +93,9 @@ export abstract class AbstractProductData extends Model {
|
||||||
/**
|
/**
|
||||||
* The product data links.
|
* The product data links.
|
||||||
*
|
*
|
||||||
* @type {ReadonlyArray.<ProductLinks>}
|
* @type {ReadonlyArray.<ObjectLinks>}
|
||||||
*/
|
*/
|
||||||
public readonly links: ProductLinks = {
|
public readonly links: ObjectLinks = {
|
||||||
collection: [ { href: '' } ],
|
collection: [ { href: '' } ],
|
||||||
self: [ { href: '' } ],
|
self: [ { href: '' } ],
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,59 +208,3 @@ export class ProductImage {
|
||||||
Object.assign( this, properties );
|
Object.assign( this, properties );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A product link item.
|
|
||||||
*/
|
|
||||||
class ProductLinkItem {
|
|
||||||
/**
|
|
||||||
* The options which are available for the attribute.
|
|
||||||
*
|
|
||||||
* @type {ReadonlyArray.<string>}
|
|
||||||
*/
|
|
||||||
public readonly href: string = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new product link item.
|
|
||||||
*
|
|
||||||
* @param {Partial.<ProductLinkItem>} properties The properties to set.
|
|
||||||
*/
|
|
||||||
public constructor( properties?: Partial< ProductLinkItem > ) {
|
|
||||||
Object.assign( this, properties );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A product's links.
|
|
||||||
*/
|
|
||||||
export class ProductLinks {
|
|
||||||
/**
|
|
||||||
* The collection containing the product.
|
|
||||||
*
|
|
||||||
* @type {ReadonlyArray.<ProductLinkItem>}
|
|
||||||
*/
|
|
||||||
public readonly collection: readonly ProductLinkItem[] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Self referential link to the product.
|
|
||||||
*
|
|
||||||
* @type {ReadonlyArray.<ProductLinkItem>}
|
|
||||||
*/
|
|
||||||
public readonly self: readonly ProductLinkItem[] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The link to the parent.
|
|
||||||
*
|
|
||||||
* @type {ReadonlyArray.<ProductLinkItem>}
|
|
||||||
*/
|
|
||||||
public readonly up?: readonly ProductLinkItem[] = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new product link list.
|
|
||||||
*
|
|
||||||
* @param {Partial.<ProductLinks>} properties The properties to set.
|
|
||||||
*/
|
|
||||||
public constructor( properties?: Partial< ProductLinks > ) {
|
|
||||||
Object.assign( this, properties );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,13 +15,13 @@ import {
|
||||||
ProductPriceUpdateParams,
|
ProductPriceUpdateParams,
|
||||||
ProductSalesTaxUpdateParams,
|
ProductSalesTaxUpdateParams,
|
||||||
ProductShippingUpdateParams,
|
ProductShippingUpdateParams,
|
||||||
ProductLinks,
|
|
||||||
Taxability,
|
Taxability,
|
||||||
ProductDownload,
|
ProductDownload,
|
||||||
StockStatus,
|
StockStatus,
|
||||||
BackorderStatus,
|
BackorderStatus,
|
||||||
ProductDefaultAttribute,
|
ProductDefaultAttribute,
|
||||||
} from './shared';
|
} from './shared';
|
||||||
|
import { ObjectLinks } from '../shared-types';
|
||||||
import {
|
import {
|
||||||
CreatesChildModels,
|
CreatesChildModels,
|
||||||
DeletesChildModels,
|
DeletesChildModels,
|
||||||
|
@ -149,11 +149,11 @@ export class ProductVariation extends AbstractProductData implements
|
||||||
public readonly shippingClassId: number = 0;
|
public readonly shippingClassId: number = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The variation links.
|
* The variation's links.
|
||||||
*
|
*
|
||||||
* @type {ReadonlyArray.<ProductLinks>}
|
* @type {ReadonlyArray.<ObjectLinks>}
|
||||||
*/
|
*/
|
||||||
public readonly links: ProductLinks = {
|
public readonly links: ObjectLinks = {
|
||||||
collection: [ { href: '' } ],
|
collection: [ { href: '' } ],
|
||||||
self: [ { href: '' } ],
|
self: [ { href: '' } ],
|
||||||
up: [ { href: '' } ],
|
up: [ { href: '' } ],
|
||||||
|
|
|
@ -35,6 +35,20 @@ export class MetaData extends Model {
|
||||||
*/
|
*/
|
||||||
public readonly value: any = '';
|
public readonly value: any = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The key of the metadata.
|
||||||
|
*
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
public readonly displayKey?: string = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value of the metadata.
|
||||||
|
*
|
||||||
|
* @type {*}
|
||||||
|
*/
|
||||||
|
public readonly displayValue?: string = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new metadata.
|
* Creates a new metadata.
|
||||||
*
|
*
|
||||||
|
@ -45,3 +59,59 @@ export class MetaData extends Model {
|
||||||
Object.assign( this, properties );
|
Object.assign( this, properties );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object link item.
|
||||||
|
*/
|
||||||
|
class LinkItem {
|
||||||
|
/**
|
||||||
|
* The href of the link.
|
||||||
|
*
|
||||||
|
* @type {ReadonlyArray.<string>}
|
||||||
|
*/
|
||||||
|
public readonly href: string = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new product link item.
|
||||||
|
*
|
||||||
|
* @param {Partial.<LinkItem>} properties The properties to set.
|
||||||
|
*/
|
||||||
|
public constructor( properties?: Partial< LinkItem > ) {
|
||||||
|
Object.assign( this, properties );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object's links.
|
||||||
|
*/
|
||||||
|
export class ObjectLinks {
|
||||||
|
/**
|
||||||
|
* The collection containing the object.
|
||||||
|
*
|
||||||
|
* @type {ReadonlyArray.<LinkItem>}
|
||||||
|
*/
|
||||||
|
public readonly collection: readonly LinkItem[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Self referential link to the object.
|
||||||
|
*
|
||||||
|
* @type {ReadonlyArray.<LinkItem>}
|
||||||
|
*/
|
||||||
|
public readonly self: readonly LinkItem[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The link to the parent object.
|
||||||
|
*
|
||||||
|
* @type {ReadonlyArray.<LinkItem>}
|
||||||
|
*/
|
||||||
|
public readonly up?: readonly LinkItem[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new product link list.
|
||||||
|
*
|
||||||
|
* @param {Partial.<ObjectLinks>} properties The properties to set.
|
||||||
|
*/
|
||||||
|
public constructor( properties?: Partial< ObjectLinks > ) {
|
||||||
|
Object.assign( this, properties );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ export function createCouponTransformer(): ModelTransformer< Coupon > {
|
||||||
maximumAmount: 'maximum_amount',
|
maximumAmount: 'maximum_amount',
|
||||||
emailRestrictions: 'email_restrictions',
|
emailRestrictions: 'email_restrictions',
|
||||||
usedBy: 'used_by',
|
usedBy: 'used_by',
|
||||||
|
links: '_links',
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
CreateChildFn,
|
CreateChildFn,
|
||||||
ModelTransformer,
|
ModelTransformer,
|
||||||
IgnorePropertyTransformation,
|
IgnorePropertyTransformation,
|
||||||
|
KeyChangeTransformation,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
ModelParentID,
|
ModelParentID,
|
||||||
} from '../../framework';
|
} from '../../framework';
|
||||||
|
@ -34,6 +35,12 @@ export function createMetaDataTransformer(): ModelTransformer< MetaData > {
|
||||||
return new ModelTransformer(
|
return new ModelTransformer(
|
||||||
[
|
[
|
||||||
new IgnorePropertyTransformation( [ 'id' ] ),
|
new IgnorePropertyTransformation( [ 'id' ] ),
|
||||||
|
new KeyChangeTransformation< MetaData >(
|
||||||
|
{
|
||||||
|
displayKey: 'display_key',
|
||||||
|
displayValue: 'display_value',
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue