Skip to content

Commit e54923a

Browse files
committed
chore: sync recent changes - docs, env example, handlers, validation, routes, and UI
1 parent 97ac116 commit e54923a

38 files changed

Lines changed: 1104 additions & 543 deletions

.env.example

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Server
2+
PORT=5000
3+
NODE_ENV=development
4+
5+
# MongoDB (use MONGO_URI or MONGODB_URI for rate-product transaction)
6+
MONGO_URI=mongodb://localhost:27017/your-db
7+
MONGO_DB_NAME=digital-market-place-updates
8+
9+
# JWT
10+
ACCESS_TOKEN_SECRETKEY=your_access_token_secret
11+
JWT_REFRESH_SECRET=your_refresh_token_secret
12+
JWT_EXPIRES_IN=15m
13+
JWT_REFRESH_EXPIRES_IN=7d
14+
15+
# Email (for password reset)
16+
MY_EMAIL=your-email@gmail.com
17+
PASSWORD=your-app-password
18+
19+
# CORS: add allowed origins in interface-adapters/middlewares/config/allowedOrigin.js

.eslintrc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
],
1313
"rules": {
1414
"prettier/prettier": "error",
15-
"indent": [
16-
"error",
17-
2
18-
],
15+
"indent": "off",
1916
"no-unused-vars": "warn",
2017
"no-console": "off"
2118
}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
.env
3-
3+
*.log
4+
logs/
45
/interface-adapters/middlewares/logs/
56
/interface-adapters/controllers/examples

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env sh
22
. "$(dirname -- "$0")/_/husky.sh"
33

4-
yarn lint && yarn format
4+
yarn lint && yarn format && yarn test

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ public/ # Static files and HTML views
7070
```bash
7171
yarn install
7272
```
73-
3. Create a `.env` file in the root with your environment variables:
74-
```env
75-
PORT=5000
76-
MONGO_URI=mongodb://localhost:27017/your-db
77-
JWT_SECRET=your_jwt_secret
78-
```
73+
3. Copy `.env.example` to `.env` and set your environment variables. For production, set `NODE_ENV=production` (logging is disabled in production; file and console logs run only in development).
7974
4. Start the server:
8075
```bash
8176
yarn dev
@@ -147,7 +142,7 @@ See the `routes/` directory for all endpoints. Example:
147142

148143
## Troubleshooting
149144

150-
- See [troubleshooting.md](./troubleshooting.md) for common issues and solutions.
145+
- See [troubleshooting.md](./docs/troubleshooting.md) for common issues and solutions.
151146

152147
## License
153148

application-business-rules/use-cases/blogs/blog-handlers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module.exports = {
1616
async function findAllBlogsUseCaseHandler() {
1717
try {
1818
const blogs = await dbBlogHandler.findAllBlogs();
19-
// console.log('\n\n from find all blogs use case: ', blogs);
2019
return Object.freeze(blogs.flat().data);
2120
} catch (error) {
2221
logEvents && logEvents(error.message, 'blogUseCase.log');

application-business-rules/use-cases/products/product-handlers.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
'use strict';
2+
13
const productValidationFcts = require('../../../enterprise-business-rules/validate-models/product-validation-fcts');
2-
// const { findAllProductUseCaseHandler } = require('./product-handlers');
4+
const { log } = require('../../../interface-adapters/middlewares/loggers/logger');
35

46
/**
57
* Creates a new product in the database using the provided product data.
@@ -24,12 +26,14 @@ const createProductUseCase = ({ makeProductModelHandler }) =>
2426
const newProduct = await createProductDbHandler(validatedProductData);
2527
return Object.freeze(newProduct);
2628
} catch (error) {
27-
console.log('Error from create product handler: ', error);
29+
log.error('Error from create product handler:', error.message);
2830
throw new Error(error.message);
2931
}
3032
};
3133

32-
//find one product from DB
34+
/**
35+
* Fetches a single product by ID.
36+
*/
3337
const findOneProductUseCase = ({ productValidation }) =>
3438
async function findOneProductUseCaseHandler({
3539
productId,
@@ -44,25 +48,28 @@ const findOneProductUseCase = ({ productValidation }) =>
4448
const newProduct = await findOneProductDbHandler({ productId: uuid });
4549
return Object.freeze(newProduct);
4650
} catch (error) {
47-
console.log('Error from fetch one product handler: ', error);
51+
log.error('Error from fetch one product handler:', error.message);
4852
throw new Error(error.message);
4953
}
5054
};
5155

52-
// find all product use case handler
56+
/**
57+
* Fetches all products with optional filters.
58+
*/
5359
const findAllProductsUseCase = () =>
5460
async function findAllProductUseCaseHandler({ dbProductHandler, filterOptions }) {
5561
try {
5662
const allProducts = await dbProductHandler.findAllProductsDbHandler(filterOptions);
57-
// console.log('from find all products use case: ', allProducts);
5863
return Object.freeze(allProducts.data);
5964
} catch (e) {
60-
console.log('Error from fetch all product handler: ', e);
65+
log.error('Error from fetch all product handler:', e.message);
6166
throw new Error(e.message);
6267
}
6368
};
6469

65-
// delete product use case
70+
/**
71+
* Deletes a product by ID.
72+
*/
6673
const deleteProductUseCase = () =>
6774
async function deleteProductUseCaseHandler({ productId, dbProductHandler, errorHandlers }) {
6875
const { findOneProductDbHandler, deleteProductDbHandler } = dbProductHandler;
@@ -83,12 +90,14 @@ const deleteProductUseCase = () =>
8390
};
8491
return Object.freeze(result);
8592
} catch (error) {
86-
console.log('Error from delete product handler: ', error);
93+
log.error('Error from delete product handler:', error.message);
8794
throw new Error(error.message);
8895
}
8996
};
9097

91-
// update product
98+
/**
99+
* Updates a product by ID.
100+
*/
92101
const updateProductUseCase = ({ makeProductModelHandler }) =>
93102
async function updateProductUseCaseHandler({
94103
productId,
@@ -113,17 +122,17 @@ const updateProductUseCase = ({ makeProductModelHandler }) =>
113122
errorHandlers,
114123
});
115124

116-
// store product in database mongodb
117125
const newProduct = await updateProductDbHandler({ productId, ...productData });
118-
console.log(' from product handler after DB: ', newProduct);
119126
return Object.freeze(newProduct);
120127
} catch (error) {
121-
console.log('Error from update product handler: ', error);
128+
log.error('Error from update product handler:', error.message);
122129
throw new Error(error.message);
123130
}
124131
};
125132

126-
// rate product in transaction with both Rate model and Product model
133+
/**
134+
* Rates a product (creates rating and updates product aggregates in a transaction).
135+
*/
127136
const rateProductUseCase = ({ makeProductRatingModelHandler }) =>
128137
async function rateProductUseCaseHandler({
129138
userId,
@@ -132,16 +141,13 @@ const rateProductUseCase = ({ makeProductRatingModelHandler }) =>
132141
dbProductHandler,
133142
errorHandlers,
134143
}) {
135-
console.log('hit rating use case handler');
136144
const ratingData = { ratingValue, userId, productId };
137145
try {
138-
/* validate and build rating model */
139146
const ratingModel = await makeProductRatingModelHandler({ errorHandlers, ...ratingData });
140147
const newProduct = await dbProductHandler.rateProductDbHandler(ratingModel);
141-
console.log(' from rating product handler after DB: ', newProduct);
142148
return Object.freeze(newProduct);
143149
} catch (error) {
144-
console.log('Error from fetch one product handler: ', error);
150+
log.error('Error from rating product handler:', error.message);
145151
throw new Error(error.message);
146152
}
147153
};

application-business-rules/use-cases/user/index.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const profileUseCases = require('./user-profile-usecases');
33
const { dbUserHandler } = require('../../../interface-adapters/database-access');
44
const { makeUser, validateId } = require('../../../enterprise-business-rules/entities');
55
const { RequiredParameterError } = require('../../../interface-adapters/validators-errors/errors');
6-
const { logEvents } = require('../../../interface-adapters/middlewares/loggers/logger');
6+
const { logEvents, log } = require('../../../interface-adapters/middlewares/loggers/logger');
77
const { makeHttpError } = require('../../../interface-adapters/validators-errors/http-error');
88

99
const entityModels = require('../../../enterprise-business-rules/entities');
@@ -13,30 +13,34 @@ const registerUserUseCaseHandler = authUseCases.registerUserUseCase({
1313
dbUserHandler,
1414
entityModels,
1515
logEvents,
16+
log,
1617
makeHttpError,
1718
});
1819
const loginUserUseCaseHandler = authUseCases.loginUserUseCase({
1920
dbUserHandler,
2021
logEvents,
22+
log,
2123
makeHttpError,
2224
});
23-
const logoutUseCaseHandler = authUseCases.logoutUseCase({ RequiredParameterError, logEvents });
25+
const logoutUseCaseHandler = authUseCases.logoutUseCase({ RequiredParameterError, logEvents, log });
2426
const refreshTokenUseCaseHandler = authUseCases.refreshTokenUseCase({
2527
dbUserHandler,
2628
RequiredParameterError,
2729
logEvents,
30+
log,
2831
});
2932
const forgotPasswordUseCaseHandler = authUseCases.forgotPasswordUseCase({
3033
dbUserHandler,
3134
logEvents,
35+
log,
3236
});
3337
const resetPasswordUseCaseHandler = authUseCases.resetPasswordUseCase({
3438
dbUserHandler,
3539
logEvents,
40+
log,
3641
makeHttpError,
3742
});
3843

39-
// Profile Use Cases
4044
const findAllUsersUseCaseHandler = profileUseCases.findAllUsersUseCase({
4145
dbUserHandler,
4246
logEvents,
@@ -45,32 +49,37 @@ const findOneUserUseCaseHandler = profileUseCases.findOneUserUseCase({
4549
dbUserHandler,
4650
validateId,
4751
logEvents,
52+
log,
4853
});
4954
const updateUserUseCaseHandler = profileUseCases.updateUserUseCase({
5055
dbUserHandler,
5156
makeUser,
5257
validateId,
5358
RequiredParameterError,
5459
logEvents,
60+
log,
5561
makeHttpError,
5662
});
5763
const deleteUserUseCaseHandler = profileUseCases.deleteUserUseCase({
5864
dbUserHandler,
5965
validateId,
6066
RequiredParameterError,
6167
logEvents,
68+
log,
6269
});
6370
const blockUserUseCaseHandler = profileUseCases.blockUserUseCase({
6471
dbUserHandler,
6572
validateId,
6673
RequiredParameterError,
6774
logEvents,
75+
log,
6876
});
6977
const unBlockUserUseCaseHandler = profileUseCases.unBlockUserUseCase({
7078
dbUserHandler,
7179
validateId,
7280
RequiredParameterError,
7381
logEvents,
82+
log,
7483
});
7584

7685
module.exports = {

0 commit comments

Comments
 (0)