[1.0.0] #19

Merged
ashir merged 80 commits from dev into main 2026-04-30 18:37:18 +00:00
8 changed files with 94 additions and 41 deletions
Showing only changes of commit 86afb86d3c - Show all commits
+11 -2
View File
@@ -22,7 +22,8 @@
"jsonwebtoken": "^9.0.3",
"multer": "^2.1.1",
"postmark": "^4.0.7",
"prisma": "^6.19.2"
"prisma": "^6.19.2",
"slugify": "^1.6.9"
},
"devDependencies": {
"nodemon": "^3.1.11"
@@ -1727,7 +1728,6 @@
"integrity": "sha512-XTKeKxtQElcq3U9/jHyxSPgiRgeYDKxWTPOf6NkXA0dNj5j40MfEsZkMbyNpwDWCUv7YBFUl7I2VK/6ALbmhEg==",
"hasInstallScript": true,
"license": "Apache-2.0",
"peer": true,
"dependencies": {
"@prisma/config": "6.19.2",
"@prisma/engines": "6.19.2"
@@ -2064,6 +2064,15 @@
"node": ">=10"
}
},
"node_modules/slugify": {
"version": "1.6.9",
"resolved": "https://registry.npmjs.org/slugify/-/slugify-1.6.9.tgz",
"integrity": "sha512-vZ7rfeehZui7wQs438JXBckYLkIIdfHOXsaVEUMyS5fHo1483l1bMdo0EDSWYclY0yZKFOipDy4KHuKs6ssvdg==",
"license": "MIT",
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/statuses": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
+2 -1
View File
@@ -28,7 +28,8 @@
"jsonwebtoken": "^9.0.3",
"multer": "^2.1.1",
"postmark": "^4.0.7",
"prisma": "^6.19.2"
"prisma": "^6.19.2",
"slugify": "^1.6.9"
},
"devDependencies": {
"nodemon": "^3.1.11"
@@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `slug` to the `Blog` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Blog" ADD COLUMN "slug" TEXT NOT NULL;
@@ -0,0 +1,8 @@
/*
Warnings:
- A unique constraint covering the columns `[slug]` on the table `Blog` will be added. If there are existing duplicate values, this will fail.
*/
-- CreateIndex
CREATE UNIQUE INDEX "Blog_slug_key" ON "Blog"("slug");
+1 -1
View File
@@ -93,6 +93,7 @@ model Blog {
image String?
content Json
isActive Boolean @default(true)
slug String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -175,7 +176,6 @@ model AcademicsResearch {
updatedAt DateTime @updatedAt
}
model EmailConfig {
id Int @id @default(autoincrement())
name String
@@ -1,4 +1,5 @@
import prisma from "../prisma/client.js";
import slugify from "slugify";
/* CREATE BLOG */
@@ -13,6 +14,7 @@ export async function createBlog(req, res) {
image,
content,
isActive,
slug: slugify(title),
},
});
@@ -54,6 +56,27 @@ export async function getAllBlogs(req, res) {
/* GET SINGLE BLOG */
export async function getBlog(req, res) {
try {
const slug = req.params.slug;
console.log({ slug });
const blog = await prisma.blog.findUnique({
where: { slug },
});
if (!blog) {
return res.status(404).json({ error: "Blog not found" });
}
res.json(blog);
} catch (error) {
res.status(500).json({ error: error.message });
}
}
/* GET SINGLE BLOG (ADMIN)*/
export async function getBlogForAdmin(req, res) {
try {
const id = Number(req.params.id);
+5 -1
View File
@@ -6,6 +6,7 @@ import {
updateBlog,
deleteBlog,
getAllBlogs,
getBlogForAdmin,
} from "../controllers/blog.controller.js";
import jwtAuthMiddleware from "../middleware/auth.js";
@@ -15,11 +16,14 @@ const router = express.Router();
/* PUBLIC */
router.get("/", getBlogs);
router.get("/:id", getBlog);
router.get("/:slug", getBlog);
// Protected
router.get("/admin/all", jwtAuthMiddleware, getAllBlogs);
router.get("/admin/:id", jwtAuthMiddleware, getBlogForAdmin);
router.post("/", jwtAuthMiddleware, createBlog);
router.put("/:id", jwtAuthMiddleware, updateBlog);
router.delete("/:id", jwtAuthMiddleware, deleteBlog);
Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB