From 375b7874e57f62d2399718185d2e988f77b1b25d Mon Sep 17 00:00:00 2001
From: "kelly.nguyen" <kelly.nguyen@etu.hesge.ch>
Date: Wed, 28 Feb 2024 22:23:24 +0100
Subject: [PATCH] display data with table - user list

---
 .../user/subcommands/UserListCommand.ts       | 32 +++++++++++--------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/NodeApp/src/commander/user/subcommands/UserListCommand.ts b/NodeApp/src/commander/user/subcommands/UserListCommand.ts
index db99164..32afb7a 100644
--- a/NodeApp/src/commander/user/subcommands/UserListCommand.ts
+++ b/NodeApp/src/commander/user/subcommands/UserListCommand.ts
@@ -2,8 +2,8 @@ import chalk from "chalk";
 import CommanderCommand from "../../CommanderCommand";
 import DojoBackendManager from "../../../managers/DojoBackendManager";
 import User from "../../../sharedByClients/models/User";
-import ora from "ora";
 import SessionManager from "../../../managers/SessionManager";
+import Table from 'cli-table3';
 
 class UserListCommand extends CommanderCommand {
      protected commandName : string = 'list';
@@ -33,22 +33,26 @@ class UserListCommand extends CommanderCommand {
           
           // Retrieve data
           {
-               // TODO : display data in table
                users = await DojoBackendManager.getAllUsers();
-               users.forEach(user => {
-                    const oraInfo = (message: string) => {
-                         ora({
-                              text: message,
-                              indent: 4
-                         }).start().info();
-                    };
-                    
-                    oraInfo(`${chalk.magenta('Id:')} ${user.id}`);
-                    oraInfo(`${chalk.magenta('Mail:')} ${user.gitlabUsername}`);
-                    oraInfo(`${chalk.magenta('Role:')} ${user.role}`);
-               });
+               if (!users) {
+                    return;
+               }
+
+               this.display(users);
           }
      }
+
+     private display(u : User[]) {
+          const table = new Table({
+               head: ['Id', 'Mail', 'Role']
+          });
+
+          u.forEach(user => {
+               table.push([user.id, user.gitlabUsername, user.role]);
+          });
+
+          console.log(table.toString());
+     }
 }
 
 export default new UserListCommand();
\ No newline at end of file
-- 
GitLab