@tomei/product
Version:
NestJS package for product module
44 lines (37 loc) • 1.29 kB
text/typescript
import { IProductAttrBase } from '../../interfaces/product-attr.base.interface';
import { ProductBase } from '../../base/product/product.base';
import { LoginUser } from '@tomei/sso';
export class GemLabProduct extends ProductBase {
ObjectType = 'GemLabProduct';
private static _GemLabProductRepository: any;
private constructor(product?: IProductAttrBase) {
super(product);
}
public static async init(productId?: string): Promise<GemLabProduct> {
try {
if (productId) {
const gemLabProduct =
await GemLabProduct._GemLabProductRepository.findOne(productId);
if (!gemLabProduct) {
throw new Error('Product not found');
}
const data: IProductAttrBase = gemLabProduct.get({ plain: true });
const product = await super.findOne(data.ProductId);
const productData: IProductAttrBase = product.get({ plain: true });
return new GemLabProduct({ ...data, ...productData });
} else {
return new GemLabProduct();
}
} catch (err) {
console.log(err);
throw err;
}
}
public async create(
loginUser: LoginUser,
dbTransaction?: any,
): Promise<ProductBase> {
const product = await super.create(loginUser, dbTransaction);
return product;
}
}