Skip to content

Commit

Permalink
refactor: refactor my commit with base main
Browse files Browse the repository at this point in the history
  • Loading branch information
wendesongomes committed Jun 24, 2024
1 parent 378fba6 commit 0753211
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
32 changes: 16 additions & 16 deletions src/features/account/controllers/account-controller.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { accountDeleteBySchema } from '@/features/account/validators/account-find-by-id-schema.js';
import type { Validator } from '@/shared/infra/validator/validator.js';
import type { Controller } from '@/shared/protocols/controller.js';
import type { AsyncRequestHandler } from '@/shared/protocols/handlers.js';
import { HttpStatusCode } from '@/shared/protocols/http-client.js';
import type { Service } from '@/shared/protocols/service.js';
import type { Controller } from '@/shared/protocols/controller';
import type { AsyncRequestHandler } from '@/shared/protocols/handlers';
import { HttpStatusCode } from '@/shared/protocols/http-client';

export class AccountController implements Controller {
deleteAccountById: AsyncRequestHandler = async (req, res) => {
const accountId = req.params.id;
import type { DeleteUserAccountsService } from '../services/delete-user-accounts-service';

this.validator.validate(accountDeleteBySchema, {
params: req.params,
});
export class AccountController implements Controller {
deleteAccountById: AsyncRequestHandler = async (req, res, next) => {
try {
const accountId = Number(req.params.id);

await this.deleteByIdService.execute({ socialMediaId: accountId });
await this.deleteUserAccountService.execute({
socialMediaId: accountId,
});

res.status(HttpStatusCode.noContent).send();
return res.status(HttpStatusCode.noContent).send();
} catch (error) {
next(error);
}
};

constructor(
private readonly validator: Validator,
private readonly deleteByIdService: Service
private readonly deleteUserAccountService: DeleteUserAccountsService
) {}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { Validator } from '@/shared/infra/validator/validator.js';
import { AccountRepository } from '../repositories/account-repository/account-repository.js';
import { DeleteUserAccountsService } from '../services/delete-user-accounts-service.js';
import { AccountController } from './account-controller.js';
import { AccountController } from '../controllers/account-controller';
import { AccountRepository } from '../repositories/account-repository/account-repository';
import { DeleteUserAccountsService } from '../services/delete-user-accounts-service';

export function accountControllerFactory() {
const validator = new Validator();
const accountRepository = new AccountRepository();

const deleteAccountByIdService = new DeleteUserAccountsService(
accountRepository
);

const accountController = new AccountController(
validator,
deleteAccountByIdService
);
const accountController = new AccountController(deleteAccountByIdService);

return { accountController };
}
3 changes: 2 additions & 1 deletion src/features/account/routes/account-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Router } from 'express';
import { accountControllerFactory } from '../controllers/account-controller-factory.js';

import { accountControllerFactory } from './account-controller-factory';

const router = Router();

Expand Down
8 changes: 4 additions & 4 deletions src/features/account/validators/account-find-by-id-schema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Joi from 'joi';
import { z } from 'zod';

export const accountDeleteByParamsSchema = Joi.object({
id: Joi.string().guid().required(),
export const accountDeleteByParamsSchema = z.object({
id: z.string().uuid(),
});

export const accountDeleteBySchema = Joi.object({
export const accountDeleteBySchema = z.object({
params: accountDeleteByParamsSchema,
});

0 comments on commit 0753211

Please sign in to comment.