@tomei/finance
Version:
NestJS package for finance module
108 lines • 4.09 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const general_1 = require("@tomei/general");
const record_not_found_error_1 = require("@tomei/general/dist/class/exceptions/record-not-found.error");
const payment_method_repository_1 = require("./payment-method.repository");
const payment_method_type_1 = __importDefault(require("../payment-method-type/payment-method-type"));
const payment_method_type_repository_1 = require("../payment-method-type/payment-method-type.repository");
class PaymentMethod extends general_1.ObjectBase {
get ObjectType() {
return this._ObjectType;
}
constructor(dbTransaction, methodId, companyId, name) {
super();
this.MethodId = 'New';
this.Name = '';
this.CompanyId = '';
this._ObjectType = 'PaymentMethod';
this._PaymentMethodTypes = [];
if (dbTransaction) {
this._DbTransaction = dbTransaction;
}
if (methodId) {
this.MethodId = methodId;
}
if (companyId) {
this.CompanyId = companyId;
}
if (name) {
this.Name = name;
}
}
static async initPaymentMethod(dbTransaction, methodId) {
try {
if (methodId) {
const methodData = await PaymentMethod._RepositoryBase.findOne({
where: {
MethodId: methodId,
},
transaction: dbTransaction,
});
if (methodData) {
return new PaymentMethod(dbTransaction, methodData.MethodId, methodData.CompanyId, methodData.Name);
}
else {
throw new record_not_found_error_1.RecordNotFoundError('PaymentMethodErrMsg', 'No record found.');
}
}
return new PaymentMethod(dbTransaction);
}
catch (error) {
error;
}
}
get ObjectId() {
return this.MethodId;
}
get ObjectName() {
return this.Name;
}
get TableName() {
return 'finance_PaymentMethod';
}
get PaymentMethodTypes() {
return new Promise((resolve, reject) => {
if (this.MethodId !== 'New') {
PaymentMethod._PaymentMethodTypeRepository
.findAll({
where: {
MethodId: this.MethodId,
},
transaction: this._DbTransaction,
})
.then((paymentMethodTypes) => {
const paymentMethodTypeObjects = paymentMethodTypes.map((paymentMethodTypeData) => new payment_method_type_1.default(this._DbTransaction, paymentMethodTypeData.MethodTypeId));
return Promise.all(paymentMethodTypeObjects);
})
.then((paymentMethodTypeObjects) => {
this._PaymentMethodTypes = paymentMethodTypeObjects;
resolve(this._PaymentMethodTypes);
})
.catch((err) => {
reject(err);
});
}
else {
resolve(this._PaymentMethodTypes);
}
});
}
async newPaymentMethodType(payload, transaction) {
try {
const newPaymentMethodType = await PaymentMethod._PaymentMethodTypeRepository.create(payload, {
transaction: transaction,
});
this._PaymentMethodTypes.push(newPaymentMethodType);
}
catch (err) {
throw err;
}
}
}
PaymentMethod._RepositoryBase = new payment_method_repository_1.PaymentMethodRepository();
PaymentMethod._PaymentMethodTypeRepository = new payment_method_type_repository_1.PaymentMethodTypeRepository();
exports.default = PaymentMethod;
//# sourceMappingURL=payment-method.js.map