-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from michacurri/develop
Develop
- Loading branch information
Showing
32 changed files
with
902 additions
and
383 deletions.
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,25 @@ | ||
const Services = require("../models/serviceSchema"); | ||
|
||
exports.findService = async (title) => { | ||
try { | ||
const serviceRes = await Services.find({ title }); | ||
return serviceRes; | ||
} catch (err) { | ||
throw err; | ||
} | ||
}; | ||
|
||
exports.createService = async ({ serviceType, title, desc, price }) => { | ||
try { | ||
const newService = new Service({ | ||
serviceType, | ||
title, | ||
desc, | ||
price, | ||
}); | ||
const service = await newService.save(); | ||
return service; | ||
} catch (err) { | ||
console.log(`error: ${err}`); | ||
} | ||
}; |
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,52 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const Services = require("../models/serviceSchema"); | ||
|
||
router.route("/").get(async (req, res) => { | ||
try { | ||
const services = await Services.find(); | ||
res.json(services); | ||
} catch (err) { | ||
res.json({ error: err }); | ||
} | ||
}); | ||
|
||
router.route("/create").post(async (req, res) => { | ||
const { serviceType, title, desc, price } = req.body; | ||
if (!serviceType || serviceType === " ") { | ||
res.status(400).json({ message: "service type must be provided" }); | ||
return; | ||
} | ||
if (!title || title === " ") { | ||
res.status(400).json({ message: "title must be provided" }); | ||
return; | ||
} | ||
if (!desc || desc === " ") { | ||
res.status(400).json({ message: "description must be provided" }); | ||
return; | ||
} | ||
if (!price || price === " ") { | ||
res.status(400).json({ message: "price must be provided" }); | ||
return; | ||
} | ||
try { | ||
const service = await findService(title); | ||
if (service) { | ||
res | ||
.status(400) | ||
.json({ message: `a service with this title already exists` }); | ||
} | ||
const newService = await createService({ | ||
serviceType, | ||
title, | ||
desc, | ||
price, | ||
}); | ||
res.status(200).json({ data: { id: newService._id } }); | ||
} catch (err) { | ||
console.log(err); | ||
res.status(500).json({ message: "Internal server error" }); | ||
} | ||
}); | ||
|
||
module.exports = 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
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,4 +1,4 @@ | ||
.App { | ||
/* .App { | ||
text-align: center; | ||
} | ||
|
@@ -35,4 +35,4 @@ | |
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
} */ |
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
Oops, something went wrong.