diff --git a/src/routes/auth.ts b/src/routes/auth.ts index 183448c..344acb9 100644 --- a/src/routes/auth.ts +++ b/src/routes/auth.ts @@ -66,6 +66,7 @@ route.post("/register", async (req: any, res, next) => { verified: false, }, }); + log({ ...req, user }, "UPDATE", `Credentials updated for user ${user.id}`); } else { user = await prisma.user.create({ data: { @@ -74,7 +75,7 @@ route.post("/register", async (req: any, res, next) => { password: hashedPassword, }, }); - log({ ...req, user }, "CREATE", "User registered"); + log({ ...req, user }, "CREATE", `New user ${user.id}, '${user.name}' registered`); } } catch (exception) { console.error(exception); @@ -87,7 +88,7 @@ route.post("/register", async (req: any, res, next) => { data: { type: "EMAIL_VERIFICATION", userId: user.id }, }); log({ ...req, user }, "CREATE", "Email verification token created"); - const verificationLink = `${process.env.API_BASE_URL}/auth/verify?token=${verificationToken.id}&userId=${user.id}`; + const verificationLink = `${process.env.API_BASE_URL}/auth/verify?token=${verificationToken.id}&userId=${user.email}`; try { // Send mail to user with verification token await mail({ @@ -99,6 +100,7 @@ route.post("/register", async (req: any, res, next) => { ${verificationLink}

`, }); + log({ ...req, user }, "CREATE", `Verification email sent to ${user.id}`); } catch (err) { respond(res, req, 500, "There was an error sending the email"); return; diff --git a/src/routes/buy.ts b/src/routes/buy.ts index fafea3f..1be985e 100644 --- a/src/routes/buy.ts +++ b/src/routes/buy.ts @@ -12,54 +12,6 @@ import { respond } from "src/lib/request-respond"; import prisma from "src/prisma"; const route = express(); -route.post( - "/product/:productId", - isUser, - isNotDeleted, - isNotBanned, - isUserVerified, - isBuyer, - async (req: any, res, next) => { - const { productId } = req.params; - try { - const product = await prisma.product.findUnique({ - where: { id: productId }, - select:{ - id: true, - banned: true, - seller:{ - select:{ - id: true, - user:{ - select:{ - id: true, - banned: true, - deleted: true, - } - } - } - } - } - }) - if(product && (product.banned || product.seller.user.banned || product.seller.user.deleted)){ - respond(res,res,400,ERROR.BAD_REQUEST); - return; - } - const order = await prisma.orders.create({ - data: { - buyerId: req.user.buyerProfile.id, - productId: productId, - }, - }); - log(req, "CREATE", `Order created for product ${productId}`); - respond(res, req, 200, "success", order); - } catch (err) { - console.error(err); - respond(res, req, 500, ERROR.INTERNAL_ERROR); - return; - } - } -); route.get( "/orders", diff --git a/src/routes/payment.ts b/src/routes/payment.ts index 931d474..3d167fc 100644 --- a/src/routes/payment.ts +++ b/src/routes/payment.ts @@ -69,7 +69,7 @@ route.post( quantity: 1, }, }); - log(req, "CREATE", `Order created for product ${productId}`); + log(req, "CREATE", `Order ${order.id} created for product ${productId}`); const body = { amount: product.price * 100, //razorpay processess amount in Paise @@ -117,7 +117,7 @@ route.get( isUserVerified, isNotBanned, isBuyer, - async (req, res, next) => { + async (req: any, res, next) => { const querySchema = Joi.string() .trim() .required() @@ -152,6 +152,9 @@ route.get( where: { id: value.orderId }, data: { status: true }, }); + + log(req, "CREATE", `Payment recorded for order ${value.orderId}`); + respond(res, req, 200, "Payment Successful", { status: true }); return; } catch (exception) { diff --git a/src/routes/products.ts b/src/routes/products.ts index fbf5d33..a458de7 100644 --- a/src/routes/products.ts +++ b/src/routes/products.ts @@ -162,7 +162,7 @@ route.post( }, }); - log(req, "CREATE", `Product ${product.id} created`); + log(req, "CREATE", `New product ${product.id} '${product.name}' added to marketplace`); respond(res, req, 200, "success", product); } catch (err) { console.error(err); @@ -255,7 +255,7 @@ route.post( isNotDeleted, isNotBanned, isAdmin, - async (req, res, next) => { + async (req: any, res, next) => { try { const product = await prisma.product.update({ where: { @@ -265,6 +265,8 @@ route.post( banned: true, }, }); + + log(req, "UPDATE", `Product ${req.params.productId} banned`); respond(res, req, 200, "success", product); } catch (err) { console.error(err); @@ -280,7 +282,7 @@ route.post( isNotDeleted, isNotBanned, isAdmin, - async (req, res, next) => { + async (req: any, res, next) => { try { const product = await prisma.product.update({ where: { @@ -290,6 +292,7 @@ route.post( banned: false, }, }); + log(req, "UPDATE", `Product ${req.params.productId} unbanned`); respond(res, req, 200, "success", product); } catch (err) { console.error(err); @@ -365,7 +368,7 @@ route.patch( }, }); - log(req, "UPDATE", `Product ${product.id} updated`); + log(req, "UPDATE", `Details of product ${product.id} updated`); respond(res, req, 200, "success", product); } catch (err) { console.error(err); diff --git a/src/routes/sell.ts b/src/routes/sell.ts index c9e2a2c..c16130f 100644 --- a/src/routes/sell.ts +++ b/src/routes/sell.ts @@ -64,7 +64,7 @@ route.post( approvalDocument: req.file.filename, }, }); - log(req, "CREATE", "Seller profile created with proposal"); + log(req, "CREATE", `Seller ${req.user.id} '${req.user.name}' profile created with proposal`); respond(res, req, 200, "success"); } catch (err) { respond(res, req, 500, INTERNAL_ERROR); diff --git a/src/routes/user.ts b/src/routes/user.ts index fd64701..ba6591c 100644 --- a/src/routes/user.ts +++ b/src/routes/user.ts @@ -265,6 +265,8 @@ route.post( where: { id: userId }, data: { banned: true }, }); + + log(req, "UPDATE", `User ${userId} banned`) respond(res, req, 200, "Success"); } catch (error) { // Record not found @@ -283,13 +285,15 @@ route.post( isNotDeleted, isNotBanned, isAdmin, - async (req, res, next) => { + async (req: any, res, next) => { try { const { userId } = req.params; await prisma.user.update({ where: { id: userId }, data: { banned: false }, }); + + log(req, "UPDATE", `User ${userId} unbanned`); respond(res, req, 200, "Success"); } catch (error) { // Record not found