mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 08:36:10 +02:00
Fix fix fix!
This commit is contained in:
Generated
+6943
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -28,21 +28,23 @@
|
|||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/redis": "^4.0.11",
|
"@types/redis": "^4.0.11",
|
||||||
"argon2": "^0.28.5",
|
"argon2": "^0.28.5",
|
||||||
|
"axios": "^0.26.1",
|
||||||
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"express": "^4.17.3",
|
"express": "^4.17.3",
|
||||||
"handlebars": "^4.7.7",
|
"handlebars": "^4.7.7",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mjml": "^4.12.0",
|
"mjml": "^4.12.0",
|
||||||
"nanoid": "^3.3.2",
|
"nanoid": "^3.3.2",
|
||||||
|
"node-fetch": "^3.2.3",
|
||||||
"nodemailer": "^6.7.2",
|
"nodemailer": "^6.7.2",
|
||||||
"prisma": "^3.10.0",
|
"prisma": "^3.10.0",
|
||||||
"redis": "^4.0.4",
|
"redis": "^4.0.4",
|
||||||
"axios": "^0.26.1",
|
|
||||||
"node-fetch": "^3.2.3",
|
|
||||||
"ts-node": "^10.5.0",
|
"ts-node": "^10.5.0",
|
||||||
"typescript": "^4.5.5"
|
"typescript": "^4.5.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/cors": "^2.8.12",
|
||||||
"@types/node": "^8.9.5",
|
"@types/node": "^8.9.5",
|
||||||
"nodemon": "^2.0.15"
|
"nodemon": "^2.0.15"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ export const register = async (req: Request, res: Response) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hash = await argon2.hash("salty" + password + "salty",{
|
const hash = await argon2.hash("salty" + password + "salty", {
|
||||||
type: argon2.argon2id
|
type: argon2.argon2id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!(await prisma.organization.findUnique({ where: { id: organization } }))) {
|
if (!(await prisma.organization.findUnique({ where: { id: organization } }))) {
|
||||||
@@ -96,8 +96,8 @@ export const authenthicate = async (req: Request, res: Response) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hash = await argon2.hash("salty" + password + "salty",{
|
const hash = await argon2.hash("salty" + password + "salty", {
|
||||||
type: argon2.argon2id
|
type: argon2.argon2id,
|
||||||
});
|
});
|
||||||
|
|
||||||
const user = await prisma.user.findUnique({ where: { email: name } });
|
const user = await prisma.user.findUnique({ where: { email: name } });
|
||||||
@@ -106,7 +106,7 @@ export const authenthicate = async (req: Request, res: Response) => {
|
|||||||
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
|
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await argon2.verify(user.passwordHash,hash)) {
|
if (await argon2.verify(user.passwordHash, hash)) {
|
||||||
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
|
return res.status(403).json(createDefaultError("Username or Password wrong", {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ export const authenthicate = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
req.headers.authorization = jwt.sign(userjwt, JWT_SECRET);
|
req.headers.authorization = jwt.sign(userjwt, JWT_SECRET);
|
||||||
|
|
||||||
res.status(200).json(createDefaultSucces("Logged in succesfully",{}))
|
res.status(200).json(createDefaultSucces("Logged in succesfully", { token: req.headers.authorization }));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const verifyEmail = async (req: Request, res: Response) => {
|
export const verifyEmail = async (req: Request, res: Response) => {
|
||||||
|
|||||||
@@ -2,22 +2,32 @@ import { Request, Response } from "express";
|
|||||||
import { HttpStatusCodes } from "../statusCodes";
|
import { HttpStatusCodes } from "../statusCodes";
|
||||||
import { DataType } from "../datatypes";
|
import { DataType } from "../datatypes";
|
||||||
import prisma from "../lib/prisma.lib";
|
import prisma from "../lib/prisma.lib";
|
||||||
|
import { connect } from "net";
|
||||||
|
|
||||||
export const addOrder = async (req: Request, res: Response) => {
|
export const addOrder = async (req: Request, res: Response) => {
|
||||||
if (typeof req.body.userId !== "number" || !Array.isArray(req.body.pizzas)) {
|
if (!Array.isArray(req.body.pizzas)) {
|
||||||
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
res.status(HttpStatusCodes.BAD_REQUEST).json({
|
||||||
userId: DataType.NUMBER,
|
|
||||||
pizzas: DataType.ARRAY,
|
pizzas: DataType.ARRAY,
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const userId = req.auth?.id;
|
||||||
|
if (!userId) return res.status(500).json();
|
||||||
|
|
||||||
console.log(req.body.pizzas);
|
console.log(req.body.pizzas);
|
||||||
|
|
||||||
|
const pizzas = req.body.pizzas.map((a: number) => ({
|
||||||
|
id: a,
|
||||||
|
}));
|
||||||
|
|
||||||
|
console.log(pizzas);
|
||||||
|
|
||||||
const order = await prisma.order.create({
|
const order = await prisma.order.create({
|
||||||
data: {
|
data: {
|
||||||
userId: req.body.userId,
|
userId: userId,
|
||||||
pizzas: req.body.pizzas,
|
pizzas: {
|
||||||
|
connect: pizzas,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import express, { NextFunction, Request, Response } from "express";
|
import express, { NextFunction, Request, Response } from "express";
|
||||||
import dotenv from "dotenv";
|
import dotenv from "dotenv";
|
||||||
|
import argon2 from "argon2";
|
||||||
|
import cors from "cors";
|
||||||
|
|
||||||
import adminRoutes from "./routes/auth.route";
|
import adminRoutes from "./routes/auth.route";
|
||||||
import { requireAuthentication } from "./middleware/auth.middle";
|
import { requireAuthentication } from "./middleware/auth.middle";
|
||||||
|
import prisma from "./lib/prisma.lib";
|
||||||
const ordersRoutes = require("./routes/orders.route");
|
const ordersRoutes = require("./routes/orders.route");
|
||||||
const organizationsRoutes = require("./routes/organisations.route");
|
const organizationsRoutes = require("./routes/organisations.route");
|
||||||
const pizzasRoutes = require("./routes/pizzas.route");
|
const pizzasRoutes = require("./routes/pizzas.route");
|
||||||
@@ -16,6 +19,8 @@ const app = express();
|
|||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
app.use(cors());
|
||||||
|
|
||||||
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
app.use((err: any, req: Request, res: Response, next: NextFunction) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(400).send({
|
res.status(400).send({
|
||||||
@@ -34,6 +39,31 @@ app.use("/pizza", pizzasRoutes);
|
|||||||
app.use("/restaurant", restaurantsRoutes);
|
app.use("/restaurant", restaurantsRoutes);
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
if ((await prisma.user.findUnique({ where: { email: "[email protected]" } })) == undefined)
|
||||||
|
await prisma.user.create({
|
||||||
|
data: {
|
||||||
|
role: "ADMIN",
|
||||||
|
email: "[email protected]",
|
||||||
|
passwordHash: await argon2.hash("salty" + "admin" + "salty", {
|
||||||
|
type: argon2.argon2id,
|
||||||
|
}),
|
||||||
|
status: "ENABLED",
|
||||||
|
organization: {
|
||||||
|
connectOrCreate: {
|
||||||
|
where: { id: 1 },
|
||||||
|
create: {
|
||||||
|
id: 1,
|
||||||
|
domain: "@admin.admin",
|
||||||
|
name: "admin_org",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
passwordSalt: "salty",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(await prisma.user.count());
|
||||||
|
|
||||||
app.get("/", (_req, res) => {
|
app.get("/", (_req, res) => {
|
||||||
res.send("Hello World!");
|
res.send("Hello World!");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const router = express.Router();
|
|||||||
|
|
||||||
router.get("/", requireAuthentication, getOrders);
|
router.get("/", requireAuthentication, getOrders);
|
||||||
router.get("/:id", getOrder);
|
router.get("/:id", getOrder);
|
||||||
router.post("/", addOrder);
|
router.post("/", requireAuthentication, addOrder);
|
||||||
router.put("/:id", updateOrder);
|
router.put("/:id", updateOrder);
|
||||||
router.delete("/:id", deleteOrder);
|
router.delete("/:id", deleteOrder);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user