Skip to content

Commit

Permalink
Improvements eslint and prettier configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Dec 6, 2023
1 parent 69a6e7e commit 7e30d98
Show file tree
Hide file tree
Showing 38 changed files with 98 additions and 77 deletions.
33 changes: 19 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,27 @@ module.exports = {
},
plugins: ['@typescript-eslint', 'prettier'],
ignorePatterns: ['migrations/'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
rules: {
'no-undef': ['error', { 'typeof': true }],
'no-undef': ['error', { typeof: true }],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-use-before-define': 'error',
'quotes': [2, 'single', { 'avoidEscape': true }],
'semi': ['error', 'always'],
'indent': 'off',

quotes: [2, 'single', { avoidEscape: true }],
semi: ['error', 'always'],
indent: 'off',
'linebreak-style': ['error', 'unix'],
'no-extra-semi': 'error',

'max-len': ['error', { code: 120, ignorePattern: '^(import\\s.+from\\s.+;?)|(export\\s.+;?)$' }],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'function' },
{ blankLine: 'always', prev: 'function', next: '*' },
{ blankLine: 'always', prev: 'export', next: '*' },
{ blankLine: 'always', prev: '*', next: 'export' },
],

'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
Expand All @@ -33,9 +38,9 @@ module.exports = {
'error',
'single',
{
'allowTemplateLiterals': true
}
allowTemplateLiterals: true,
},
],
'@typescript-eslint/no-extra-semi': 'error'
}
'@typescript-eslint/no-extra-semi': 'error',
},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.stryker-tmp
/reports/
stryker.log
.idea
5 changes: 4 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"singleQuote": true,
"semi": true,
"tabWidth": 2,
"printWidth": 120,
"tabWidth": 2
"trailingComma": "all",
"arrowParens": "always"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class LoginUserCommand implements Command {
public readonly email: string,
public readonly token: string,
public readonly provider: string,
public readonly photo: string
public readonly photo: string,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@ export default class LoginUserCommandHandler implements ICommandHandler<LoginUse
constructor(
@Inject(AUTH_SESSION_REPOSITORY) private readonly authSessionRepository: AuthSessionRepository,
@Inject(SOCIAL_AUTHENTICATOR) private readonly socialAuthenticator: SocialAuthenticator,
@Inject(EVENT_BUS) private readonly eventBus: EventBus
@Inject(EVENT_BUS) private readonly eventBus: EventBus,
) {}

async execute(command: LoginUserCommand): Promise<void> {
await this.guardIsValidLogin(command);

const authSession = this.getAuthSession(command);
await this.authSessionRepository.save(authSession);

void this.eventBus.publish(authSession.pullDomainEvents());
}

private async guardIsValidLogin(command: LoginUserCommand) {
const isValid: boolean = await this.socialAuthenticator.login(command.token);
if (!isValid) {
throw new LoginException();
}
}

private getAuthSession(command: LoginUserCommand) {
const authSessionId = AuthSessionId.of(command.id);
const session = Session.of({
name: command.name,
Expand All @@ -31,9 +42,7 @@ export default class LoginUserCommandHandler implements ICommandHandler<LoginUse
token: command.token,
photo: command.photo,
});
const authSession = AuthSession.create(authSessionId, session);
await this.authSessionRepository.save(authSession);

void this.eventBus.publish(authSession.pullDomainEvents());
return AuthSession.create(authSessionId, session);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export default class CreateCountryCommand implements Command {
public readonly id: string,
public readonly name: string,
public readonly iso: string,
public readonly languages: Array<LanguagePrimitives>
public readonly languages: Array<LanguagePrimitives>,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class CreateCountryCommandHandler implements ICommandHandler<Crea

async execute(command: CreateCountryCommand): Promise<void> {
const countryId = CountryId.of(command.id);
await this.checkCountryDoesNotExists(countryId);
await this.guardCountryDoesNotExists(countryId);

const languages = LanguageCollection.of(command.languages);

Expand All @@ -22,7 +22,7 @@ export default class CreateCountryCommandHandler implements ICommandHandler<Crea
await this.countryRepository.save(country);
}

private async checkCountryDoesNotExists(countryId: CountryId): Promise<void> {
private async guardCountryDoesNotExists(countryId: CountryId): Promise<void> {
const country = await this.countryRepository.findById(countryId);
if (country) {
throw new CountryAlreadyExistsException(countryId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class CreateExpressionCommand implements Command {
public readonly languageId: string,
public readonly countryId: string,
public readonly userId: string,
public readonly terms: Array<ExpressionTermPrimitives>
public readonly terms: Array<ExpressionTermPrimitives>,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/buses/comman
export default class CreateExpressionCommandHandler implements ICommandHandler<CreateExpressionCommand> {
constructor(
@Inject(EXPRESSION_REPOSITORY) private readonly expressionRepository: ExpressionRepository,
@Inject(EVENT_BUS) private readonly eventBus: EventBus
@Inject(EVENT_BUS) private readonly eventBus: EventBus,
) {}

async execute(command: CreateExpressionCommand): Promise<void> {
const expressionId = ExpressionId.of(command.id);
await this.checkExpressionDoesNotExists(expressionId);
await this.guardExpressionDoesNotExists(expressionId);

const expression = Expression.create(
expressionId,
command.languageId,
CountryId.of(command.countryId),
ExpressionTermCollection.of(command.terms),
UserId.of(command.userId)
UserId.of(command.userId),
);

await this.expressionRepository.save(expression);

void this.eventBus.publish(expression.pullDomainEvents());
}

private async checkExpressionDoesNotExists(expressionId: ExpressionId): Promise<void> {
private async guardExpressionDoesNotExists(expressionId: ExpressionId): Promise<void> {
const expression = await this.expressionRepository.findById(expressionId);
if (expression) {
throw new ExpressionAlreadyExistsException(expressionId.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class CreateTermCommand extends Projection implements Command {
public readonly description: string,
public readonly example: string,
public readonly hashtags: Array<string>,
public readonly type: string
public readonly type: string,
) {
super();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EVENT_BUS, EventBus } from '@src/shared/domain/buses/eventBus/eventBus'
export default class CreateTermCommandHandler implements ICommandHandler<CreateTermCommand> {
constructor(
@Inject(TERM_REPOSITORY) private readonly termRepository: TermRepository,
@Inject(EVENT_BUS) private readonly eventBus: EventBus
@Inject(EVENT_BUS) private readonly eventBus: EventBus,
) {}

async execute(command: CreateTermCommand): Promise<void> {
Expand All @@ -34,7 +34,7 @@ export default class CreateTermCommandHandler implements ICommandHandler<CreateT
command.hashtags,
[],
[],
[]
[],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ export default class CreateOnExpressionCreatedEventHandler implements IEventHand
constructor(@Inject(COMMAND_BUS) private readonly commandBus: CommandBus) {}

async handle(event: ExpressionCreatedEvent): Promise<void> {
const terms = event.terms;

for (const term of terms) {
for (const term of event.terms) {
await this.commandBus.dispatch(
new CreateTermCommand(
event.aggregateId,
term['expression'],
term['description'],
term['example'],
term['hashtags'],
TermTypeEnum.EXPRESSION
)
TermTypeEnum.EXPRESSION,
),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@ export default class CreateOnWordCreatedEventHandler implements IEventHandler<Wo
constructor(@Inject(COMMAND_BUS) private readonly commandBus: CommandBus) {}

async handle(event: WordCreatedEvent): Promise<void> {
const terms = event.terms;

for (const term of terms) {
for (const term of event.terms) {
await this.commandBus.dispatch(
new CreateTermCommand(
event.aggregateId,
term['word'],
term['description'],
term['example'],
term['hashtags'],
TermTypeEnum.WORD
)
TermTypeEnum.WORD,
),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class CreateUserCommand implements Command {
public readonly email: string,
public readonly token: string,
public readonly provider: string,
public readonly photo: string
public readonly photo: string,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class CreateUserCommandHandler implements ICommandHandler<CreateU
command.name,
command.provider,
Email.of(command.email),
command.photo
command.photo,
);

await this.userRepository.save(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ export default class UpdateUserCommandHandler implements ICommandHandler<UpdateU
constructor(@Inject(USER_REPOSITORY) private readonly userRepository: UserRepository) {}

async execute(command: UpdateUserCommand): Promise<void> {
const user = await this.getUser(command);

user.update(command.name, command.photo);
await this.userRepository.save(user);
}

private async getUser(command: UpdateUserCommand) {
const user = await this.userRepository.findById(UserId.of(command.id));
if (null === user) {
throw new UserDoesNotExistsException(command.id);
}

user.update(command.name, command.photo);
await this.userRepository.save(user);
return user;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export default class CreateOrUpdateUserOnAuthSessionCreatedEventHandler
{
constructor(
@Inject(USER_REPOSITORY) private readonly userRepository: UserRepository,
@Inject(COMMAND_BUS) private readonly commandBus: CommandBus
@Inject(COMMAND_BUS) private readonly commandBus: CommandBus,
) {}

async handle(event: AuthSessionCreatedEvent): Promise<void> {
const userId = UserId.fromIdWithEmailVerification(event.id, event.email);
const user = await this.userRepository.findById(userId);
if (null === user) {
await this.commandBus.dispatch(
new CreateUserCommand(userId.toString(), event.name, event.email, event.token, event.provider, event.photo)
new CreateUserCommand(userId.toString(), event.name, event.email, event.token, event.provider, event.photo),
);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export default class CreateWordCommand implements Command {
public readonly languageId: string,
public readonly countryId: string,
public readonly userId: string,
public readonly terms: Array<WordTermPrimitives>
public readonly terms: Array<WordTermPrimitives>,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ import { CommandHandler, ICommandHandler } from '@src/shared/domain/buses/comman
export default class CreateWordCommandHandler implements ICommandHandler<CreateWordCommand> {
constructor(
@Inject(WORD_REPOSITORY) private readonly wordRepository: WordRepository,
@Inject(EVENT_BUS) private readonly eventBus: EventBus
@Inject(EVENT_BUS) private readonly eventBus: EventBus,
) {}

async execute(command: CreateWordCommand): Promise<void> {
const wordId = WordId.of(command.id);
await this.checkWordDoesNotExists(wordId);
await this.guardWordDoesNotExists(wordId);

const word = Word.create(
wordId,
command.languageId,
CountryId.of(command.countryId),
WordTermCollection.of(command.terms),
UserId.of(command.userId)
UserId.of(command.userId),
);

await this.wordRepository.save(word);

void this.eventBus.publish(word.pullDomainEvents());
}

private async checkWordDoesNotExists(wordId: WordId): Promise<void> {
private async guardWordDoesNotExists(wordId: WordId): Promise<void> {
const word = await this.wordRepository.findById(wordId);
if (word) {
throw new WordAlreadyExistsException(wordId.toString());
Expand Down
4 changes: 2 additions & 2 deletions src/languages/domain/auth/authSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class AuthSession extends AggregateRoot {
sessionPrimitives.email,
sessionPrimitives.token,
sessionPrimitives.provider,
sessionPrimitives.photo
)
sessionPrimitives.photo,
),
);

return authSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class AuthSessionCreatedEvent extends DomainEvent {
public readonly token: string,
public readonly provider: string,
public readonly photo: string,
eventId = ''
eventId = '',
) {
super(id, eventId);
}
Expand All @@ -21,7 +21,7 @@ export default class AuthSessionCreatedEvent extends DomainEvent {
payload['token'],
payload['provider'],
payload['photo'],
payload['eventId']
payload['eventId'],
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/languages/domain/auth/valueObjects/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class Session {
private readonly email: string,
private readonly provider: string,
private readonly token: string,
private readonly photo: string
private readonly photo: string,
) {}

static of(session: SessionPrimitives): Session {
Expand Down
Loading

0 comments on commit 7e30d98

Please sign in to comment.