Skip to content

Commit

Permalink
Merge pull request #34 from Edward-J-Xu/edward/final
Browse files Browse the repository at this point in the history
Fix game id requirement
  • Loading branch information
Edward-J-Xu authored Mar 26, 2023
2 parents c48378e + cde5f5d commit 76dbada
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions client/src/pages/posts/createPost.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function CreatePost() {
const initialValues = {
title: "",
postText: "",
gameId: "",
};

useEffect(() => {
Expand All @@ -31,6 +32,9 @@ function CreatePost() {
const validationSchema = Yup.object().shape({
title: Yup.string().required("You must input a Title!"),
postText: Yup.string().required(),
gameId: Yup.number()
.required()
.max(199, "Game ID must be less than 200"),
});

const onSubmit = (data) => {
Expand Down Expand Up @@ -63,22 +67,30 @@ function CreatePost() {
validationSchema={validationSchema}
>
<Form className="formContainer">
<label>Title: </label>
<label>Title: </label>
<ErrorMessage name="title" component="span" />
<Field
autocomplete="off"
autoComplete="off"
id="inputCreatePost"
name="title"
placeholder="(Ex. Title...)"
/>
<label>Post: </label>
<ErrorMessage name="postText" component="span" />
<Field
autocomplete="off"
autoComplete="off"
id="inputCreatePost"
name="postText"
placeholder="(Ex. Post...)"
/>
<label>Game ID: </label>
<ErrorMessage name="gameId" component="span" />
<Field
autoComplete="off"
id="inputCreatePost"
name="gameId"
placeholder="(Between 1 and 199)"
/>

<button type="submit"> Create Post</button>
</Form>
Expand Down
6 changes: 3 additions & 3 deletions server/routes/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ router.get("/byId/:id", async (req, res) => {
});

router.get("/byuserId/:id", async (req, res) => {
console.log("User's Ran!!!!!!!!!! ");
const id = req.params.id;
const listOfPosts = await db.pool.query(
"select p.*, count(l.post_id) as likeCount " +
Expand All @@ -60,13 +59,14 @@ router.get("/byuserId/:id", async (req, res) => {
router.post("/", validateToken, async (req, res) => {
const post = req.body;
post.username = req.user.username;
const parsedGid = parseInt(post.gameId);
// Create / Insert Posts
console.log("creating a post:", post);
// await Posts.create(post);
try {
await db.pool.query(
"insert into post (title, postText, username) values (?, ?, ?)",
[post.title, post.postText, post.username]
"insert into post (title, postText, username, gid) values (?, ?, ?, ?)",
[post.title, post.postText, post.username, parsedGid]
);
} catch (e) {
console.log(e);
Expand Down

0 comments on commit 76dbada

Please sign in to comment.