diff --git a/src/features/account/controllers/account-controller.ts b/src/features/account/controllers/account-controller.ts index 75903f7..b274113 100644 --- a/src/features/account/controllers/account-controller.ts +++ b/src/features/account/controllers/account-controller.ts @@ -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 ) {} } diff --git a/src/features/account/controllers/account-controller-factory.ts b/src/features/account/routes/account-controller-factory.ts similarity index 52% rename from src/features/account/controllers/account-controller-factory.ts rename to src/features/account/routes/account-controller-factory.ts index 1787471..3771d30 100644 --- a/src/features/account/controllers/account-controller-factory.ts +++ b/src/features/account/routes/account-controller-factory.ts @@ -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 }; } diff --git a/src/features/account/routes/account-routes.ts b/src/features/account/routes/account-routes.ts index cf294c0..e64379d 100644 --- a/src/features/account/routes/account-routes.ts +++ b/src/features/account/routes/account-routes.ts @@ -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(); diff --git a/src/features/account/validators/account-find-by-id-schema.ts b/src/features/account/validators/account-find-by-id-schema.ts index 88a3b52..29a9b5a 100644 --- a/src/features/account/validators/account-find-by-id-schema.ts +++ b/src/features/account/validators/account-find-by-id-schema.ts @@ -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, });