diff --git a/README.md b/README.md index ec0ad70..a4c4787 100644 --- a/README.md +++ b/README.md @@ -409,9 +409,15 @@ kubectl delete all --all --namespace default **Option 1: Running on localhost** -Before you start the installation, ensure that you have `.env` files setup inside all the microservices. +1. Clone the MartianBank GitHub repository and navigate to the downloaded directory. +```bash +git clone https://github.com/cisco-open/martian-bank-demo.git +cd bankapp +``` + +2. Before you start the installation, ensure that you have `.env` files setup inside all the microservices. You need to create a `.env` file under these folders: `./customer-auth`, `./atm-locator`, `./dashboard`, `./accounts`, `./loan`, `./transactions`. -1. To run all the microservices and UI: +3. To run all the microservices and UI: ```bash cd scripts bash run_local.sh @@ -419,7 +425,7 @@ bash run_local.sh Fire up `http://localhost:3000` to access the Martian Bank App. -2. To stop all the microservices: +4. To stop all the microservices: ```bash cd scripts bash stop_local.sh diff --git a/atm-locator/config/db.js b/atm-locator/config/db.js index 584db26..4fe3de7 100644 --- a/atm-locator/config/db.js +++ b/atm-locator/config/db.js @@ -24,33 +24,6 @@ const connectDB = async () => { const conn = await mongoose.connect( `mongodb://${process.env.DATABASE_HOST}:27017/` ); - - console.log(`Seeding database with data from atm_data.json ...`); - - const atmDataFile = join( - dirname(fileURLToPath(import.meta.url)), - "atm_data.json" - ); - const rawData = fs.readFileSync(atmDataFile); - const jsonData = JSON.parse(rawData); - const processedData = jsonData.map((item) => ({ - ...item, - _id: new mongoose.Types.ObjectId(item._id.$oid), - createdAt: new Date(item.createdAt.$date), - updatedAt: new Date(item.updatedAt.$date), - })); - try { - try { - await ATM.collection.drop(); - } - catch (error) { - console.log(`Error: ${error.message}`.red.bold); - } - await ATM.insertMany(processedData); - console.log(`Database seeded with ${processedData.length} records.`); - } catch (error) { - console.log(`Error: ${error.message}`.red.bold); - } } else { console.log( `Connecting to MongoDB Atlas (Cloud) at ${process.env.DB_URL} ...` @@ -63,6 +36,32 @@ const connectDB = async () => { console.error(`Error: ${error.message}`.red.bold); process.exit(1); } + + console.log(`Seeding database with data from atm_data.json ...`); + + const atmDataFile = join( + dirname(fileURLToPath(import.meta.url)), + "atm_data.json" + ); + const rawData = fs.readFileSync(atmDataFile); + const jsonData = JSON.parse(rawData); + const processedData = jsonData.map((item) => ({ + ...item, + _id: new mongoose.Types.ObjectId(item._id.$oid), + createdAt: new Date(item.createdAt.$date), + updatedAt: new Date(item.updatedAt.$date), + })); + try { + try { + await ATM.collection.drop(); + } catch (error) { + console.log(`Error: ${error.message}`.red.bold); + } + await ATM.insertMany(processedData); + console.log(`Database seeded with ${processedData.length} records.`); + } catch (error) { + console.log(`Error: ${error.message}`.red.bold); + } }; export default connectDB;