diff --git a/api/controllers/serviceController.js b/api/controllers/serviceController.js new file mode 100644 index 0000000..40472b0 --- /dev/null +++ b/api/controllers/serviceController.js @@ -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}`); + } +}; diff --git a/api/models/serviceSchema.js b/api/models/serviceSchema.js index 4598b63..e021a59 100644 --- a/api/models/serviceSchema.js +++ b/api/models/serviceSchema.js @@ -2,10 +2,28 @@ const mongoose = require("mongoose"); const { Schema } = mongoose; //___ servicesSchema -// service: String +// serviceType: String +// title: String +// description: [String] +// price: Number const serviceSchema = new Schema({ - services: String, + serviceType: { + type: String, + required: true, + }, + title: { + type: String, + required: true, + }, + desc: { + type: [String], + required: true, + }, + price: { + type: Number, + required: true, + }, }); -module.exports = serviceSchema; +module.exports = mongoose.model("Services", serviceSchema); diff --git a/api/routes/serviceRoutes.js b/api/routes/serviceRoutes.js new file mode 100644 index 0000000..c08cf68 --- /dev/null +++ b/api/routes/serviceRoutes.js @@ -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; diff --git a/server.js b/server.js index 363988c..31832d9 100644 --- a/server.js +++ b/server.js @@ -26,8 +26,10 @@ app.use( // * EXPRESS ROUTER MINI-APP const profile = require("./api/routes/profileRoutes"); const workorder = require("./api/routes/workorderRoutes"); +const services = require("./api/routes/serviceRoutes"); app.use("/api/profile", profile); app.use("/api/workorder", workorder); +app.use("/api/services", services); if (process.env.NODE_ENV === "production") { app.use(express.static("./build")); @@ -55,4 +57,3 @@ mongoose .catch((err) => { console.log({ error: err }); }); - diff --git a/src/App.css b/src/App.css index 74b5e05..1a8c21d 100644 --- a/src/App.css +++ b/src/App.css @@ -1,4 +1,4 @@ -.App { +/* .App { text-align: center; } @@ -35,4 +35,4 @@ to { transform: rotate(360deg); } -} +} */ diff --git a/src/App.js b/src/App.js index ff3c84f..9326670 100644 --- a/src/App.js +++ b/src/App.js @@ -5,30 +5,59 @@ import MainContentSection from "./components/root/MainContentSection"; import Footer from "./components/root/Footer"; import { ImpersonatorProvider } from "./backend/authorization/ImpersonatorContext"; import { UserProvider } from "./backend/authorization/UserContext"; -import { ThemeProvider } from "@material-ui/core"; -import theme from './styles/theme' +import { makeStyles } from "@material-ui/core/styles"; + +const useStyles = makeStyles((theme) => ({ + header: { + display: "flex", + justifyContent: "space-between", + alignItems: "center", + height: "15vh", + // maxWidth: "900px", + padding: "2rem", + backgroundColor: "#212529", + }, + main: { + display: "flex", + flexDirection: "column", + justifyContent: "center", + // width: "90%", + // maxWidth: "1200px", + margin: "0 auto", + height: "70vh", + backgroundColor: "gray", + }, + footer: { + display: "flex", + flexDirection: "column", + justifyContent: "center", + alignItems: "center", + height: "15vh", + padding: "2rem", + backgroundColor: "#212529", + }, +})); const App = () => { + const classes = useStyles(); const [loginClick, setLoginClick] = useState(false); return ( - - - - -
-
-
-
- -
-