-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
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,12 @@ | ||
-- CreateTable | ||
CREATE TABLE "Blog" ( | ||
"id" STRING NOT NULL, | ||
"title" STRING NOT NULL, | ||
"tags" STRING[], | ||
"content" STRING NOT NULL, | ||
"date" STRING NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "Blog_pkey" PRIMARY KEY ("id") | ||
); |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {saveToDatabase} from './repository.js' | ||
|
||
export const saveBlog = async (req, res) => { | ||
const { title, content, tags,date } = req.body; | ||
const blog = { | ||
title, | ||
tags, | ||
content, | ||
date | ||
}; | ||
const result = await saveToDatabase(blog); | ||
if(result) { | ||
return res.send({ | ||
status: 201, | ||
message: "blog saved successfully" | ||
}); | ||
} | ||
else | ||
{ | ||
return res.send({ | ||
status: 500, | ||
message: "blog could not be saved" | ||
}); | ||
} | ||
} | ||
|
||
// const getBlogs = async (req, res) => { | ||
// const blogs = await Blog.findAll(); | ||
// return res.json(blogs); | ||
// } |
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 @@ | ||
export { default as blogRouter } from './routes.js' |
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,19 @@ | ||
import db from "../../db/client.js" | ||
|
||
export const saveToDatabase = (blog) => { | ||
// Save to database | ||
return db.Blog.create({ | ||
data:blog | ||
}); | ||
|
||
} | ||
|
||
// export const getAllBlogs = async () => { | ||
// try { | ||
// const blogs = await db.Blog.findAll(); | ||
// return blogs; | ||
// } catch (error) { | ||
// console.log(error); | ||
// return []; | ||
// } | ||
// } |
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,10 @@ | ||
import { Router } from "express"; | ||
import { saveBlog } from "./controller.js"; | ||
|
||
|
||
const router = Router() | ||
|
||
router.post('/create', saveBlog) | ||
// router.get('/', getAllInductionController) | ||
|
||
export default router; |
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