From 2677a48b9266be0d2df7a6013fa6fe6836b740a0 Mon Sep 17 00:00:00 2001
From: Fikri Naufal Hamdi <18221096@std.stei.itb.ac.id>
Date: Fri, 24 Nov 2023 20:13:40 +0700
Subject: [PATCH] feat: add image column in tenant table

---
 backend/src/controller/TenantsController.ts | 4 ++++
 backend/src/model/Tenants.ts                | 6 ++++++
 backend/src/repository/TenantsRepo.ts       | 2 ++
 backend/src/schema/TenantsSchema.ts         | 2 ++
 4 files changed, 14 insertions(+)

diff --git a/backend/src/controller/TenantsController.ts b/backend/src/controller/TenantsController.ts
index a097b631..0e426049 100644
--- a/backend/src/controller/TenantsController.ts
+++ b/backend/src/controller/TenantsController.ts
@@ -13,6 +13,7 @@ class TenantController {
             new_tenant.open_hour = req.body.open_hour;
             new_tenant.description = req.body.description;
             new_tenant.rating = req.body.rating;
+            new_tenant.image = req.body.image;
 
             await new TenantsRepo().createTenant(new_tenant);
 
@@ -21,6 +22,7 @@ class TenantController {
                 message: "Successfully created tenant!",
             });
         } catch (err) {
+            console.log(err);
             res.status(500).json({
                 status: "Internal Server Error!",
                 message: "Internal Server Error!",
@@ -73,6 +75,7 @@ class TenantController {
                 data: tenants,
             });
         } catch (err) {
+            console.log(err);
             res.status(500).json({
                 status: "Internal Server Error!",
                 message: "Internal Server Error!",
@@ -91,6 +94,7 @@ class TenantController {
             tenant.open_hour = req.body.open_hour;
             tenant.description = req.body.description;
             tenant.rating = req.body.rating;
+            tenant.image = req.body.image;
 
             await new TenantsRepo().updateTenant(tenant);
 
diff --git a/backend/src/model/Tenants.ts b/backend/src/model/Tenants.ts
index d9ba50b8..18625e2a 100644
--- a/backend/src/model/Tenants.ts
+++ b/backend/src/model/Tenants.ts
@@ -52,6 +52,12 @@ export class Tenants extends Model {
     })
     rating!: number | null;
 
+    @Column({
+        type: DataType.STRING(255),
+        field: "image",
+    })
+    image!: number | null;
+
     @ForeignKey(() => Users)
     @BelongsTo(() => Users, "id")
     user!: Users;
diff --git a/backend/src/repository/TenantsRepo.ts b/backend/src/repository/TenantsRepo.ts
index fa73cd7b..64686d36 100644
--- a/backend/src/repository/TenantsRepo.ts
+++ b/backend/src/repository/TenantsRepo.ts
@@ -40,6 +40,7 @@ export default class TenantRepo implements ITenantRepo {
                 open_hour: tenant.open_hour,
                 description: tenant.description,
                 rating: tenant.rating,
+                image: tenant.image,
             });
         } catch (error: any) {
             throw new Error(`Error while creating tenant: ${error.message}`);
@@ -60,6 +61,7 @@ export default class TenantRepo implements ITenantRepo {
             existingTenant.open_hour = tenant.open_hour;
             existingTenant.description = tenant.description;
             existingTenant.rating = tenant.rating;
+            existingTenant.image = tenant.image;
 
             await existingTenant.save();
         } catch (error: any) {
diff --git a/backend/src/schema/TenantsSchema.ts b/backend/src/schema/TenantsSchema.ts
index 453210da..753e178b 100644
--- a/backend/src/schema/TenantsSchema.ts
+++ b/backend/src/schema/TenantsSchema.ts
@@ -11,6 +11,7 @@ export const createTenantSchema = z.object({
         open_hour: z.string().nullable(),
         description: z.string().nullable(),
         rating: z.number().nullable(),
+        image: z.string().nullable(),
     }),
 });
 
@@ -25,6 +26,7 @@ export const updateTenantSchema = z.object({
             open_hour: z.string().nullable(),
             description: z.string().nullable(),
             rating: z.number().nullable(),
+            image: z.string().nullable(),
         })
         .partial(),
 });
-- 
GitLab