From 25d41c77ce1a86f83f3959cb63025482a553f367 Mon Sep 17 00:00:00 2001
From: Imanuel Raditya <16521421@mahasiswa.itb.ac.id>
Date: Mon, 27 Nov 2023 23:15:13 +0700
Subject: [PATCH] fix: fix ordering when get all data

---
 backend/src/repository/OrderProductRepo.ts | 4 +++-
 backend/src/repository/OrdersRepo.ts       | 4 +++-
 backend/src/repository/PaymentsRepo.ts     | 4 +++-
 backend/src/repository/ProductsRepo.ts     | 4 +++-
 backend/src/repository/TablesRepo.ts       | 4 +++-
 backend/src/repository/TenantsRepo.ts      | 4 +++-
 backend/src/repository/UsersRepo.ts        | 4 +++-
 frontend/src/pages/ManagePayment.tsx       | 4 +++-
 8 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/backend/src/repository/OrderProductRepo.ts b/backend/src/repository/OrderProductRepo.ts
index ba0d9165..d84d7ade 100644
--- a/backend/src/repository/OrderProductRepo.ts
+++ b/backend/src/repository/OrderProductRepo.ts
@@ -15,7 +15,9 @@ interface IOrderProductRepo {
 export default class OrderProductRepo implements IOrderProductRepo {
     async getAllOrderProduct(): Promise<OrderProduct[]> {
         try {
-            return await OrderProduct.findAll();
+            return await OrderProduct.findAll({
+                order: [["id_product", "ASC"]],
+            });
         } catch (error: any) {
             throw new Error(
                 `Error while fetching order products: ${error.message}`,
diff --git a/backend/src/repository/OrdersRepo.ts b/backend/src/repository/OrdersRepo.ts
index 8793ef66..6b8904f9 100644
--- a/backend/src/repository/OrdersRepo.ts
+++ b/backend/src/repository/OrdersRepo.ts
@@ -14,7 +14,9 @@ interface IOrdersRepo {
 export default class OrdersRepo implements IOrdersRepo {
     async getAllOrders(): Promise<Orders[]> {
         try {
-            return await Orders.findAll();
+            return await Orders.findAll({
+                order: [["id", "DESC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching orders: ${error.message}`);
         }
diff --git a/backend/src/repository/PaymentsRepo.ts b/backend/src/repository/PaymentsRepo.ts
index 296d9240..6b79b9b3 100644
--- a/backend/src/repository/PaymentsRepo.ts
+++ b/backend/src/repository/PaymentsRepo.ts
@@ -13,7 +13,9 @@ interface IPaymentsRepo {
 export default class PaymentsRepo implements IPaymentsRepo {
     async getAllPayments(): Promise<Payments[]> {
         try {
-            return await Payments.findAll();
+            return await Payments.findAll({
+                order: [["id", "DESC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching payments: ${error.message}`);
         }
diff --git a/backend/src/repository/ProductsRepo.ts b/backend/src/repository/ProductsRepo.ts
index 2e6f27b5..58bcd9a9 100644
--- a/backend/src/repository/ProductsRepo.ts
+++ b/backend/src/repository/ProductsRepo.ts
@@ -13,7 +13,9 @@ interface IProductsRepo {
 export default class ProductsRepo implements IProductsRepo {
     async getAllProducts(): Promise<Products[]> {
         try {
-            return await Products.findAll();
+            return await Products.findAll({
+                order: [["id", "ASC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching products: ${error.message}`);
         }
diff --git a/backend/src/repository/TablesRepo.ts b/backend/src/repository/TablesRepo.ts
index 3b67116b..588c10e4 100644
--- a/backend/src/repository/TablesRepo.ts
+++ b/backend/src/repository/TablesRepo.ts
@@ -13,7 +13,9 @@ export default class TablesRepo implements ITablesRepo {
     async getAllTables(): Promise<Tables[]> {
         try {
             console.log("masuk getTables");
-            return await Tables.findAll();
+            return await Tables.findAll({
+                order: [["id", "ASC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching tables: ${error.message}`);
         }
diff --git a/backend/src/repository/TenantsRepo.ts b/backend/src/repository/TenantsRepo.ts
index 64686d36..7312d5ea 100644
--- a/backend/src/repository/TenantsRepo.ts
+++ b/backend/src/repository/TenantsRepo.ts
@@ -13,7 +13,9 @@ interface ITenantRepo {
 export default class TenantRepo implements ITenantRepo {
     async getAllTenants(): Promise<Tenants[]> {
         try {
-            return await Tenants.findAll();
+            return await Tenants.findAll({
+                order: [["id", "ASC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching tenants: ${error.message}`);
         }
diff --git a/backend/src/repository/UsersRepo.ts b/backend/src/repository/UsersRepo.ts
index 72492b20..5149fa00 100644
--- a/backend/src/repository/UsersRepo.ts
+++ b/backend/src/repository/UsersRepo.ts
@@ -13,7 +13,9 @@ interface IUsersRepo {
 export default class UsersRepo implements IUsersRepo {
     async getAllUsers(): Promise<Users[]> {
         try {
-            return await Users.findAll();
+            return await Users.findAll({
+                order: [["id", "ASC"]],
+            });
         } catch (error: any) {
             throw new Error(`Error while fetching users: ${error.message}`);
         }
diff --git a/frontend/src/pages/ManagePayment.tsx b/frontend/src/pages/ManagePayment.tsx
index 6d694bb4..1b3f078e 100644
--- a/frontend/src/pages/ManagePayment.tsx
+++ b/frontend/src/pages/ManagePayment.tsx
@@ -10,6 +10,7 @@ import ConfirmPopUp from "../components/ConfirmPopUp";
 import Axios from "axios";
 import { useParams } from "react-router-dom";
 import crypto from "crypto-js";
+import { useAuth } from "../hooks/useAuth";
 
 interface Order {
     id: number;
@@ -58,6 +59,7 @@ interface OrderDetails {
 }
 
 const ManagePayment = () => {
+    const { user } = useAuth();
     const { orderid } = useParams();
     const paymentid = orderid;
     const [showProfileDropDown, setShowProfileDropDown] = useState(false);
@@ -218,7 +220,7 @@ const ManagePayment = () => {
             {/* Header */}
             <div className="col-span-4">
                 <div className="row-span-1 ms-20 mt-9 py-3 w-11/12">
-                    <Welcome user="Aldaebaran" />
+                    <Welcome user={user ? user!.fullname : ""} />
                 </div>
                 <div className="absolute top-0 right-0 mt-9 mx-12">
                     <Profile
-- 
GitLab