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