mirror of
https://github.com/GithubOrgProjectPiza/server.git
synced 2026-09-04 00:26:07 +02:00
E̵̯͎͖̫̙̩̣͈͖̲̜̠̭̟͒̃͒͑̓ͅṽ̸͇͓͓͚̬̹̟͈̰̤͈͇͆̑̓̏̂̈́͌͜͜ẻ̷̩̺͉̱͔͍̹̙̝̱r̸̬͊̓̍̌̏ÿ̵̧̳̟̭̤̙̼͎̮̱̞́̋̿̂̾͋͊́͌̕͘o̵̜̲̱͉̭̳͂̾̄̍̔́̂̀n̶̻̠͈̾͑͐́͘ȩ̶͙̗̗̻̤͇̭̥̄̑̓̋́̊̾̍́͆̾͑̊̕͠ ̸̛̻̩̫͔͕̤̰͚͒͑̀̾͗̾̈́͐̈́̉̍̾̋̐ì̴̛̲͂͊͐̀̆̕s̸̨͚̲̞̺̖̺̞͚̱͚̘̀͂͆̂ ̷͇̽̈́͗͘f̴̘̰̠͂̾̂̓͆́͒̋͛͠i̶͎͓͍̦͈̞͙̣͕͕͚̖̳̓̉̋͐̊̇̚̚͝ņ̵̥͚͈͕̓̍͜ͅe̵̥̳̹͖̮̰͈͕͙͌̆́̊̔̎͑̇̾͆͘͝͝ͅ
n̶̥̑͊̚̕͠o̷͇̗̞̦͚̐̊̓̋̕ț̶̜͉͔̎
This commit is contained in:
+9
-16
@@ -30,28 +30,20 @@ model Restaurant {
|
||||
}
|
||||
|
||||
model Pizza {
|
||||
id Int @id @default(autoincrement())
|
||||
name String
|
||||
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,8 +57,9 @@ enum Role {
|
||||
USER
|
||||
ADMIN
|
||||
}
|
||||
|
||||
enum Status {
|
||||
UNVERIFIED
|
||||
VERIFIED
|
||||
ENABLED
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user