UNPKG

@ic-wallet-kit/hpl

Version:
64 lines (63 loc) 2.98 kB
"use strict"; 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.HplContactRepository = void 0; const common_1 = require("@ic-wallet-kit/common"); require("reflect-metadata"); const typedi_1 = require("typedi"); let HplContactRepository = class HplContactRepository { hplContactDataStorage; constructor(hplContactDataStorage) { this.hplContactDataStorage = hplContactDataStorage; } async getContacts() { return await this.hplContactDataStorage.getItems(); } async getContactById(contactId) { return await this.getContactByIdInternal(contactId); } async addContact(contact) { await this.hplContactDataStorage.addItem(contact); } async updateContact(contact) { await this.hplContactDataStorage.updateItem(contact); return contact; } async addContactRemotes(contactId, remotes) { const item = await this.getContactByIdInternal(contactId); item.remotes = item.remotes.concat(item.remotes, remotes); await this.hplContactDataStorage.updateItem(item); } async removeContact(contactId) { await this.hplContactDataStorage.deleteItem(contactId); } async removeContactLink(contactId, linkId) { const item = await this.getContactByIdInternal(contactId); item.remotes = item.remotes.filter((r) => r.remoteId !== linkId); await this.hplContactDataStorage.updateItem(item); } async getContactByIdInternal(contactId) { const contact = await this.hplContactDataStorage.getItem(contactId); if (!contact) { throw new common_1.ValidationError("contact.not.exists", "contactId", `FtContact not exists. ContactId: ${contactId}`); } return contact; } }; exports.HplContactRepository = HplContactRepository; exports.HplContactRepository = HplContactRepository = __decorate([ (0, typedi_1.Service)("HplContactRepository"), __param(0, (0, typedi_1.Inject)("IHplContactDataStorage")), __metadata("design:paramtypes", [Object]) ], HplContactRepository);