mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 00:26:07 +02:00
Generated
+3210
-4
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -21,13 +21,15 @@
|
||||
"dependencies": {
|
||||
"@prisma/client": "^3.10.0",
|
||||
"@types/express": "^4.17.13",
|
||||
"axios": "^0.26.1",
|
||||
"express": "^4.17.3",
|
||||
"prisma": "^3.10.0",
|
||||
"node-fetch": "^3.2.3",
|
||||
"prisma": "^3.11.1",
|
||||
"ts-node": "^10.5.0",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^8.9.5",
|
||||
"nodemon": "^1.18.4"
|
||||
"nodemon": "^2.0.15"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ model Organization {
|
||||
name String
|
||||
domain String
|
||||
users User[]
|
||||
userId Int
|
||||
}
|
||||
|
||||
enum Role {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Request, Response } from "express";
|
||||
import { HttpStatusCodes } from "../statusCodes";
|
||||
import { DataType } from "../datatypes";
|
||||
import prisma from "../lib/prisma.lib";
|
||||
|
||||
export const addOrder = async (req: Request, res: Response) => {
|
||||
if (typeof req.body.userId !== "number" || !Array.isArray(req.body.pizzas)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
userId: DataType.NUMBER,
|
||||
pizzas: DataType.ARRAY,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(req.body.pizzas);
|
||||
|
||||
const order = await prisma.order.create({
|
||||
data: {
|
||||
userId: req.body.userId,
|
||||
pizzas: req.body.pizzas,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.CREATED).json(order);
|
||||
};
|
||||
|
||||
export const updateOrder = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
} else if (typeof req.body.userId !== "string" || !Array.isArray(req.body.pizzas)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
pizzas: DataType.ARRAY,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const order = await prisma.order.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
userId: req.body.userId,
|
||||
pizzas: req.body.pizzas,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(order);
|
||||
};
|
||||
|
||||
export const deleteOrder = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.order.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.NO_CONTENT).json();
|
||||
};
|
||||
|
||||
export const getOrder = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
const order = await prisma.restaurant.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(order);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Request, Response } from "express";
|
||||
import { HttpStatusCodes } from "../statusCodes";
|
||||
import { DataType } from "../datatypes";
|
||||
import prisma from "../lib/prisma.lib";
|
||||
|
||||
export const addOrganization = async (req: Request, res: Response) => {
|
||||
if (typeof req.body.name !== "string" || typeof req.body.domain !== "string") {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const organization = await prisma.organization.create({
|
||||
data: {
|
||||
name: req.body.name,
|
||||
domain: req.body.domain,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.CREATED).json(organization);
|
||||
};
|
||||
|
||||
export const updateOrganization = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
} else if (typeof req.body.name !== "string" || typeof req.body.domain !== "string") {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const organization = await prisma.organization.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
name: req.body.name,
|
||||
domain: req.body.domain,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(organization);
|
||||
};
|
||||
|
||||
export const deleteOrganization = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.organization.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.NO_CONTENT).json();
|
||||
};
|
||||
|
||||
export const getOrganization = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
const organization = await prisma.restaurant.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(organization);
|
||||
};
|
||||
@@ -0,0 +1,98 @@
|
||||
import { Request, Response } from "express";
|
||||
import { HttpStatusCodes } from "../statusCodes";
|
||||
import { DataType } from "../datatypes";
|
||||
import prisma from "../lib/prisma.lib";
|
||||
|
||||
export const addPizza = async (req: Request, res: Response) => {
|
||||
if (
|
||||
typeof req.body.name !== "string" ||
|
||||
typeof req.body.description !== "string" ||
|
||||
typeof req.body.restaurantId !== "number"
|
||||
) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
restaurantId: DataType.NUMBER,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const pizza = await prisma.pizza.create({
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
restaurantId: req.body.restaurantId,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.CREATED).json(pizza);
|
||||
};
|
||||
|
||||
export const updatePizza = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
} else if (
|
||||
typeof req.body.name !== "string" ||
|
||||
typeof req.body.description !== "string" ||
|
||||
typeof req.body.restaurantId !== "number"
|
||||
) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
restaurantId: DataType.NUMBER,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const pizza = await prisma.pizza.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(pizza);
|
||||
};
|
||||
|
||||
export const deletePizza = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.pizza.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.NO_CONTENT).json();
|
||||
};
|
||||
|
||||
export const getPizza = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
const pizza = await prisma.pizza.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(pizza);
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Request, Response } from "express";
|
||||
import { HttpStatusCodes } from "../statusCodes";
|
||||
import { DataType } from "../datatypes";
|
||||
import prisma from "../lib/prisma.lib";
|
||||
|
||||
export const addRestaurant = async (req: Request, res: Response) => {
|
||||
if (typeof req.body.name !== "string" || typeof req.body.description !== "string") {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const restaurant = await prisma.restaurant.create({
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.CREATED).json(restaurant);
|
||||
};
|
||||
|
||||
export const updateRestaurant = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
} else if (typeof req.body.name !== "string" || typeof req.body.description !== "string") {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
name: DataType.STRING,
|
||||
description: DataType.STRING,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const restaurant = await prisma.restaurant.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
name: req.body.name,
|
||||
description: req.body.description,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(restaurant);
|
||||
};
|
||||
|
||||
export const deleteRestaurant = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.restaurant.delete({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.NO_CONTENT).json();
|
||||
};
|
||||
|
||||
export const getRestaurant = async (req: Request, res: Response) => {
|
||||
const id = Number(req.params.id);
|
||||
|
||||
if (Number.isNaN(id)) {
|
||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||
id: DataType.NUMBER,
|
||||
});
|
||||
}
|
||||
|
||||
const restaurant = await prisma.restaurant.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(HttpStatusCodes.OK).json(restaurant);
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Request, Response } from "express";
|
||||
|
||||
export const sayHello = async (request: Request, response: Response) => {
|
||||
response.status(200).send("Hello!");
|
||||
};
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export const DataType = {
|
||||
STRING: "String",
|
||||
NUMBER: "Number",
|
||||
ARRAY: "Array",
|
||||
};
|
||||
@@ -1,6 +1,19 @@
|
||||
import express from "express";
|
||||
const app = express();
|
||||
|
||||
const testRoutes = require("./routes/testrouter.route");
|
||||
const ordersRoutes = require("./routes/orders.route");
|
||||
const organizationsRoutes = require("./routes/organisations.route");
|
||||
const pizzasRoutes = require("./routes/pizzas.route");
|
||||
const restaurantsRoutes = require("./routes/restaurants.route");
|
||||
|
||||
app.use(express.json());
|
||||
app.use("/tests", testRoutes);
|
||||
app.use("/order", ordersRoutes);
|
||||
app.use("/organization", organizationsRoutes);
|
||||
app.use("/pizza", pizzasRoutes);
|
||||
app.use("/restaurant", restaurantsRoutes);
|
||||
|
||||
async function main() {
|
||||
app.get("/", (req, res) => {
|
||||
res.send("Hello World!");
|
||||
|
||||
@@ -5,4 +5,4 @@ let prisma: PrismaClient;
|
||||
|
||||
prisma = new PrismaClient();
|
||||
|
||||
export default prisma;
|
||||
export default prisma;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import express from "express";
|
||||
import { addOrder, deleteOrder, getOrder, updateOrder } from "../controller/orders.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/:id", getOrder);
|
||||
router.post("/", addOrder);
|
||||
router.put("/:id", updateOrder);
|
||||
router.delete("/:id", deleteOrder);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,16 @@
|
||||
import express from "express";
|
||||
import {
|
||||
addOrganization,
|
||||
deleteOrganization,
|
||||
getOrganization,
|
||||
updateOrganization,
|
||||
} from "../controller/organisations.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/:id", getOrganization);
|
||||
router.post("/", addOrganization);
|
||||
router.put("/:id", updateOrganization);
|
||||
router.delete("/:id", deleteOrganization);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,11 @@
|
||||
import express from "express";
|
||||
import { addPizza, deletePizza, getPizza, updatePizza } from "../controller/pizzas.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/:id", getPizza);
|
||||
router.post("/", addPizza);
|
||||
router.put("/:id", updatePizza);
|
||||
router.delete("/:id", deletePizza);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,11 @@
|
||||
import express from "express";
|
||||
import { addRestaurant, deleteRestaurant, getRestaurant, updateRestaurant } from "../controller/restaurants.controller";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get("/:id", getRestaurant);
|
||||
router.post("/", addRestaurant);
|
||||
router.put("/:id", updateRestaurant);
|
||||
router.delete("/:id", deleteRestaurant);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,12 @@
|
||||
import express from "express";
|
||||
import { sayHello } from "../controller/testcontroller.controller";
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
router.get("/", (request: Request, response: Response) => {
|
||||
response.status(200).send("Cool test stuff!");
|
||||
});
|
||||
|
||||
router.post("/test1", sayHello);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export const HttpStatusCodes = {
|
||||
OK: 200,
|
||||
CREATED: 201,
|
||||
MODIFIED: 202,
|
||||
NO_CONTENT: 204,
|
||||
BAD_REQUEST: 400,
|
||||
NOT_FOUND: 404,
|
||||
INTERNAL_SERVER: 500,
|
||||
};
|
||||
Reference in New Issue
Block a user