Commit 522afefb authored by Panagiotis Skarvelis's avatar Panagiotis Skarvelis
Browse files

build to export members

parent 7e7e818e
......@@ -9,6 +9,7 @@
// auditTransactionDate: varchar(20);
// auditUserIp: varchar(16);
// auditUserId: varchar(255);
// if you do not provide the table name, the engine will create it for you.
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
......@@ -95,7 +96,7 @@ class PostgreSqlEngine {
try {
let data = {};
const res = __classPrivateFieldGet(this, _PostgreSqlEngine_client, "f").querySync("SELECT * FROM " + __classPrivateFieldGet(this, _PostgreSqlEngine_table, "f") + " WHERE " + __classPrivateFieldGet(this, _PostgreSqlEngine_columnNames, "f").auditTransactionId + "='" + auditTransactionId + "';");
data = res.rows[0];
data = res[0];
return data;
}
catch (error) {
......@@ -129,11 +130,10 @@ class PostgreSqlEngine {
pn() {
try {
const protocol_date = new Date().toISOString().split('T')[0];
const seqName = "SEQ" + protocol_date.replace(/-/g, '');
const seqName = "prot" + protocol_date.replace(/-/g, '');
//create sequence for protocol_date if not exists
__classPrivateFieldGet(this, _PostgreSqlEngine_client, "f").querySync("CREATE SEQUENCE IF NOT EXISTS " + seqName + "_seq START 1");
const res = __classPrivateFieldGet(this, _PostgreSqlEngine_client, "f").querySync("SELECT nextval('" + seqName + "_seq');");
//TODO delete past protocol_date sequences
return res[0].nextval + "/" + protocol_date;
}
catch (error) {
......
......@@ -11,5 +11,5 @@ import { AuditRecord, AuditEngine } from './interfaces/index.js';
*/
export declare const generateAuditRecord: (auditInit?: AuditRecord | undefined, dbEngine?: AuditEngine | undefined) => AuditRecord | null;
export default generateAuditRecord;
export { FileEngine } from './engines/index.js';
export { AuditRecord };
export { FileEngine, PostgreSqlEngine } from './engines/index.js';
export { AuditRecord, AuditEngine, FS_ERROR } from './interfaces/index.js';
......@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileEngine = exports.generateAuditRecord = void 0;
exports.PostgreSqlEngine = exports.FileEngine = exports.generateAuditRecord = void 0;
const db_js_1 = __importDefault(require("./lib/db.js"));
const index_js_1 = require("./engines/index.js");
/**
......@@ -46,3 +46,4 @@ exports.generateAuditRecord = generateAuditRecord;
exports.default = exports.generateAuditRecord;
var index_js_2 = require("./engines/index.js");
Object.defineProperty(exports, "FileEngine", { enumerable: true, get: function () { return index_js_2.FileEngine; } });
Object.defineProperty(exports, "PostgreSqlEngine", { enumerable: true, get: function () { return index_js_2.PostgreSqlEngine; } });
......@@ -8,6 +8,7 @@
// auditTransactionDate: varchar(20);
// auditUserIp: varchar(16);
// auditUserId: varchar(255);
// if you do not provide the table name, the engine will create it for you.
//You can use Docker to run PostgreSQL for your tests.
//`docker run -d --name audit-postgres -e POSTGRES_PASSWORD=audit --network host postgres`
//`docker exec -it audit-postgres psql -U postgres -h localhost -c "CREATE DATABASE audit;"`
......@@ -77,7 +78,7 @@ export class PostgreSqlEngine {
try {
let data = {};
const res = this.#client.querySync("SELECT * FROM " + this.#table + " WHERE " + this.#columnNames.auditTransactionId + "='" + auditTransactionId + "';");
data = res.rows[0];
data = res[0];
return data;
}
catch (error) {
......@@ -111,11 +112,10 @@ export class PostgreSqlEngine {
pn() {
try {
const protocol_date = new Date().toISOString().split('T')[0];
const seqName = "SEQ" + protocol_date.replace(/-/g, '');
const seqName = "prot" + protocol_date.replace(/-/g, '');
//create sequence for protocol_date if not exists
this.#client.querySync("CREATE SEQUENCE IF NOT EXISTS " + seqName + "_seq START 1");
const res = this.#client.querySync("SELECT nextval('" + seqName + "_seq');");
//TODO delete past protocol_date sequences
return res[0].nextval + "/" + protocol_date;
}
catch (error) {
......
......@@ -11,5 +11,5 @@ import { AuditRecord, AuditEngine } from './interfaces/index.js';
*/
export declare const generateAuditRecord: (auditInit?: AuditRecord | undefined, dbEngine?: AuditEngine | undefined) => AuditRecord | null;
export default generateAuditRecord;
export { FileEngine } from './engines/index.js';
export { AuditRecord };
export { FileEngine, PostgreSqlEngine } from './engines/index.js';
export { AuditRecord, AuditEngine, FS_ERROR } from './interfaces/index.js';
......@@ -37,4 +37,4 @@ export const generateAuditRecord = (auditInit, dbEngine) => {
}
};
export default generateAuditRecord;
export { FileEngine } from './engines/index.js';
export { FileEngine, PostgreSqlEngine } from './engines/index.js';
import db from './lib/db.js';
import { AuditRecord,AuditEngine,FS_ERROR } from './interfaces/index.js';
import { FileEngine, PostgreSqlEngine } from './engines/index.js';
import { FileEngine } from './engines/index.js';
/**
* @description Use this on your app to generate and log the audit record
......@@ -41,5 +41,5 @@ export const generateAuditRecord = (auditInit?: AuditRecord | undefined, dbEngin
}
export default generateAuditRecord;
export { FileEngine, PostgreSqlEngine };
export { AuditRecord, AuditEngine ,FS_ERROR };
export { FileEngine, PostgreSqlEngine } from './engines/index.js';
export { AuditRecord, AuditEngine ,FS_ERROR } from './interfaces/index.js';
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment