Skip to content

Commit

Permalink
Merge branch 'main' into temp
Browse files Browse the repository at this point in the history
  • Loading branch information
thesantatitan authored Nov 10, 2021
2 parents 3c24504 + 238ee5d commit 417db39
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ model Buyer {
model Product {
id String @id @default(uuid())
name String
description String
description String @db.VarChar(1028)
price Int
sellerId String
categoryId String
Expand Down
8 changes: 8 additions & 0 deletions src/lib/validators/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export default async function validate(req, res, next) {
return;
}

if(user.banned){
await prisma.session.delete({ where: { sid: req.sessionID } });
req.session.destroy(() => {
respond(res, req, 400, ERROR.ACCOUNT_BANNED, undefined);
});
return;
}

req.session.lastActive = currentTime;
req.user = user;

Expand Down
29 changes: 29 additions & 0 deletions src/routes/buy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { respond } from "src/lib/request-respond";
import prisma from "src/prisma";
const route = express();


route.get(
"/orders",
isUser,
Expand All @@ -23,6 +24,34 @@ route.get(
try {
const orders = await prisma.orders.findMany({
where: { buyer: { userId: req.user.id } },
select: {
id: true,
status: true,
time: true,
quantity: true,
buyer: {
select: {
id: true,
},
},
product: {
select: {
id: true,
name: true,
price: true,
seller: {
select: {
id: true,
user: {
select: {
name: true,
},
},
},
},
},
},
},
});
respond(res, req, 200, "success", orders);
} catch (err) {
Expand Down
3 changes: 0 additions & 3 deletions src/routes/buyers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ route.get(
where: {
user: {
deleted: false,
adminProfile: {
is: null,
},
},
},
select: {
Expand Down
12 changes: 12 additions & 0 deletions src/routes/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ route.post(
try {
const product = await prisma.product.findUnique({
where: { id: productId },
include:{
seller: {
include: {
user: true
}
}
}
});
if (!product) {
respond(res, req, 404, ERROR.PRODUCT_NOT_FOUND);
return;
}

if(product && product.seller.user.banned || product.seller.user.deleted || product.banned){
respond(res, req, 404, ERROR.PRODUCT_NOT_FOUND);
return;
}

const order = await prisma.orders.create({
data: {
buyerId: req.user.buyerProfile.id,
Expand Down
7 changes: 6 additions & 1 deletion src/routes/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const route = express();

const productSchema = Joi.object({
name: Joi.string().trim().max(28).required(),
description: Joi.string().trim().max(124).required(),
description: Joi.string().trim().max(1024).required(),
price: Joi.number().positive().max(15000).min(1).required(),
category: Joi.string().trim().required(),
});
Expand Down Expand Up @@ -322,6 +322,11 @@ route.get("/:productId", async (req, res, next) => {
},
});

if (!product) {
respond(res, req, 404, "Product not found.", null);
return;
}

convertImagePath(product);
respond(res, req, 200, "success", product);
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "commonjs",
"module": "CommonJS",
"moduleResolution": "node",
"noEmit": false,
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true,
"sourceMap": false,
"target": "es6",
"baseUrl": ".",
"rootDir": "./src",
Expand Down

0 comments on commit 417db39

Please sign in to comment.