@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
108 lines • 2.95 kB
JavaScript
import * as PUPPET from '@juzi/wechaty-puppet';
import { log } from '../config.js';
import { poolifyMixin } from '../user-mixins/poolify.js';
import { validationMixin } from '../user-mixins/validation.js';
import { wechatifyMixin } from '../user-mixins/wechatify.js';
const MixinBase = wechatifyMixin(poolifyMixin(Object)());
class WxxdProductMixin extends MixinBase {
id;
/**
* Instance properties
* @ignore
*/
payload;
/**
* @hideconstructor
*/
constructor(id) {
super();
this.id = id;
log.silly('WxxdProduct', 'constructor(%s)', id);
}
/**
* List all products
*/
static async list(query) {
log.verbose('WxxdProduct', 'list(%s)', JSON.stringify(query));
return await this.wechaty.puppet.listWxxdProducts(query);
}
/**
* Find product by id or filter
*/
static async find(query) {
log.verbose('WxxdProduct', 'find(%s)', JSON.stringify(query));
const id = typeof query === 'string' ? query : query.id;
if (!id) {
return undefined;
}
const product = this.wechaty.WxxdProduct.load(id);
try {
await product.ready();
}
catch (e) {
this.wechaty.emitError(e);
return undefined;
}
return product;
}
isReady() {
return !!(this.payload && this.payload.productId);
}
async ready(forceSync = false) {
log.silly('WxxdProduct', 'ready() @ %s with id="%s"', this.wechaty.puppet, this.id);
if (!forceSync && this.isReady()) {
log.silly('WxxdProduct', 'ready() isReady() true');
return;
}
try {
this.payload = await this.wechaty.puppet.wxxdProductPayload(this.id);
}
catch (e) {
this.wechaty.emitError(e);
log.verbose('WxxdProduct', 'ready() this.wechaty.puppet.wxxdProductPayload(%s) exception: %s', this.id, e.message);
throw e;
}
}
/**
* Get product title
*/
title() {
return this.payload?.title || '';
}
/**
* Get product short title
*/
shortTitle() {
return this.payload?.shortTitle || '';
}
/**
* Get product status
*/
status() {
return this.payload?.status || PUPPET.types.WxxdProductStatus.NotExist;
}
/**
* Get product min price
*/
minPrice() {
return this.payload?.minPrice || 0;
}
/**
* Get product total sold number
*/
totalSoldNum() {
return this.payload?.totalSoldNum || 0;
}
/**
* Get product SKUs
*/
skus() {
return this.payload?.skus || [];
}
}
class WxxdProductImplBase extends validationMixin(WxxdProductMixin)() {
}
class WxxdProductImpl extends validationMixin(WxxdProductImplBase)() {
}
export { WxxdProductImpl, };
//# sourceMappingURL=wxxd-product.js.map