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
+9 -16
View File
@@ -30,28 +30,20 @@ model Restaurant {
} }
model Pizza { model Pizza {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
name String name String
description String? description String?
price Decimal price Decimal
restaurant Restaurant @relation(fields: [restaurantId], references: [id]) restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurantId Int restaurantId Int
orders PizzaToOrder[] orders Order[]
} }
model Order { model Order {
id Int @id @default(autoincrement()) id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id]) user User @relation(fields: [userId], references: [id])
userId Int userId Int
pizzas PizzaToOrder[] pizzas Pizza[]
}
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
} }
model Organization { model Organization {
@@ -65,8 +57,9 @@ enum Role {
USER USER
ADMIN ADMIN
} }
enum Status { enum Status {
UNVERIFIED UNVERIFIED
VERIFIED VERIFIED
ENABLED ENABLED
} }
+3 -10
View File
@@ -28,14 +28,7 @@ const ROLES: readonly string[] = [Role.ADMIN, Role.USER];
export const register = async (req: Request, res: Response) => { export const register = async (req: Request, res: Response) => {
const { name, password, role, organization } = req.body || {}; const { name, password, role, organization } = req.body || {};
if ( if (!(typeof name === "string" && typeof password === "string" && typeof organization === "number")) {
!(
typeof name === "string" &&
typeof password === "string" &&
ROLES.includes(role) &&
typeof organization === "number"
)
) {
return res.status(400).json( return res.status(400).json(
createDefaultError("Request body does not match required parameters", { createDefaultError("Request body does not match required parameters", {
name: "string", 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}`, {})); 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) { if (req.auth?.role !== Role.ADMIN) {
return res.status(401).json(createDefaultError(`Unauthorized`, {})); return res.status(401).json(createDefaultError(`Unauthorized`, {}));
} }
@@ -65,7 +58,7 @@ export const register = async (req: Request, res: Response) => {
passwordSalt: "salty", passwordSalt: "salty",
passwordHash: hash, passwordHash: hash,
role: role as Role, 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 }, organization: { connect: { id: organization } || undefined },
}, },
select: { select: {
+19 -1
View File
@@ -29,8 +29,13 @@ export const addOrder = async (req: Request, res: Response) => {
connect: pizzas, connect: pizzas,
}, },
}, },
select: {
pizzas: true,
},
}); });
console.log(order);
res.status(HttpStatusCodes.CREATED).json(order); res.status(HttpStatusCodes.CREATED).json(order);
}; };
@@ -93,13 +98,26 @@ export const getOrder = async (req: Request, res: Response) => {
where: { where: {
id: id, id: id,
}, },
select: {
id: true,
pizzas: true,
user: true,
userId: true,
},
}); });
res.status(HttpStatusCodes.OK).json(order); res.status(HttpStatusCodes.OK).json(order);
}; };
export const getOrders = async (_req: Request, res: Response) => { 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); res.status(HttpStatusCodes.OK).json(orders);
}; };
+6 -2
View File
@@ -12,7 +12,11 @@ export let mailAccount = {
let transporter = let transporter =
process.env.DEV == "true" || process.env.DOMAIN == undefined process.env.DEV == "true" || process.env.DOMAIN == undefined
? (async () => { ? (async () => {
mailAccount = await nodemailer.createTestAccount(); //mailAccount = await nodemailer.createTestAccount();
mailAccount = {
user: "[email protected]",
pass: "24yk6juHY8PzftcGTa",
};
//mailAccount = { //mailAccount = {
// user: "", // user: "",
// pass: "", // pass: "",
@@ -64,7 +68,7 @@ export const verificationMail = async (to: string, id: string) => {
//TODO: Replace other handlebars with final values //TODO: Replace other handlebars with final values
const message = Handlebars.compile(raw); const message = Handlebars.compile(raw);
const data = {}; const data = { link: id };
const compiled = message(data); const compiled = message(data);
sendMail(mailAccount.user, to, "Verify Email", undefined, compiled); sendMail(mailAccount.user, to, "Verify Email", undefined, compiled);