Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo master doesnt update #66

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ STORE_STATE_PORT=27017
STORE_STATE_USERNAME=root
STORE_STATE_PASSWORD=example
STORE_STATE_DB=hangman-position
MONGO_PROJECTIONS_HOSTNAME=127.0.0.1
MONGO_PROJECTIONS_PORT=27017
MONGO_PROJECTIONS_CREDENTIALS_USERNAME=root
MONGO_PROJECTIONS_CREDENTIALS_PASSWORD=example
MONGO_PROJECTIONS_DB_TYPE=mongodb
MONGO_PROJECTIONS_DATABASE=hangman-projections-mongo
MONGO_HOST=hangman-projections
MONGO_ROOT_USERNAME=admin
MONGO_ROOT_PASSWORD=admin
MONGO_DB=hangman-projections
MONGO_USER=user
MONGO_PASSWORD=userpwd
MONGO_HOST_PORT=27016
MONGO_CONTAINER_PORT=27016
GQL_PLAYGROUND=enabled
JWT_SECRET=test
EXPIRES_IN=1h
Expand Down
22 changes: 10 additions & 12 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ version: '3.4'
services:
hangman-projections:
container_name: hangman-projections
image: mysql
command: --default-authentication-plugin=mysql_native_password
image: mongo
command: mongod --port ${MONGO_CONTAINER_PORT}
restart: always
environment:
MYSQL_ROOT_PASSWORD: ${PROJECTIONS_CREDENTIALS_PASSWORD}
MYSQL_DATABASE: ${PROJECTIONS_DATABASE}
MYSQL_TCP_PORT: ${PROJECTIONS_PORT}
networks:
- backend
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
MONGO_INITDB_DATABASE: ${MONGO_DB}
ports:
- ${PROJECTIONS_PORT}:${PROJECTIONS_PORT}
- ${MONGO_HOST_PORT}:${MONGO_CONTAINER_PORT}
volumes:
- type: volume
source: projections-volume-data
target: /var/lib/projections
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
networks:
- backend

hangman-eventstore:
container_name: hangman-eventstore
Expand Down Expand Up @@ -94,7 +92,7 @@ services:
restart: always
deploy:
mode: replicated
replicas: ${CONTAINER_SCALE}
# replicas: ${CONTAINER_SCALE}
# above is ignored by dc up and dc run (only when deploy to swarm with docker stack deploy)
depends_on:
- hangman-projections
Expand Down
10 changes: 10 additions & 0 deletions mongo-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
db.createUser({
user: 'user',
pwd: 'userpwd',
roles: [
{
role: 'readWrite',
db: 'hangman-projections',
},
],
});
55 changes: 16 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"prestart": "npm run migration:run",
"start": "nodemon --config nodemon.json",
"start:prod": "node dist/src/main",
"start:debug": "nest start --debug --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"migration:generate": "npm run typeorm -- -d ./src/datasources/MysqlDatasource.ts migration:generate",
"typeorm:generate-migration": "npm run typeorm -- -d ./src/datasources/MysqlDatasource.ts migration:generate ./src/migrations/",
"migration:run": "npm run typeorm migration:run -- -d ./src/datasources/MysqlDatasource.ts",
"migration:revert": "npm run typeorm migration:revert -- -d ./src/datasources/MysqlDatasource.ts",
"typeorm": "ts-node ./node_modules/typeorm/cli",
"reconstruct-view-db": "ts-node -r tsconfig-paths/register src/scripts/reconstruct-view-db.ts",
"test": "jest",
Expand Down Expand Up @@ -48,6 +43,7 @@
"class-validator": "^0.13.2",
"dotenv": "^16.0.2",
"graphql": "^16.6.0",
"mongodb": "^3.7.4",
"mongoose": "^6.6.1",
"mysql2": "^2.3.3",
"node-nats-streaming": "^0.3.2",
Expand Down
2 changes: 2 additions & 0 deletions src/domains/Game/Game.aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export class Game extends AggregateRoot {
}

async onNewGameStartedEvent(event: NewGameStartedEvent) {
this.logger.log('onNewGameStartedEvent');

this.wordToGuess = Word.createReplay(event.wordToGuess);
this.maxGuesses = MaxGuesses.createReplay(event.maxGuesses);
this.lettersGuessed = LettersGuessed.createReplay([]);
Expand Down
2 changes: 1 addition & 1 deletion src/domains/Game/Updaters/LetterGuessed.updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class LetterGuessedUpdater implements IViewUpdater<LetterGuessedEvent> {
lettersGuessed: game.lettersGuessed.value.map(
(letter) => letter.value,
),
dateModified: event.dateModified,
dateModified: new Date(event.dateModified),
},
);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/domains/Game/Updaters/NewGameStarted.updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class NewGameStartedUpdater
playerId: event.playerId,
wordToGuess: event.wordToGuess,
playerName: player.fullName.value,
dateCreated: event.dateCreated,
dateModified: event.dateModified,
dateCreated: new Date(event.dateCreated),
dateModified: new Date(event.dateModified),
lettersGuessed: [],
maxGuesses: event.maxGuesses,
});
Expand Down
6 changes: 5 additions & 1 deletion src/domains/User/Events/FullNameChanged.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ export class FullNameChangedEvent extends StorableEvent {
public readonly eventVersion = 1;
aggregateName = 'user';

constructor(public readonly id: string, public readonly newFullName: string) {
constructor(
public readonly id: string,
public readonly newFullName: string,
public readonly dateModified: Date,
) {
super();
}
}
4 changes: 2 additions & 2 deletions src/domains/User/Events/UserEventSerializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const UserEventSerializers = {
UserLoggedOutEvent: ({ id, dateLoggedOut }) => {
return new UserLoggedOutEvent(id, dateLoggedOut);
},
FullNameChangedEvent: ({ id, newFullName }) => {
return new FullNameChangedEvent(id, newFullName);
FullNameChangedEvent: ({ id, newFullName, dateModified }) => {
return new FullNameChangedEvent(id, newFullName, dateModified);
},
};
6 changes: 6 additions & 0 deletions src/domains/User/Updaters/FullNameChanged.updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export class FullNameChangedUpdater
async handle(event: FullNameChangedEvent) {
try {
this.logger.log(JSON.stringify(event));

const dateModified = event.dateModified
? new Date(event.dateModified)
: null;

await this.userProjectionRepository.update(
{
userId: event.id,
},
{
fullName: event.newFullName,
dateModified,
},
);
} catch (err) {
Expand Down
2 changes: 2 additions & 0 deletions src/domains/User/Updaters/UserCreated.updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class UserCreatedUpdater implements IViewUpdater<UserCreatedEvent> {
userId: event.id,
username: event.userName,
password: event.password,
dateCreated: new Date(event.dateCreated),
dateModified: new Date(event.dateModified),
});
await user.save();
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/domains/User/Updaters/UserLoggedIn.updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class UserLoggedInUpdater implements IViewUpdater<UserLoggedInEvent> {
},
{
numberLogins: event.numberLogins,
lastLoggedIn: event.dateLoggedIn,
dateModified: event.dateModified,
lastLoggedIn: new Date(event.dateLoggedIn),
dateModified: new Date(event.dateModified),
},
);
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/domains/User/User.aggregate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class User extends AggregateRoot {
this.logger.debug(`newFullName: ${newFullName}`);

const fullName = await FullName.create(newFullName);
this.apply(new FullNameChangedEvent(this.id, fullName.value));
this.apply(new FullNameChangedEvent(this.id, fullName.value, new Date()));
} catch (err) {
throw new Error(err);
}
Expand Down
Loading
Loading