Skip to content

Commit

Permalink
Merge branch 'fix-google-auth' of https://github.com/atlp-rwanda/knig…
Browse files Browse the repository at this point in the history
…hts-ecomm-be into fix-google-auth
  • Loading branch information
maxCastro1 committed Jun 24, 2024
2 parents 3291418 + 3555b41 commit 2c9de8f
Show file tree
Hide file tree
Showing 10 changed files with 4,928 additions and 3,679 deletions.
8,571 changes: 4,902 additions & 3,669 deletions model.nlp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/controllers/productController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
searchProductService,
listAllProductsService,
confirmPayment,
getAllCategories
} from '../services';

export const readProduct = async (req: Request, res: Response) => {
Expand Down Expand Up @@ -57,4 +58,7 @@ export const searchProduct = async (req: Request, res: Response) => {
};
export const Payment = async (req: Request, res: Response) => {
await confirmPayment(req, res);
};
export const getAllCategory = async (req: Request, res: Response) => {
await getAllCategories(req, res);
};
4 changes: 4 additions & 0 deletions src/routes/ProductRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
getBuyerVendorOrders,
getSingleBuyerVendorOrder,
updateBuyerVendorOrder,
getAllCategory
} from '../controllers';
const router = Router();

Expand All @@ -33,6 +34,7 @@ router.get('/all', listAllProducts);
router.get('/recommended', authMiddleware as RequestHandler, hasRole('BUYER'), getRecommendedProducts);
router.get('/collection', authMiddleware as RequestHandler, hasRole('VENDOR'), readProducts);
router.get('/', authMiddleware as RequestHandler, hasRole('BUYER'), readProducts);
router.get('/categories', getAllCategory);
router.get('/:id', singleProduct);
router.get('/collection/:id', authMiddleware as RequestHandler, hasRole('VENDOR'), readProduct);
router.post('/', authMiddleware as RequestHandler, hasRole('VENDOR'), upload.array('images', 10), createProduct);
Expand All @@ -59,4 +61,6 @@ router.put('/admin/orders/:id', authMiddleware as RequestHandler, hasRole('ADMIN
router.post('/payment/:id', authMiddleware as RequestHandler, hasRole('BUYER'), Payment);




export default router;
3 changes: 2 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './productServices/productStatus';
export * from './productServices/viewSingleProduct';
export * from './productServices/searchProduct';
export * from './productServices/payment';
export * from './productServices/getCategories';

// Buyer wishlist services
export * from './wishListServices/addProduct';
Expand Down Expand Up @@ -49,4 +50,4 @@ export * from './notificationServices/deleteNotification';
export * from './notificationServices/updateNotification';

// chatbot
export * from './chatbotServices/chatBot';
export * from './chatbotServices/chatBot';
15 changes: 15 additions & 0 deletions src/services/productServices/getCategories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Request, Response } from 'express';
import { getRepository } from 'typeorm';
import { Category } from '../../entities/Category';

export const getAllCategories = async (req: Request, res: Response) => {
try {
const categoryRepository = getRepository(Category);
const categories = await categoryRepository.find();

res.status(200).json({ status: 'success', categories });
} catch (error) {
console.error('Error fetching categories:', error);
res.status(500).json({ status: 'error', message: 'Error fetching categories' });
}
};
1 change: 0 additions & 1 deletion src/services/productServices/productStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const productStatusServices = async (req: Request, res: Response) => {
const { id } = req.params;

if (isAvailable === undefined) {
console.log('Error: Please fill all the required fields');
return responseError(res, 400, 'Please fill all t he required fields');
}

Expand Down
1 change: 0 additions & 1 deletion src/services/productServices/searchProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const searchProductService = async (req: Request, res: Response) => {
const { name, sortBy, sortOrder, page = 1, limit = 10 }: SearchProductParams = req.query as any;
try {
if (!name) {
console.log("no name");
return res.status(400).json({ status: 'error', error: 'Please provide a search term' });
}

Expand Down
4 changes: 0 additions & 4 deletions src/services/productServices/viewSingleProduct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export const viewSingleProduct = async (req: Request, res: Response) => {
if (!product) {
return res.status(404).send({ status: 'error', message: 'Product not found' });
}

if (product.expirationDate && new Date(product.expirationDate) < new Date()) {
return res.status(400).json({ status: 'error', message: 'Product expired' });
}
res.status(200).json({ status: 'success', product: product });
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/userServices/sendResetPasswordLinkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const sendPasswordResetLinkService = async (req: Request, res: Response)
password has been generated for you. To reset your password, click the
following link and follow the instructions.
</p>
<a href="${process.env.FRONTEND_URL}/${process.env.PASSWORD_ROUTE}?userid=${existingUser.id}&email=${existingUser.email}" target="_blank"
<a href="${process.env.CLIENT_URL}/reset-password?userid=${existingUser.id}&email=${existingUser.email}" target="_blank"
style="background:#20e277;text-decoration:none !important; font-weight:500; margin-top:35px; color:#fff;text-transform:uppercase; font-size:14px;padding:10px 24px;display:inline-block;border-radius:50px;">Reset
Password</a>
</td>
Expand Down
2 changes: 0 additions & 2 deletions src/services/userServices/userResendOTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ export const userResendOtpService = async (req: Request, res: Response) => {
const { email } = req.body;

if (!email) {
console.log('No email address provided');
return res.status(400).json({ status: 'error', message: 'Please provide an email' });
}

const userRepository = getRepository(User);
const user = await userRepository.findOneBy({ email });

if (!user) {
console.log('User not found');
return res.status(404).json({ status: 'error', message: 'Incorrect email' });
}

Expand Down

0 comments on commit 2c9de8f

Please sign in to comment.