E̵̯͎͖̫̙̩̣͈͖̲̜̠̭̟͒̃͒͑̓ͅṽ̸͇͓͓͚̬̹̟͈̰̤͈͇͆̑̓̏̂̈́͌͜͜ẻ̷̩̺͉̱͔͍̹̙̝̱r̸̬͊̓̍̌̏ÿ̵̧̳̟̭̤̙̼͎̮̱̞́̋̿̂̾͋͊́͌̕͘o̵̜̲̱͉̭̳͂̾̄̍̔́̂̀n̶̻̠͈̾͑͐́͘ȩ̶͙̗̗̻̤͇̭̥̄̑̓̋́̊̾̍́͆̾͑̊̕͠ ̸̛̻̩̫͔͕̤̰͚͒͑̀̾͗̾̈́͐̈́̉̍̾̋̐ì̴̛̲͂͊͐̀̆̕s̸̨͚̲̞̺̖̺̞͚̱͚̘̀͂͆̂ ̷͇̽̈́͗͘f̴̘̰̠͂̾̂̓͆́͒̋͛͠i̶͎͓͍̦͈̞͙̣͕͕͚̖̳̓̉̋͐̊̇̚̚͝ņ̵̥͚͈͕̓̍͜ͅe̵̥̳̹͖̮̰͈͕͙͌̆́̊̔̎͑̇̾͆͘͝͝ͅ

n̶̥̑͊̚̕͠o̷͇̗̞̦͚̐̊̓̋̕ț̶̜͉͔̎
This commit is contained in:
Stefan-5422
2022-06-14 19:28:41 +00:00
parent 1e160a94d2
commit 22dca614e7
4 changed files with 37 additions and 29 deletions
+7 -14
View File
@@ -30,28 +30,20 @@ model Restaurant {
}
model Pizza {
id Int @id @default(autoincrement())
id Int @id @default(autoincrement())
name String
description String?
price Decimal
restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurantId Int
orders PizzaToOrder[]
orders Order[]
}
model Order {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
pizzas PizzaToOrder[]
}
model PizzaToOrder {
id Int @id @default(autoincrement())
order Order @relation(fields: [orderId], references: [id])
orderId Int
pizza Pizza @relation(fields: [pizzaId], references: [id])
pizzaId Int
pizzas Pizza[]
}
model Organization {
@@ -65,6 +57,7 @@ enum Role {
USER
ADMIN
}
enum Status {
UNVERIFIED
VERIFIED
+3 -10
View File
@@ -28,14 +28,7 @@ const ROLES: readonly string[] = [Role.ADMIN, Role.USER];
export const register = async (req: Request, res: Response) => {
const { name, password, role, organization } = req.body || {};
if (
!(
typeof name === "string" &&
typeof password === "string" &&
ROLES.includes(role) &&
typeof organization === "number"
)
) {
if (!(typeof name === "string" && typeof password === "string" && typeof organization === "number")) {
return res.status(400).json(
createDefaultError("Request body does not match required parameters", {
name: "string",
@@ -53,7 +46,7 @@ export const register = async (req: Request, res: Response) => {
return res.status(404).json(createDefaultError(`Could not find organization with id ${organization}`, {}));
}
if (role ? ("USER" as Role) === Role.ADMIN : Role) {
if ((role ?? ("USER" as Role)) === Role.ADMIN) {
if (req.auth?.role !== Role.ADMIN) {
return res.status(401).json(createDefaultError(`Unauthorized`, {}));
}
@@ -65,7 +58,7 @@ export const register = async (req: Request, res: Response) => {
passwordSalt: "salty",
passwordHash: hash,
role: role as Role,
status: role === Role.ADMIN ? Status.UNVERIFIED : Status.ENABLED,
status: role === Role.ADMIN ? Status.ENABLED : Status.ENABLED,
organization: { connect: { id: organization } || undefined },
},
select: {
+19 -1
View File
@@ -29,8 +29,13 @@ export const addOrder = async (req: Request, res: Response) => {
connect: pizzas,
},
},
select: {
pizzas: true,
},
});
console.log(order);
res.status(HttpStatusCodes.CREATED).json(order);
};
@@ -93,13 +98,26 @@ export const getOrder = async (req: Request, res: Response) => {
where: {
id: id,
},
select: {
id: true,
pizzas: true,
user: true,
userId: true,
},
});
res.status(HttpStatusCodes.OK).json(order);
};
export const getOrders = async (_req: Request, res: Response) => {
const orders = await prisma.order.findMany();
const orders = await prisma.order.findMany({
select: {
id: true,
pizzas: true,
user: true,
userId: true,
},
});
res.status(HttpStatusCodes.OK).json(orders);
};
+6 -2
View File
@@ -12,7 +12,11 @@ export let mailAccount = {
let transporter =
process.env.DEV == "true" || process.env.DOMAIN == undefined
? (async () => {
mailAccount = await nodemailer.createTestAccount();
//mailAccount = await nodemailer.createTestAccount();
mailAccount = {
user: "[email protected]",
pass: "24yk6juHY8PzftcGTa",
};
//mailAccount = {
// user: "",
// pass: "",
@@ -64,7 +68,7 @@ export const verificationMail = async (to: string, id: string) => {
//TODO: Replace other handlebars with final values
const message = Handlebars.compile(raw);
const data = {};
const data = { link: id };
const compiled = message(data);
sendMail(mailAccount.user, to, "Verify Email", undefined, compiled);