-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor my commit with base main
- Loading branch information
1 parent
378fba6
commit 0753211
Showing
4 changed files
with
27 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) {} | ||
} |
14 changes: 5 additions & 9 deletions
14
...controllers/account-controller-factory.ts → ...ount/routes/account-controller-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); |