@tomei/rental
Version:
Tomei Rental Package
66 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RentalPrice = void 0;
const general_1 = require("@tomei/general");
const rental_price_repository_1 = require("./rental-price.repository");
const config_1 = require("@tomei/config");
class RentalPrice extends general_1.ObjectBase {
get PriceId() {
return this.ObjectId;
}
set PriceId(value) {
this.ObjectId = value;
}
constructor(rentalPriceAttr) {
super();
this.ObjectType = 'RentalPrice';
if (rentalPriceAttr) {
this.PriceId = rentalPriceAttr.PriceId;
this.RetailPrice = rentalPriceAttr.RetailPrice;
this.Currency = rentalPriceAttr.Currency;
this.PromoCode = rentalPriceAttr.PromoCode;
this.Remarks = rentalPriceAttr.Remarks;
}
}
static async init(dbTransaction, priceId) {
try {
if (priceId) {
const rentalPrice = await RentalPrice._Repo.findByPk(priceId, dbTransaction);
if (rentalPrice) {
return new RentalPrice(rentalPrice);
}
else {
throw new general_1.ClassError('RentalPrice', 'RentalPriceErrMsg', 'RentalPrice Not Found');
}
}
return new RentalPrice();
}
catch (error) {
throw new general_1.ClassError('RentalPrice', 'RentalPriceErrMsg', 'Failed To Initialize RentalPrice');
}
}
async create(loginUser, dbTransaction) {
try {
const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
const isPrivileged = await loginUser.checkPrivileges(systemCode, 'Rental - Create');
if (!isPrivileged) {
throw new general_1.ClassError('RentalPrice', 'RentalPriceErrMsg01', "You do not have 'Rental - Create' privilege.");
}
this.PriceId = this.createId();
await RentalPrice._Repo.create({
PriceId: this.PriceId,
RetailPrice: this.RetailPrice,
Currency: this.Currency,
PromoCode: this.PromoCode,
Remarks: this.Remarks,
}, dbTransaction);
return this;
}
catch (error) {
throw error;
}
}
}
exports.RentalPrice = RentalPrice;
RentalPrice._Repo = new rental_price_repository_1.RentalPriceRepository();
//# sourceMappingURL=rental-price.js.map