diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3bb20cd..a090925 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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 -} \ No newline at end of file +} diff --git a/src/controller/auth.controller.ts b/src/controller/auth.controller.ts index baa636f..75ea9a6 100644 --- a/src/controller/auth.controller.ts +++ b/src/controller/auth.controller.ts @@ -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: { diff --git a/src/controller/orders.controller.ts b/src/controller/orders.controller.ts index 12b4a39..b096bd6 100644 --- a/src/controller/orders.controller.ts +++ b/src/controller/orders.controller.ts @@ -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); }; diff --git a/src/lib/mail.ts b/src/lib/mail.ts index 0a3d5c1..470113b 100644 --- a/src/lib/mail.ts +++ b/src/lib/mail.ts @@ -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: "m3v2a6gnc4dunaxu@ethereal.email", + 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);