mirror of
https://github.com/andwati/order-service.git
synced 2026-11-01 00:32:18 +00:00
feat: update docker-compose for MongoDB initialization and simplify order/user repository save methods
This commit is contained in:
+16
-13
@@ -1,24 +1,27 @@
|
||||
services:
|
||||
api:
|
||||
container_name: order-service-api
|
||||
build: .
|
||||
ports:
|
||||
- "3000:3000"
|
||||
env_file:
|
||||
- .env
|
||||
depends_on:
|
||||
- mongo
|
||||
restart: unless-stopped
|
||||
|
||||
mongo:
|
||||
image: mongo:8
|
||||
container_name: order-service-mongo
|
||||
command: ["--replSet" , "rs0", "--bind_ip_all"]
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongo-data:/data/db
|
||||
- ./docker/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
|
||||
entrypoint: >
|
||||
bash -c "
|
||||
mongod --replSet rs0 --bind_ip_all --port 27017 &
|
||||
until mongosh --port 27017 --eval 'db.runCommand({ping:1})' &>/dev/null; do
|
||||
echo 'Waiting for MongoDB...'
|
||||
sleep 2
|
||||
done;
|
||||
echo 'Initializing replica set...';
|
||||
mongosh --port 27017 --eval \"
|
||||
try {
|
||||
rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'localhost:27017'}]});
|
||||
} catch (e) {
|
||||
print('Replica set already initialized');
|
||||
}
|
||||
\";
|
||||
wait"
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node dist/server.js",
|
||||
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
|
||||
"dev": "ts-node --transpile-only src/server.ts",
|
||||
"build": "tsc",
|
||||
"lint": "eslint . --ext .ts",
|
||||
"lint:fix": "eslint . --ext .ts --fix",
|
||||
|
||||
@@ -7,7 +7,7 @@ export class OrderRepository {
|
||||
session?: ClientSession,
|
||||
): Promise<OrderDocument> {
|
||||
const order = new OrderModel(data);
|
||||
return order.save({ session: session ?? undefined });
|
||||
return order.save();
|
||||
}
|
||||
|
||||
static findById(id: string, session?: ClientSession) {
|
||||
|
||||
@@ -16,6 +16,6 @@ export class UserRepository {
|
||||
session?: ClientSession,
|
||||
): Promise<UserDocument> {
|
||||
const user = new UserModel(data);
|
||||
return user.save({ session: session ?? undefined });
|
||||
return user.save();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user