Skip to content

Commit 9007a95

Browse files
committed
chore: lint, format, and ensure app runs in Docker
1 parent 0fb7cf7 commit 9007a95

File tree

10 files changed

+223
-522
lines changed

10 files changed

+223
-522
lines changed

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: yarn test
4343

4444
- name: Build Docker image
45-
run: docker build -t maebrie2017/clean-code-arch-rest-api:latest .
45+
run: docker build -t maebrie2017/clean-arch-app:latest .
4646

4747
- name: Log in to Docker Hub
4848
uses: docker/login-action@v3
@@ -52,7 +52,7 @@ jobs:
5252

5353
- name: Push Docker image
5454
run: |
55-
IMAGE=maebrie2017/clean-code-arch-rest-api
55+
IMAGE=maebrie2017/clean-arch-app
5656
docker tag $IMAGE:latest $IMAGE:${{ github.sha }}
5757
docker push $IMAGE:latest
5858
docker push $IMAGE:${{ github.sha }}

docker-compose.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ services:
44
build: .
55
container_name: clean-arch-app
66
ports:
7-
- '5000:5000'
7+
- '5001:5000' # Change 5001 to any free port
88
environment:
99
- PORT=5000
10-
- MONGODB_URI=mongodb://mongo:27017/cleanarchdb
11-
- JWT_SECRET=your_jwt_secret
10+
- MONGODB_URI=${MONGODB_URI}
11+
- JWT_SECRET=${JWT_SECRET}
1212
depends_on:
1313
- mongo
1414
restart: unless-stopped
15+
1516
mongo:
1617
image: mongo:6.0
1718
container_name: clean-arch-mongo

enterprise-business-rules/validate-models/product-validation-fcts.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,28 @@ function validateColors(colors, InvalidPropertyError) {
7272
}
7373

7474
// constructs an enumeration of brands
75-
function validateBrands(brands, InvalidPropertyError) {
76-
console.log('brand: ', brands);
77-
if (!Array.isArray(brands)) {
78-
return [brands];
79-
}
80-
81-
const validbrands = new Set([
82-
'Apple',
83-
'Samsung',
84-
'Microsoft',
85-
'Lenovo',
86-
'Acer',
87-
'Asus',
88-
'HP',
89-
'Dell',
90-
]);
91-
if (brands.length === 0 || !brands.some((color) => validbrands.has(color))) {
92-
throw new InvalidPropertyError(`A product must have at least one color.`);
93-
}
94-
95-
return [...new Set(brands)];
96-
}
75+
// function validateBrands(brands, InvalidPropertyError) {
76+
// console.log('brand: ', brands);
77+
// if (!Array.isArray(brands)) {
78+
// return [brands];
79+
// }
80+
81+
// const validbrands = new Set([
82+
// 'Apple',
83+
// 'Samsung',
84+
// 'Microsoft',
85+
// 'Lenovo',
86+
// 'Acer',
87+
// 'Asus',
88+
// 'HP',
89+
// 'Dell',
90+
// ]);
91+
// if (brands.length === 0 || !brands.some((color) => validbrands.has(color))) {
92+
// throw new InvalidPropertyError(`A product must have at least one color.`);
93+
// }
94+
95+
// return [...new Set(brands)];
96+
// }
9797

9898
//validate and normalize product rating: rating is an array of refences to users in the users collection
9999
// function validateRating(rating, InvalidPropertyError) {

enterprise-business-rules/validate-models/user-validation-functions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55

66
// TODO: remove this external data storage and package here and from here.
77
// We don't respect the clean code architecture with this
8-
const bcrypt = require('bcrypt');
8+
const bcrypt = require('bcryptjs');
99
const { ObjectId } = require('mongodb');
1010

1111
/**

interface-adapters/controllers/users/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const userUseCaseHandlers = require('../../../application-business-rules/use-cas
33

44
const { makeHttpError } = require('../../validators-errors/http-error');
55
const { logEvents } = require('../../middlewares/loggers/logger');
6-
const bcrypt = require('bcrypt');
6+
const bcrypt = require('bcryptjs');
77
const jwt = require('jsonwebtoken');
88
const sendEmail = require('../../adapter/email-sending');
99

interface-adapters/database-access/db-connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
dbconnection: async () => {
1111
// The MongoClient is the object that references the connection to our
1212
// datastore (Atlas, for example)
13-
const client = new MongoClient(process.env.DB_URI);
13+
const client = new MongoClient(process.env.MONGODB_URI);
1414

1515
// The connect() method does not attempt a connection; instead it instructs
1616
// the driver to connect using the settings provided when a connection

interface-adapters/database-access/db-indexes.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ module.exports = async function setupDb() {
66
console.log('Setting up database indexes...');
77
const db = await dbconnection();
88

9-
const allProductsIndexName = await db.collection('products').listIndexes().toArray();
9+
// PRODUCTS
10+
let allProductsIndexName = [];
11+
try {
12+
allProductsIndexName = await db.collection('products').listIndexes().toArray();
13+
} catch (err) {
14+
if (err.codeName === 'NamespaceNotFound') {
15+
await db.collection('products').insertOne({ __seed: true });
16+
await db.collection('products').deleteOne({ __seed: true });
17+
allProductsIndexName = [];
18+
} else {
19+
throw err;
20+
}
21+
}
1022

1123
let indexArr = [];
12-
// create indexes only if not exist
1324
allProductsIndexName.forEach((element) => {
1425
if (element.name === 'productTextIndex' || element.name === 'productUniqueIndex') {
1526
return;
@@ -37,7 +48,19 @@ module.exports = async function setupDb() {
3748
];
3849
});
3950

40-
const allUsersIndexName = await db.collection('users').listIndexes().toArray();
51+
// USERS
52+
let allUsersIndexName = [];
53+
try {
54+
allUsersIndexName = await db.collection('users').listIndexes().toArray();
55+
} catch (err) {
56+
if (err.codeName === 'NamespaceNotFound') {
57+
await db.collection('users').insertOne({ __seed: true });
58+
await db.collection('users').deleteOne({ __seed: true });
59+
allUsersIndexName = [];
60+
} else {
61+
throw err;
62+
}
63+
}
4164
allUsersIndexName.forEach((element) => {
4265
if (element.name === 'userUniqueIndex') {
4366
return;
@@ -50,7 +73,19 @@ module.exports = async function setupDb() {
5073
];
5174
});
5275

53-
const allRatingsIndexName = await db.collection('ratings').listIndexes().toArray();
76+
// RATINGS
77+
let allRatingsIndexName = [];
78+
try {
79+
allRatingsIndexName = await db.collection('ratings').listIndexes().toArray();
80+
} catch (err) {
81+
if (err.codeName === 'NamespaceNotFound') {
82+
await db.collection('ratings').insertOne({ __seed: true });
83+
await db.collection('ratings').deleteOne({ __seed: true });
84+
allRatingsIndexName = [];
85+
} else {
86+
throw err;
87+
}
88+
}
5489
allRatingsIndexName.forEach((element) => {
5590
if (element.name === 'ratingsUniqueIndex') {
5691
// db.collection('ratings').dropIndex('ratingsUniqueIndex');

interface-adapters/database-access/store-product.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ const updatedProduct = async ({ productId, dbconnection, logEvents, ...productDa
196196
}
197197
};
198198

199-
// create a raiting document and update product document alongside
199+
// create a rating document and update product document alongside
200+
// we are creating transaction session to ensure data consistency
200201

201202
const rateProduct = async ({ logEvents, ...ratingModel }) => {
202-
const client = new MongoClient(process.env.DB_URI);
203+
const client = new MongoClient(process.env.MONGODB_URI);
203204
const session = client.startSession();
204205

205206
/* start a transaction session */

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
"author": {
88
"name": "avom brice ",
99
"address": "frckbrice <bricefrkc@gmail,com> (https://maebrie.vercel.app)",
10-
"date": "jun 12 2024"
10+
"date": "jun 12 2024",
11+
"update": "jul 22 2025"
1112
},
1213
"scripts": {
1314
"start": "node index.js",
1415
"dev": "nodemon index.js",
1516
"lint": "eslint . --ext .js",
1617
"format": "prettier --write .",
1718
"prepare": "husky install",
18-
"test": "jest --runInBand"
19+
"test": "jest --runInBand",
20+
"build": "tsc --noEmitOnError"
1921
},
2022
"dependencies": {
21-
"bcrypt": "^5.1.1",
23+
"bcryptjs": "^3.0.2",
2224
"cors": "^2.8.5",
2325
"cuid": "^3.0.0",
2426
"date-fns": "^3.6.0",

0 commit comments

Comments
 (0)