Skip to content

Commit

Permalink
feat: rename auth service to login service to improve clarity of intent
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirogab committed Sep 15, 2024
1 parent ab8093a commit be3678f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ErrorHandlingMiddleware } from './middlewares';
import { EmailTemplateRepository, RegisterTokenRepository, SessionRepository, UserRepository } from './repositories';
import { AppRouter, AuthRouter, RegisterRouter, UserRouter } from './routers';
import {
AuthService,
LoginService,
CreateRegisterTokenService,
CreateUserService,
GetRegisterTokenService,
Expand Down Expand Up @@ -41,7 +41,7 @@ container.registerSingleton<CreateRegisterTokenService>('CreateRegisterTokenServ
container.registerSingleton<GetRegisterTokenService>('GetRegisterTokenService', GetRegisterTokenService);
container.registerSingleton<CreateUserService>('CreateUserService', CreateUserService);
container.registerSingleton<LogoutService>('LogoutService', LogoutService);
container.registerSingleton<AuthService>('AuthService', AuthService);
container.registerSingleton<LoginService>('LoginService', LoginService);

// Controllers
container.registerSingleton<RegisterController>('RegisterController', RegisterController);
Expand Down
10 changes: 5 additions & 5 deletions src/controllers/auth.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
import { inject, injectable } from 'tsyringe';

import { HttpStatusCodesEnum } from '@/constants';
import type { AuthService, AuthServiceDto, LogoutService } from '@/interfaces';
import type { LoginService, LoginServiceDto, LogoutService } from '@/interfaces';

@injectable()
export class AuthController {
constructor(
@inject('AuthService')
private readonly authService: AuthService,
@inject('LoginService')
private readonly loginService: LoginService,

@inject('LogoutService')
private readonly logoutService: LogoutService,
) {}

public async login(request: FastifyRequest, reply: FastifyReply) {
const { email, password } = request.body as AuthServiceDto;
const { email, password } = request.body as LoginServiceDto;

const response = await this.authService.execute({ email, password });
const response = await this.loginService.execute({ email, password });

return reply.code(HttpStatusCodesEnum.OK).send(response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export * from './services/create-register-token.service';
export * from './services/get-register-token.service';
export * from './services/create-user.service';
export * from './services/logout.service';
export * from './services/auth.service';
export * from './services/login.service';
10 changes: 0 additions & 10 deletions src/interfaces/services/auth.service.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/interfaces/services/login.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { Session } from '../models/session';

export type LoginServiceDto = {
email: string;
password: string;
};

export interface LoginService {
execute(dto: LoginServiceDto): Promise<Omit<Session, 'user_id'>>;
}
2 changes: 1 addition & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './create-register-token.service';
export * from './get-register-token.service';
export * from './create-user.service';
export * from './logout.service';
export * from './auth.service';
export * from './login.service';
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { HttpStatusCodesEnum } from '@/constants';
import { AppError } from '@/errors';
import type {
AuthHelper,
AuthServiceDto,
AuthService as AuthServiceInterface,
LoginServiceDto,
LoginService as LoginServiceInterface,
HashAdapter,
Session,
UserRepository,
} from '@/interfaces';

@injectable()
export class AuthService implements AuthServiceInterface {
export class LoginService implements LoginServiceInterface {
constructor(
@inject('UserRepository')
private readonly userRepository: UserRepository,
Expand All @@ -27,7 +27,7 @@ export class AuthService implements AuthServiceInterface {
public async execute({
password,
email,
}: AuthServiceDto): Promise<Omit<Session, 'user_id'>> {
}: LoginServiceDto): Promise<Omit<Session, 'user_id'>> {
const user = await this.userRepository.findByEmail({ email });

if (!user) {
Expand Down

0 comments on commit be3678f

Please sign in to comment.