Skip to content

Commit

Permalink
atm locator will populate db for atlas too
Browse files Browse the repository at this point in the history
  • Loading branch information
jashmehta3300 committed Aug 11, 2023
1 parent 21aab42 commit 882915c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,23 @@ 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
```

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
Expand Down
53 changes: 26 additions & 27 deletions atm-locator/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} ...`
Expand All @@ -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;

0 comments on commit 882915c

Please sign in to comment.