@ic-wallet-kit/hpl
Version:
Ic middleware wallet HPL protocol
58 lines (57 loc) • 2.65 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HplAccountRepository = void 0;
const common_1 = require("@ic-wallet-kit/common");
require("reflect-metadata");
const typedi_1 = require("typedi");
let HplAccountRepository = class HplAccountRepository {
hplAccountDataStorage;
constructor(hplAccountDataStorage) {
this.hplAccountDataStorage = hplAccountDataStorage;
}
async getAccounts() {
return await this.hplAccountDataStorage.getItems();
}
async addAccount(account) {
await this.hplAccountDataStorage.addItem(account);
}
async updateAccount(account) {
const item = await this.getAccountById(account.accountId);
item.name = account.name;
await this.hplAccountDataStorage.updateItem(item);
return item;
}
async removeAccount(accountId) {
await this.hplAccountDataStorage.deleteItem(accountId);
}
async isAccountExist(accountId) {
const account = await this.hplAccountDataStorage.getItem(accountId);
const result = account ? true : false;
return result;
}
async getAccountById(accountId) {
const account = await this.hplAccountDataStorage.getItem(accountId);
if (!account) {
throw new common_1.ValidationError("account.not.exists", "accountId", `Account not exists. AccountId: ${accountId}`);
}
return account;
}
};
exports.HplAccountRepository = HplAccountRepository;
exports.HplAccountRepository = HplAccountRepository = __decorate([
(0, typedi_1.Service)("HplAccountRepository"),
__param(0, (0, typedi_1.Inject)("IHplAccountDataStorage")),
__metadata("design:paramtypes", [Object])
], HplAccountRepository);