wallet-storage-client
Version:
Client only Wallet Storage
68 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TxLabelMap = void 0;
const index_client_1 = require("../../../index.client");
const _1 = require(".");
class TxLabelMap extends _1.EntityBase {
constructor(api) {
const now = new Date();
super(api || {
created_at: now,
updated_at: now,
transactionId: 0,
txLabelId: 0,
isDeleted: false
});
}
updateApi() {
/* nothing needed yet... */
}
get txLabelId() { return this.api.txLabelId; }
set txLabelId(v) { this.api.txLabelId = v; }
get transactionId() { return this.api.transactionId; }
set transactionId(v) { this.api.transactionId = 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 isDeleted() { return this.api.isDeleted; }
set isDeleted(v) { this.api.isDeleted = v; }
get id() { throw new index_client_1.sdk.WERR_INVALID_OPERATION('entity has no "id" value'); } // entity does not have its own id.
get entityName() { return 'TxLabelMap'; }
get entityTable() { return 'tx_labels_map'; }
equals(ei, syncMap) {
const eo = this.toApi();
if (eo.transactionId !== (syncMap ? syncMap.transaction.idMap[(0, index_client_1.verifyId)(ei.transactionId)] : ei.transactionId) ||
eo.txLabelId !== (syncMap ? syncMap.txLabel.idMap[(0, index_client_1.verifyId)(ei.txLabelId)] : ei.txLabelId) ||
eo.isDeleted !== ei.isDeleted)
return false;
return true;
}
static async mergeFind(storage, userId, ei, syncMap, trx) {
const transactionId = syncMap.transaction.idMap[ei.transactionId];
const txLabelId = syncMap.txLabel.idMap[ei.txLabelId];
const ef = (0, index_client_1.verifyOneOrNone)(await storage.findTxLabelMaps({ partial: { transactionId, txLabelId }, trx }));
return {
found: !!ef,
eo: new index_client_1.entity.TxLabelMap(ef || { ...ei }),
eiId: -1
};
}
async mergeNew(storage, userId, syncMap, trx) {
this.transactionId = syncMap.transaction.idMap[this.transactionId];
this.txLabelId = syncMap.txLabel.idMap[this.txLabelId];
await storage.insertTxLabelMap(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.updateTxLabelMap(this.transactionId, this.txLabelId, this.toApi(), trx);
wasMerged = true;
}
return wasMerged;
}
}
exports.TxLabelMap = TxLabelMap;
//# sourceMappingURL=TxLabelMap.js.map