feat: update docker-compose for MongoDB initialization and simplify order/user repository save methods

This commit is contained in:
2026-01-13 01:58:58 +03:00
parent f13a83c992
commit 6068848375
4 changed files with 19 additions and 16 deletions
+16 -13
View File
@@ -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
View File
@@ -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",
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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();
}
}