UNPKG

@absolute/change-tracker-node-sdk

Version:

ChangeTracker SDK for Node.js

68 lines (61 loc) 1.67 kB
/** * Table - Change Tracker table model * @class * @public */ module.exports = class Table { /** * @constructor * @returns {Table} * @param {string} name - table name * @param {Row[]} [rows] - table rows **/ constructor(name, rows) { /** * @private * @type {Date} **/ this.odt = undefined; /** * @type {string} **/ this.name = name; /** * @type {string} **/ this.ip = undefined; /** * @type {string} **/ this.user = undefined; /** * @type {Row[]} **/ this.rows = Array.isArray(rows) ? rows : []; } set operationDateTime(odt) { this.odt = odt; } get operationDateTime() { return this.odt; } /** * @param {Row[]} rows - an array of rows * @param {string} tableName - the changed table name * @param {string} userName - the name of the user who perform the modification (for log purposes) * @param {string} ipAddress - current request ip address (for log purposes) * @returns {Table} a new Table instance **/ static createTable(rows, tableName, userName, ipAddress) { if (!Array.isArray(rows)) { console.error('ChangeTracker, createTable: invalid rows model'); return null; } let model = new Table(tableName); model.user = userName; model.odt = new Date(); model.ip = ipAddress; model.rows = rows; return model; } }