@bsv/wallet-toolbox-client
Version:
Client only Wallet Storage
104 lines • 2.89 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityTxLabel = void 0;
const utilityHelpers_1 = require("../../../utility/utilityHelpers");
const EntityBase_1 = require("./EntityBase");
class EntityTxLabel extends EntityBase_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 '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, utilityHelpers_1.verifyOneOrNone)(await storage.findTxLabels({ partial: { label: ei.label, userId }, trx }));
return {
found: !!ef,
eo: new EntityTxLabel(ef || { ...ei }),
eiId: (0, utilityHelpers_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(Math.max(ei.updated_at.getTime(), this.updated_at.getTime()));
await storage.updateTxLabel(this.id, this.toApi(), trx);
wasMerged = true;
}
return wasMerged;
}
}
exports.EntityTxLabel = EntityTxLabel;
//# sourceMappingURL=EntityTxLabel.js.map