wallet-storage-client
Version:
Client only Wallet Storage
73 lines • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TxLabel = void 0;
const index_client_1 = require("../../../index.client");
const _1 = require(".");
class TxLabel extends _1.EntityBase {
constructor(api) {
const now = new Date();
super(api || {
txLabelId: 0,
created_at: now,
updated_at: now,
label: "",
userId: 0,
isDeleted: false
});
}
updateApi() {
/* nothing needed yet... */
}
get txLabelId() { return this.api.txLabelId; }
set txLabelId(v) { this.api.txLabelId = v; }
get created_at() { return this.api.created_at; }
set created_at(v) { this.api.created_at = v; }
get updated_at() { return this.api.updated_at; }
set updated_at(v) { this.api.updated_at = v; }
get label() { return this.api.label; }
set label(v) { this.api.label = v; }
get userId() { return this.api.userId; }
set userId(v) { this.api.userId = v; }
get isDeleted() { return this.api.isDeleted; }
set isDeleted(v) { this.api.isDeleted = v; }
get id() { return this.api.txLabelId; }
set id(v) { this.api.txLabelId = v; }
get entityName() { return 'entity.TxLabel'; }
get entityTable() { return 'tx_labels'; }
equals(ei, syncMap) {
const eo = this.toApi();
if (eo.label != ei.label ||
eo.isDeleted != ei.isDeleted)
return false;
if (!syncMap) {
if (eo.userId !== ei.userId)
return false;
}
return true;
}
static async mergeFind(storage, userId, ei, syncMap, trx) {
const ef = (0, index_client_1.verifyOneOrNone)(await storage.findTxLabels({ partial: { label: ei.label, userId }, trx }));
return {
found: !!ef,
eo: new index_client_1.entity.TxLabel(ef || { ...ei }),
eiId: (0, index_client_1.verifyId)(ei.txLabelId)
};
}
async mergeNew(storage, userId, syncMap, trx) {
this.userId = userId;
this.txLabelId = 0;
this.txLabelId = await storage.insertTxLabel(this.toApi(), trx);
}
async mergeExisting(storage, since, ei, syncMap, trx) {
let wasMerged = false;
if (ei.updated_at > this.updated_at) {
this.isDeleted = ei.isDeleted;
this.updated_at = new Date();
await storage.updateTxLabel(this.id, this.toApi(), trx);
wasMerged = true;
}
return wasMerged;
}
}
exports.TxLabel = TxLabel;
//# sourceMappingURL=TxLabel.js.map