@apicart/store-sdk
Version:
Apicart SDK for integrating store into any web application
94 lines (73 loc) • 2.21 kB
text/typescript
import Apicart from '@apicart/core-sdk';
import { DataSourceInterface } from '../../Contract/DataSource/DataSourceInterface';
import ShippingMethod from '../../Entity/Shipping/ShippingMethod';
import { ShippingMethodDaoInterface } from '../../Contract/Dao/Shipping/ShippingMethodDaoInterface';
export default class ShippingMethodDao implements ShippingMethodDaoInterface
{
private _id: number;
private _dataSource: DataSourceInterface
private _shippingMethod: ShippingMethod | null = null;
private _shippingMethodPromise: Promise<ShippingMethod | null> | null = null;
constructor(dataSource: DataSourceInterface, id: number)
{
this._dataSource = dataSource;
this._id = id;
}
/** @inheritdoc */
public async getEntity(): Promise<ShippingMethod | null>
{
if (this._shippingMethod === null) {
this._shippingMethodPromise = this._dataSource.findShippingMethod(this.getId());
const shippingMethod = await this._shippingMethodPromise;
if (shippingMethod === null) {
Apicart.Utils.Console.error('Shipping method with id "' + this.getId() + '" not found.');
} else {
this._shippingMethod = shippingMethod;
}
}
if (this._shippingMethodPromise) {
await this._shippingMethodPromise;
this._shippingMethodPromise = null;
}
return this._shippingMethod;
}
/** @inheritdoc */
public async getDescription(): Promise<string | null>
{
return (await this.getEntity()).getDescription();
}
/** @inheritdoc */
public getId(): number {
return this._id;
}
/** @inheritdoc */
public async getUid(): Promise<string | null>
{
return (await this.getEntity()).getUid();
}
/** @inheritdoc */
public async getImage(): Promise<string | null>
{
return (await this.getEntity()).getImage();
}
/** @inheritdoc */
public async getName(): Promise<string>
{
return (await this.getEntity()).getName();
}
/** @inheritdoc */
public async getPrice(): Promise<number>
{
return (await this.getEntity()).getPrice();
}
/** @inheritdoc */
public async getSort(): Promise<number>
{
return (await this.getEntity()).getSort();
}
/** @inheritdoc */
public async isEnabled(): Promise<boolean>
{
return (await this.getEntity()).isEnabled();
}
}