-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit Tenant Models : add images_tenant
- Loading branch information
1 parent
574ba0c
commit 929d731
Showing
4 changed files
with
99 additions
and
8 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240611153513_add_image_to_tenant/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE `Tenants` ADD COLUMN `image` VARCHAR(191) NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
const express = require("express"); | ||
const tenant_controllers = express.Router(); | ||
const authCheck = require("../middlewares/AuthCheck"); | ||
import multer from "multer"; | ||
|
||
// Filter file untuk memastikan hanya gambar yang diizinkan | ||
const imageFilter = (req, file, cb) => { | ||
if (!file.mimetype.match(/^image\/(jpeg|png|gif|webp)$/)) { | ||
console.error("Only image files are allowed!"); | ||
return cb(new Error("Only image files are allowed!"), false); | ||
} | ||
cb(null, true); | ||
}; | ||
|
||
// Mengijinkan upload gambar dengan batasan 5MB | ||
const upload = multer({ | ||
storage: multer.memoryStorage(), | ||
limits: { fileSize: 5 * 1024 * 1024 }, // 5MB | ||
fileFilter: imageFilter, | ||
}); | ||
|
||
import { createTenant, getAllTenants, getTenantById, updateTenant, deleteTenant } from "../controllers/tenantController"; // Sesuaikan dengan path controller Anda | ||
|
||
tenant_controllers.post("/tenants", authCheck, createTenant); | ||
tenant_controllers.post("/tenants", upload.single('image'), authCheck, createTenant); | ||
tenant_controllers.get("/tenants", authCheck, getAllTenants); | ||
tenant_controllers.get("/tenants/:id", authCheck, getTenantById); | ||
tenant_controllers.patch("/tenants/:id", authCheck, updateTenant); | ||
tenant_controllers.patch("/tenants/:id", upload.single('image'), authCheck, updateTenant); | ||
tenant_controllers.delete("/tenants/:id", authCheck, deleteTenant); | ||
|
||
export default tenant_controllers; |