mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-03-24 11:05:49 +00:00
clean using es6
This commit is contained in:
@@ -3,7 +3,7 @@ import { InjectMapper } from '@automapper/nestjs';
|
||||
import { Controller, UsePipes } from '@nestjs/common';
|
||||
import { CommandBus, QueryBus } from '@nestjs/cqrs';
|
||||
import { GrpcMethod, RpcException } from '@nestjs/microservices';
|
||||
import { DatabaseException } from 'src/modules/database/src/exceptions/database.exception';
|
||||
import { DatabaseException } from 'src/modules/database/exceptions/database.exception';
|
||||
import { AddUsernameCommand } from '../../commands/add-username.command';
|
||||
import { CreateAuthenticationCommand } from '../../commands/create-authentication.command';
|
||||
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthRepository } from '../../../database/src/domain/auth-repository';
|
||||
import { AuthRepository } from '../../../database/domain/auth-repository';
|
||||
import { Authentication } from '../../domain/entities/authentication';
|
||||
|
||||
@Injectable()
|
||||
export class AuthenticationRepository extends AuthRepository<Authentication> {
|
||||
protected _model = 'auth';
|
||||
protected model = 'auth';
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import { IMessageBroker } from '../../domain/interfaces/message-broker';
|
||||
@Injectable()
|
||||
export class Messager extends IMessageBroker {
|
||||
constructor(
|
||||
private readonly _amqpConnection: AmqpConnection,
|
||||
private readonly amqpConnection: AmqpConnection,
|
||||
configService: ConfigService,
|
||||
) {
|
||||
super(configService.get<string>('RMQ_EXCHANGE'));
|
||||
}
|
||||
|
||||
publish(routingKey: string, message: string): void {
|
||||
this._amqpConnection.publish(this.exchange, routingKey, message);
|
||||
}
|
||||
publish = (routingKey: string, message: string): void => {
|
||||
this.amqpConnection.publish(this.exchange, routingKey, message);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthRepository } from '../../../database/src/domain/auth-repository';
|
||||
import { AuthRepository } from '../../../database/domain/auth-repository';
|
||||
import { Username } from '../../domain/entities/username';
|
||||
|
||||
@Injectable()
|
||||
export class UsernameRepository extends AuthRepository<Username> {
|
||||
protected _model = 'username';
|
||||
protected model = 'username';
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class AddUsernameUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: AddUsernameCommand): Promise<Username> {
|
||||
execute = async (command: AddUsernameCommand): Promise<Username> => {
|
||||
const { uuid, username, type } = command.addUsernameRequest;
|
||||
try {
|
||||
return await this._usernameRepository.create({
|
||||
@@ -29,5 +29,5 @@ export class AddUsernameUseCase {
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,9 @@ export class CreateAuthenticationUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: CreateAuthenticationCommand): Promise<Authentication> {
|
||||
execute = async (
|
||||
command: CreateAuthenticationCommand,
|
||||
): Promise<Authentication> => {
|
||||
const { uuid, password, ...username } = command.createAuthenticationRequest;
|
||||
const hash = await bcrypt.hash(password, 10);
|
||||
|
||||
@@ -40,5 +42,5 @@ export class CreateAuthenticationUseCase {
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { AuthenticationRepository } from '../../adapters/secondaries/authenticat
|
||||
import { Messager } from '../../adapters/secondaries/messager';
|
||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
||||
import { Authentication } from '../entities/authentication';
|
||||
|
||||
@CommandHandler(DeleteAuthenticationCommand)
|
||||
export class DeleteAuthenticationUseCase {
|
||||
@@ -12,7 +13,9 @@ export class DeleteAuthenticationUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: DeleteAuthenticationCommand) {
|
||||
execute = async (
|
||||
command: DeleteAuthenticationCommand,
|
||||
): Promise<Authentication> => {
|
||||
try {
|
||||
await this._usernameRepository.deleteMany({
|
||||
uuid: command.deleteAuthenticationRequest.uuid,
|
||||
@@ -30,5 +33,5 @@ export class DeleteAuthenticationUseCase {
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export class DeleteUsernameUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: DeleteUsernameCommand) {
|
||||
execute = async (command: DeleteUsernameCommand): Promise<void> => {
|
||||
try {
|
||||
const { username } = command.deleteUsernameRequest;
|
||||
const usernameFound = await this._usernameRepository.findOne({
|
||||
@@ -34,5 +34,5 @@ export class DeleteUsernameUseCase {
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export class UpdatePasswordUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: UpdatePasswordCommand): Promise<Authentication> {
|
||||
execute = async (command: UpdatePasswordCommand): Promise<Authentication> => {
|
||||
const { uuid, password } = command.updatePasswordRequest;
|
||||
const hash = await bcrypt.hash(password, 10);
|
||||
|
||||
@@ -30,5 +30,5 @@ export class UpdatePasswordUseCase {
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export class UpdateUsernameUseCase {
|
||||
private readonly _messager: Messager,
|
||||
) {}
|
||||
|
||||
async execute(command: UpdateUsernameCommand): Promise<Username> {
|
||||
execute = async (command: UpdateUsernameCommand): Promise<Username> => {
|
||||
const { uuid, username, type } = command.updateUsernameRequest;
|
||||
if (!username) throw new BadRequestException();
|
||||
// update username if it exists, otherwise create it
|
||||
@@ -63,5 +63,5 @@ export class UpdateUsernameUseCase {
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ export class ValidateAuthenticationUseCase {
|
||||
private readonly _usernameRepository: UsernameRepository,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
execute = async (
|
||||
validate: ValidateAuthenticationQuery,
|
||||
): Promise<Authentication> {
|
||||
): Promise<Authentication> => {
|
||||
let username = new Username();
|
||||
try {
|
||||
username = await this._usernameRepository.findOne({
|
||||
@@ -37,5 +37,5 @@ export class ValidateAuthenticationUseCase {
|
||||
} catch (e) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { TestingModule, Test } from '@nestjs/testing';
|
||||
import { DatabaseModule } from '../../../database/database.module';
|
||||
import { PrismaService } from '../../../database/src/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../database/src/exceptions/database.exception';
|
||||
import { PrismaService } from '../../../database/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../database/exceptions/database.exception';
|
||||
import { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository';
|
||||
import { v4 } from 'uuid';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { TestingModule, Test } from '@nestjs/testing';
|
||||
import { DatabaseModule } from '../../../database/database.module';
|
||||
import { PrismaService } from '../../../database/src/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../database/src/exceptions/database.exception';
|
||||
import { PrismaService } from '../../../database/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../database/exceptions/database.exception';
|
||||
import { v4 } from 'uuid';
|
||||
import { Type } from '../../domain/dtos/type.enum';
|
||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ValidateAuthenticationQuery } from '../../queries/validate-authenticati
|
||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||
import { Type } from '../../domain/dtos/type.enum';
|
||||
import { NotFoundException, UnauthorizedException } from '@nestjs/common';
|
||||
import { DatabaseException } from '../../../database/src/exceptions/database.exception';
|
||||
import { DatabaseException } from '../../../database/exceptions/database.exception';
|
||||
import { ValidateAuthenticationRequest } from '../../domain/dtos/validate-authentication.request';
|
||||
|
||||
const mockAuthenticationRepository = {
|
||||
|
||||
Reference in New Issue
Block a user