Skip to content

Commit

Permalink
Merge pull request #27 from ecstacy-fcs/temp
Browse files Browse the repository at this point in the history
Add missing log commands
  • Loading branch information
thesantatitan authored Nov 10, 2021
2 parents 238ee5d + 417db39 commit f329d16
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 58 deletions.
6 changes: 4 additions & 2 deletions src/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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);
Expand All @@ -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({
Expand All @@ -99,6 +100,7 @@ route.post("/register", async (req: any, res, next) => {
<code>${verificationLink}</code>
</p>`,
});
log({ ...req, user }, "CREATE", `Verification email sent to ${user.id}`);
} catch (err) {
respond(res, req, 500, "There was an error sending the email");
return;
Expand Down
48 changes: 0 additions & 48 deletions src/routes/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/routes/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,7 +117,7 @@ route.get(
isUserVerified,
isNotBanned,
isBuyer,
async (req, res, next) => {
async (req: any, res, next) => {
const querySchema = Joi.string()
.trim()
.required()
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions src/routes/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: {
Expand All @@ -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);
Expand All @@ -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: {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f329d16

Please sign in to comment.