Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • view-database.js

    r81bc7da r69f2a41  
    33
    44const dbPath = path.join(__dirname, 'database', 'handcraft.db');
    5 const db = new sqlite3.Database(dbPath, (err) => {
    6     if (err) {
    7         console.error('Error opening database:', err.message);
    8         process.exit(1);
    9     }
    10 });
     5const db = new sqlite3.Database(dbPath);
    116
    127console.log('\nšŸŽØ HANDCRAFT MARKETPLACE - DATABASE CONTENTS\n');
    … …  
    3025}
    3126
    32 // Main execution chain
    33 function executeChecks() {
    34     let currentCheck = 0;
    35 
    36     const checks = [
    37         { name: 'clients', func: checkClients },
    38         { name: 'personal', func: checkPersonal },
    39         { name: 'store', func: checkStore },
    40         { name: 'product', func: checkProduct },
    41         { name: 'category', func: checkCategory },
    42         { name: 'works_in_store', func: checkWorksInStore },
    43         { name: 'permissions', func: checkPermissions },
    44         { name: 'employees', func: checkEmployees },
    45         { name: 'boss', func: checkBoss },
    46         { name: 'order', func: checkOrder },
    47         { name: 'report', func: checkReport },
    48         { name: 'refund', func: checkRefund },
    49         { name: 'image', func: checkImage },
    50         { name: 'color', func: checkColor }
    51     ];
    52 
    53     function next() {
    54         currentCheck++;
    55         if (currentCheck < checks.length) {
    56             checks[currentCheck].func(next);
     27// Display CLIENTS table
     28console.log('\nšŸ‘¤ CLIENTS TABLE:');
     29console.log('================================================================================');
     30tableExists('client', (exists) => {
     31    if (!exists) {
     32        console.log('Table does not exist');
     33        checkNext();
     34        return;
     35    }
     36
     37    db.all('SELECT * FROM client', [], (err, rows) => {
     38        if (err) {
     39            console.log(`Error: ${err.message}`);
     40            checkNext();
     41            return;
     42        }
     43
     44        if (!rows || rows.length === 0) {
     45            console.log('No clients found');
    5746        } else {
    58             finish();
    59         }
    60     }
    61 
    62     // Start with first check
    63     checks[0].func(next);
    64 }
    65 
    66 // Display CLIENTS table
    67 function checkClients(next) {
    68     console.log('\nšŸ‘¤ CLIENTS TABLE:');
    69     console.log('================================================================================');
    70 
    71     tableExists('client', (exists) => {
    72         if (!exists) {
    73             console.log('Table does not exist\n');
    74             if (next) next();
    75             return;
    76         }
    77 
    78         db.all('SELECT * FROM client', [], (err, rows) => {
    79             if (err) {
    80                 console.log(`Error: ${err.message}\n`);
    81                 if (next) next();
    82                 return;
    83             }
    84 
    85             if (!rows || rows.length === 0) {
    86                 console.log('No clients found\n');
    87             } else {
    88                 console.log(`Total: ${rows.length} clients\n`);
    89                 rows.forEach((client, index) => {
    90                     console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`);
    91                     console.log(`Email: ${client.email || 'N/A'}`);
    92                     if (index < rows.length - 1) console.log('-'.repeat(80));
    93                 });
    94                 console.log(); // Add blank line after table
    95             }
    96             if (next) next();
    97         });
    98     });
    99 }
     47            console.log(`Total: ${rows.length} clients\n`);
     48            rows.forEach((client, index) => {
     49                console.log(`ID: ${client.client_id} | Name: ${client.first_name || ''} ${client.last_name || ''}`);
     50                console.log(`Email: ${client.email || 'N/A'}`);
     51                if (index < rows.length - 1) console.log('-'.repeat(80));
     52            });
     53        }
     54        checkNext();
     55    });
     56});
    10057
    10158// Display PERSONAL table
    102 function checkPersonal(next) {
     59function checkPersonal() {
    10360    console.log('\nšŸ‘” PERSONAL TABLE (STORE OWNERS/EMPLOYEES):');
    10461    console.log('================================================================================');
    105 
    10662    tableExists('personal', (exists) => {
    10763        if (!exists) {
    108             console.log('Table does not exist\n');
    109             if (next) next();
     64            console.log('Table does not exist');
     65            checkStore();
    11066            return;
    11167        }
    … …  
    12177        `, [], (err, rows) => {
    12278            if (err) {
    123                 console.log(`Error: ${err.message}\n`);
    124                 if (next) next();
    125                 return;
    126             }
    127 
    128             if (!rows || rows.length === 0) {
    129                 console.log('No personal records found\n');
     79                console.log(`Error: ${err.message}`);
     80                checkStore();
     81                return;
     82            }
     83
     84            if (!rows || rows.length === 0) {
     85                console.log('No personal records found');
    13086            } else {
    13187                console.log(`Total: ${rows.length} personal records\n`);
    … …  
    13591                    if (index < rows.length - 1) console.log('-'.repeat(80));
    13692                });
    137                 console.log();
    138             }
    139             if (next) next();
     93            }
     94            checkStore();
    14095        });
    14196    });
    … …  
    14398
    14499// Display STORE table
    145 function checkStore(next) {
     100function checkStore() {
    146101    console.log('\nšŸŖ STORE TABLE:');
    147102    console.log('================================================================================');
    148 
    149103    tableExists('store', (exists) => {
    150104        if (!exists) {
    151             console.log('Table does not exist\n');
    152             if (next) next();
     105            console.log('Table does not exist');
     106            checkProduct();
    153107            return;
    154108        }
    … …  
    156110        db.all('SELECT * FROM store', [], (err, rows) => {
    157111            if (err) {
    158                 console.log(`Error: ${err.message}\n`);
    159                 if (next) next();
    160                 return;
    161             }
    162 
    163             if (!rows || rows.length === 0) {
    164                 console.log('No stores found\n');
     112                console.log(`Error: ${err.message}`);
     113                checkProduct();
     114                return;
     115            }
     116
     117            if (!rows || rows.length === 0) {
     118                console.log('No stores found');
    165119            } else {
    166120                console.log(`Total: ${rows.length} stores\n`);
    … …  
    172126                    if (index < rows.length - 1) console.log('-'.repeat(80));
    173127                });
    174                 console.log();
    175             }
    176             if (next) next();
     128            }
     129            checkProduct();
    177130        });
    178131    });
    … …  
    180133
    181134// Display PRODUCT table
    182 function checkProduct(next) {
     135function checkProduct() {
    183136    console.log('\nšŸ›ļø PRODUCT TABLE:');
    184137    console.log('================================================================================');
    185 
    186138    tableExists('product', (exists) => {
    187139        if (!exists) {
    188             console.log('Table does not exist\n');
    189             if (next) next();
     140            console.log('Table does not exist');
     141            checkCategory();
    190142            return;
    191143        }
    … …  
    197149        `, [], (err, rows) => {
    198150            if (err) {
    199                 console.log(`Error: ${err.message}\n`);
    200                 if (next) next();
    201                 return;
    202             }
    203 
    204             if (!rows || rows.length === 0) {
    205                 console.log('No products found\n');
     151                console.log(`Error: ${err.message}`);
     152                checkCategory();
     153                return;
     154            }
     155
     156            if (!rows || rows.length === 0) {
     157                console.log('No products found');
    206158            } else {
    207159                console.log(`Total: ${rows.length} products\n`);
    … …  
    213165                    if (index < rows.length - 1) console.log('-'.repeat(80));
    214166                });
    215                 console.log();
    216             }
    217             if (next) next();
     167            }
     168            checkCategory();
    218169        });
    219170    });
    … …  
    221172
    222173// Display CATEGORY table
    223 function checkCategory(next) {
     174function checkCategory() {
    224175    console.log('\nšŸ“ CATEGORY TABLE:');
    225176    console.log('================================================================================');
    226 
    227177    tableExists('category', (exists) => {
    228178        if (!exists) {
    229             console.log('Table does not exist\n');
    230             if (next) next();
     179            console.log('Table does not exist');
     180            checkWorksInStore();
    231181            return;
    232182        }
    … …  
    238188        `, [], (err, rows) => {
    239189            if (err) {
    240                 console.log(`Error: ${err.message}\n`);
    241                 if (next) next();
    242                 return;
    243             }
    244 
    245             if (!rows || rows.length === 0) {
    246                 console.log('No categories found\n');
     190                console.log(`Error: ${err.message}`);
     191                checkWorksInStore();
     192                return;
     193            }
     194
     195            if (!rows || rows.length === 0) {
     196                console.log('No categories found');
    247197            } else {
    248198                console.log(`Total: ${rows.length} categories\n`);
    … …  
    253203                    if (index < rows.length - 1) console.log('-'.repeat(80));
    254204                });
    255                 console.log();
    256             }
    257             if (next) next();
     205            }
     206            checkWorksInStore();
    258207        });
    259208    });
    … …  
    261210
    262211// Display WORKS_IN_STORE table
    263 function checkWorksInStore(next) {
     212function checkWorksInStore() {
    264213    console.log('\nšŸ”— WORKS_IN_STORE TABLE:');
    265214    console.log('================================================================================');
    266 
    267215    tableExists('works_in_store', (exists) => {
    268216        if (!exists) {
    269             console.log('Table does not exist\n');
    270             if (next) next();
     217            console.log('Table does not exist');
     218            checkPermissions();
    271219            return;
    272220        }
    … …  
    279227        `, [], (err, rows) => {
    280228            if (err) {
    281                 console.log(`Error: ${err.message}\n`);
    282                 if (next) next();
    283                 return;
    284             }
    285 
    286             if (!rows || rows.length === 0) {
    287                 console.log('No assignments found\n');
     229                console.log(`Error: ${err.message}`);
     230                checkPermissions();
     231                return;
     232            }
     233
     234            if (!rows || rows.length === 0) {
     235                console.log('No assignments found');
    288236            } else {
    289237                console.log(`Total: ${rows.length} assignments\n`);
    … …  
    293241                    if (index < rows.length - 1) console.log('-'.repeat(80));
    294242                });
    295                 console.log();
    296             }
    297             if (next) next();
     243            }
     244            checkPermissions();
    298245        });
    299246    });
    … …  
    301248
    302249// Display PERMISSIONS table
    303 function checkPermissions(next) {
     250function checkPermissions() {
    304251    console.log('\nšŸ” PERMISSIONS TABLE:');
    305252    console.log('================================================================================');
    306 
    307253    tableExists('permissions', (exists) => {
    308254        if (!exists) {
    309             console.log('Table does not exist\n');
    310             if (next) next();
     255            console.log('Table does not exist');
     256            checkEmployees();
    311257            return;
    312258        }
    … …  
    318264        `, [], (err, rows) => {
    319265            if (err) {
    320                 console.log(`Error: ${err.message}\n`);
    321                 if (next) next();
    322                 return;
    323             }
    324 
    325             if (!rows || rows.length === 0) {
    326                 console.log('No permissions found\n');
     266                console.log(`Error: ${err.message}`);
     267                checkEmployees();
     268                return;
     269            }
     270
     271            if (!rows || rows.length === 0) {
     272                console.log('No permissions found');
    327273            } else {
    328274                console.log(`Total: ${rows.length} permissions\n`);
    … …  
    332278                    if (index < rows.length - 1) console.log('-'.repeat(80));
    333279                });
    334                 console.log();
    335             }
    336             if (next) next();
     280            }
     281            checkEmployees();
    337282        });
    338283    });
    … …  
    340285
    341286// Display EMPLOYEES table
    342 function checkEmployees(next) {
     287function checkEmployees() {
    343288    console.log('\nšŸ‘· EMPLOYEES TABLE:');
    344289    console.log('================================================================================');
    345 
    346290    tableExists('employees', (exists) => {
    347291        if (!exists) {
    348             console.log('Table does not exist\n');
    349             if (next) next();
     292            console.log('Table does not exist');
     293            checkBoss();
    350294            return;
    351295        }
    … …  
    357301        `, [], (err, rows) => {
    358302            if (err) {
    359                 console.log(`Error: ${err.message}\n`);
    360                 if (next) next();
    361                 return;
    362             }
    363 
    364             if (!rows || rows.length === 0) {
    365                 console.log('No employees found\n');
     303                console.log(`Error: ${err.message}`);
     304                checkBoss();
     305                return;
     306            }
     307
     308            if (!rows || rows.length === 0) {
     309                console.log('No employees found');
    366310            } else {
    367311                console.log(`Total: ${rows.length} employees\n`);
    … …  
    371315                    if (index < rows.length - 1) console.log('-'.repeat(80));
    372316                });
    373                 console.log();
    374             }
    375             if (next) next();
     317            }
     318            checkBoss();
    376319        });
    377320    });
    … …  
    379322
    380323// Display BOSS table
    381 function checkBoss(next) {
     324function checkBoss() {
    382325    console.log('\nšŸ‘‘ BOSS TABLE:');
    383326    console.log('================================================================================');
    384 
    385327    tableExists('boss', (exists) => {
    386328        if (!exists) {
    387             console.log('Table does not exist\n');
    388             if (next) next();
     329            console.log('Table does not exist');
     330            checkOrder();
    389331            return;
    390332        }
    … …  
    396338        `, [], (err, rows) => {
    397339            if (err) {
    398                 console.log(`Error: ${err.message}\n`);
    399                 if (next) next();
    400                 return;
    401             }
    402 
    403             if (!rows || rows.length === 0) {
    404                 console.log('No bosses found\n');
     340                console.log(`Error: ${err.message}`);
     341                checkOrder();
     342                return;
     343            }
     344
     345            if (!rows || rows.length === 0) {
     346                console.log('No bosses found');
    405347            } else {
    406348                console.log(`Total: ${rows.length} bosses\n`);
    … …  
    410352                    if (index < rows.length - 1) console.log('-'.repeat(80));
    411353                });
    412                 console.log();
    413             }
    414             if (next) next();
     354            }
     355            checkOrder();
    415356        });
    416357    });
    … …  
    418359
    419360// Display ORDER table
    420 function checkOrder(next) {
     361function checkOrder() {
    421362    console.log('\nšŸ“¦ ORDERS TABLE:');
    422363    console.log('================================================================================');
    423 
    424364    tableExists('order', (exists) => {
    425365        if (!exists) {
    426             console.log('Table does not exist\n');
    427             if (next) next();
     366            console.log('Table does not exist');
     367            checkReport();
    428368            return;
    429369        }
    … …  
    436376        `, [], (err, rows) => {
    437377            if (err) {
    438                 console.log(`Error: ${err.message}\n`);
    439                 if (next) next();
    440                 return;
    441             }
    442 
    443             if (!rows || rows.length === 0) {
    444                 console.log('No orders found\n');
     378                console.log(`Error: ${err.message}`);
     379                checkReport();
     380                return;
     381            }
     382
     383            if (!rows || rows.length === 0) {
     384                console.log('No orders found');
    445385            } else {
    446386                console.log(`Total: ${rows.length} orders\n`);
    … …  
    452392                    if (index < rows.length - 1) console.log('-'.repeat(80));
    453393                });
    454                 console.log();
    455             }
    456             if (next) next();
     394            }
     395            checkReport();
    457396        });
    458397    });
    … …  
    460399
    461400// Display REPORT table
    462 function checkReport(next) {
     401function checkReport() {
    463402    console.log('\nšŸ“Š REPORTS TABLE:');
    464403    console.log('================================================================================');
    465 
    466404    tableExists('report', (exists) => {
    467405        if (!exists) {
    468             console.log('Table does not exist\n');
    469             if (next) next();
     406            console.log('Table does not exist');
     407            checkRefund();
    470408            return;
    471409        }
    … …  
    473411        db.all('SELECT * FROM report', [], (err, rows) => {
    474412            if (err) {
    475                 console.log(`Error: ${err.message}\n`);
    476                 if (next) next();
    477                 return;
    478             }
    479 
    480             if (!rows || rows.length === 0) {
    481                 console.log('No reports found\n');
     413                console.log(`Error: ${err.message}`);
     414                checkRefund();
     415                return;
     416            }
     417
     418            if (!rows || rows.length === 0) {
     419                console.log('No reports found');
    482420            } else {
    483421                console.log(`Total: ${rows.length} reports\n`);
    … …  
    487425                    if (index < rows.length - 1) console.log('-'.repeat(80));
    488426                });
    489                 console.log();
    490             }
    491             if (next) next();
     427            }
     428            checkRefund();
    492429        });
    493430    });
    … …  
    495432
    496433// Display REFUND table
    497 function checkRefund(next) {
     434function checkRefund() {
    498435    console.log('\nšŸ’° REFUND TABLE:');
    499436    console.log('================================================================================');
    500 
    501437    tableExists('refund', (exists) => {
    502438        if (!exists) {
    503             console.log('Table does not exist\n');
    504             if (next) next();
     439            console.log('Table does not exist');
     440            checkImage();
    505441            return;
    506442        }
    … …  
    508444        db.all('SELECT * FROM refund', [], (err, rows) => {
    509445            if (err) {
    510                 console.log(`Error: ${err.message}\n`);
    511                 if (next) next();
    512                 return;
    513             }
    514 
    515             if (!rows || rows.length === 0) {
    516                 console.log('No refunds found\n');
     446                console.log(`Error: ${err.message}`);
     447                checkImage();
     448                return;
     449            }
     450
     451            if (!rows || rows.length === 0) {
     452                console.log('No refunds found');
    517453            } else {
    518454                console.log(`Total: ${rows.length} refunds\n`);
    … …  
    523459                    if (index < rows.length - 1) console.log('-'.repeat(80));
    524460                });
    525                 console.log();
    526             }
    527             if (next) next();
     461            }
     462            checkImage();
    528463        });
    529464    });
    … …  
    531466
    532467// Display IMAGE table
    533 function checkImage(next) {
     468function checkImage() {
    534469    console.log('\nšŸ–¼ļø IMAGE TABLE:');
    535470    console.log('================================================================================');
    536 
    537471    tableExists('image', (exists) => {
    538472        if (!exists) {
    539             console.log('Table does not exist\n');
    540             if (next) next();
     473            console.log('Table does not exist');
     474            checkColor();
    541475            return;
    542476        }
    … …  
    544478        db.all('SELECT * FROM image', [], (err, rows) => {
    545479            if (err) {
    546                 console.log(`Error: ${err.message}\n`);
    547                 if (next) next();
    548                 return;
    549             }
    550 
    551             if (!rows || rows.length === 0) {
    552                 console.log('No images found\n');
     480                console.log(`Error: ${err.message}`);
     481                checkColor();
     482                return;
     483            }
     484
     485            if (!rows || rows.length === 0) {
     486                console.log('No images found');
    553487            } else {
    554488                console.log(`Total: ${rows.length} images\n`);
    … …  
    557491                    if (index < rows.length - 1) console.log('-'.repeat(80));
    558492                });
    559                 console.log();
    560             }
    561             if (next) next();
     493            }
     494            checkColor();
    562495        });
    563496    });
    … …  
    565498
    566499// Display COLOR table
    567 function checkColor(next) {
     500function checkColor() {
    568501    console.log('\nšŸŽØ COLOR TABLE:');
    569502    console.log('================================================================================');
    570 
    571503    tableExists('color', (exists) => {
    572504        if (!exists) {
    573             console.log('Table does not exist\n');
    574             if (next) next();
     505            console.log('Table does not exist');
     506            finish();
    575507            return;
    576508        }
    … …  
    578510        db.all('SELECT * FROM color', [], (err, rows) => {
    579511            if (err) {
    580                 console.log(`Error: ${err.message}\n`);
    581                 if (next) next();
    582                 return;
    583             }
    584 
    585             if (!rows || rows.length === 0) {
    586                 console.log('No colors found\n');
     512                console.log(`Error: ${err.message}`);
     513                finish();
     514                return;
     515            }
     516
     517            if (!rows || rows.length === 0) {
     518                console.log('No colors found');
    587519            } else {
    588520                console.log(`Total: ${rows.length} colors\n`);
    … …  
    591523                    if (index < rows.length - 1) console.log('-'.repeat(80));
    592524                });
    593                 console.log();
    594             }
    595             if (next) next();
    596         });
    597     });
    598 }
    599 
    600 // Finish and close database
     525            }
     526            finish();
     527        });
     528    });
     529}
     530
     531// Start the chain of checks
     532function checkNext() {
     533    checkPersonal();
     534}
     535
    601536function finish() {
    602     console.log('='.repeat(80));
     537    console.log('\n' + '='.repeat(80));
    603538    console.log('āœ… Database inspection complete');
    604539    console.log('='.repeat(80) + '\n');
    605540
    606     db.close((err) => {
    607         if (err) {
    608             console.error('Error closing database:', err.message);
    609         }
    610     });
    611 }
    612 
    613 // Start the execution chain
    614 executeChecks();
     541    db.close();
     542}
     543
     544// Start with CLIENTS
     545checkNext();
Note: See TracChangeset for help on using the changeset viewer.