Skip to content

Commit

Permalink
Merge pull request #35 from fac25/pets-validation
Browse files Browse the repository at this point in the history
My pets form
  • Loading branch information
flare-s authored Oct 13, 2022
2 parents b9532ef + 6436792 commit 7472157
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 9 deletions.
Binary file modified db.sqlite
Binary file not shown.
Binary file added public/uploads/2000b8c31e44853c90a5769215e06802
Binary file not shown.
Binary file added public/uploads/51f1a1f376c11a37001413afcaa31757
Binary file not shown.
Binary file added public/uploads/a4969c64bebb992774677a21d98950b9
Binary file not shown.
Binary file added public/uploads/bd650ab68c7a672e3c30b17918cfdcce
Binary file not shown.
9 changes: 4 additions & 5 deletions src/routes/my-pets.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ function post(req, res) {
const currentUser = sessionId && sessionId.user_id;
const title = "Submit a post about your pet";
const errors = {};
const { petName, petType, petImg } = req.body;
const { petName, petType, sharing } = req.body;
if (!petName) {
errors.petName = "Please enter your pet's name";
}
if (!petType) {
errors.petType = "Please enter your pet's type";
}
if (!petImg) {
errors.petImg = "Please upload your pet's image :)";
}
if (Object.keys(errors).length > 0) {
const body = Layout({
title,
Expand All @@ -42,7 +39,9 @@ function post(req, res) {
}
const petImage = req.file.path.replace("public", "..");
console.log(petImage);
insertPet(petName, currentUser, petType, petImage);
let sharingValue;
sharing.checked ? (sharingValue = 0) : (sharingValue = 1);
insertPet(petName, currentUser, petType, petImage, sharingValue);
// sharing = (sharing === "on") ? 1 : 0;
res.redirect(`/my-pets/${currentUser}`);
}
Expand Down
5 changes: 1 addition & 4 deletions src/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ function MyPets(id, errors = {}, values = {}) {
${validation(errors.petType)}
<label for="petImg">Pet Image<span aria-hidden="true">*</span></label>
<input id="petImg" name="petImg" type="file" value='${
values.petImg ? values.petImg : ""
}'>
${validation(errors.petImg)}
<input id="petImg" name="petImg" type="file">
<label for="sharing">Do you want to share with other users?
<span aria-hidden="true">*</span>
Expand Down

0 comments on commit 7472157

Please sign in to comment.