mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:59:28 +00:00
Lint cleanup with new rules
This commit is contained in:
@@ -19,12 +19,15 @@ const { data } = require('./testData');
|
||||
async function cleanDb() {
|
||||
const conn = await new DatabaseConnectionPool();
|
||||
|
||||
// Remove records from tables in reverse order to which they depend on
|
||||
// each other
|
||||
/*
|
||||
* Remove records from tables in reverse order to which they depend on
|
||||
* each other
|
||||
*/
|
||||
const tables = Object.keys(data).reverse();
|
||||
tables.push('sessions');
|
||||
|
||||
for (const table of tables)
|
||||
/* eslint-disable-next-line no-await-in-loop */
|
||||
await conn.runQuery(`DELETE FROM ${table};`);
|
||||
|
||||
conn.close();
|
||||
|
||||
@@ -12,7 +12,6 @@ const tableCreate = new Map();
|
||||
const tableConstraints = new Map();
|
||||
|
||||
// For each table, set tableCreate.tableName equal to the creation statment
|
||||
// for that table
|
||||
tableCreate.set('account', `
|
||||
CREATE TABLE IF NOT EXISTS account (
|
||||
accountId varchar(36) NOT NULL PRIMARY KEY,
|
||||
@@ -128,8 +127,10 @@ tableCreate.set('accountClassLink', `
|
||||
);
|
||||
`);
|
||||
|
||||
// For each table constraint, set tableConstraints.constraitName equal to the
|
||||
// creation statment for that constraint
|
||||
/*
|
||||
* For each table constraint, set tableConstraints.constraintName equal to the
|
||||
* creation statment for that constraint
|
||||
*/
|
||||
tableConstraints.set('accountClassLink_fk0', `
|
||||
ALTER TABLE accountClassLink
|
||||
ADD CONSTRAINT accountClassLink_fk0
|
||||
@@ -260,6 +261,7 @@ async function dbInit() {
|
||||
console.log(`Creating table ${tableName}`);
|
||||
|
||||
try {
|
||||
/* eslint-disable-next-line no-await-in-loop */
|
||||
await conn.runQuery(sql);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -274,6 +276,7 @@ async function dbInit() {
|
||||
console.log(`Creating constraint ${fkName}`);
|
||||
|
||||
try {
|
||||
/* eslint-disable-next-line no-await-in-loop */
|
||||
await conn.runQuery(sql);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-await-in-loop */
|
||||
'use strict';
|
||||
|
||||
// Import required modules
|
||||
@@ -27,34 +28,33 @@ async function insertTestData() {
|
||||
for (const record of data[table]) {
|
||||
const dataToInsert = { ...record };
|
||||
|
||||
if (details?.[table]?.['id'] === 'uuid') {
|
||||
if (details?.[table]?.id === 'uuid') {
|
||||
dataToInsert[`${table}Id`] =
|
||||
crypto.randomUUID();
|
||||
} else {
|
||||
dataToInsert[`${table}Id`] = counter + 1;
|
||||
}
|
||||
|
||||
if (details?.[table]?.['hashPassword']) {
|
||||
dataToInsert['password'] =
|
||||
if (details?.[table]?.hashPassword) {
|
||||
dataToInsert.password =
|
||||
await bcrypt.hash(
|
||||
dataToInsert['password'],
|
||||
dataToInsert.password,
|
||||
10);
|
||||
}
|
||||
|
||||
if (details?.[table]?.['link'])
|
||||
if (details?.[table]?.link)
|
||||
delete dataToInsert[`${table}Id`];
|
||||
|
||||
if (record?.lookups) {
|
||||
delete dataToInsert.lookups;
|
||||
const lookupsEntries =
|
||||
Object.entries(record.lookups);
|
||||
|
||||
for (let [ key, index ] of
|
||||
Object.entries(record.lookups)) {
|
||||
|
||||
for (const [ key, index ] of lookupsEntries) {
|
||||
const resolveTable = key.split('Id')[0];
|
||||
index--;
|
||||
const r = data[resolveTable][index - 1];
|
||||
|
||||
dataToInsert[key] =
|
||||
data[resolveTable][index][key];
|
||||
dataToInsert[key] = r[key];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user