Skip to content

Commit

Permalink
feat: added new logger structure implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tpmpb committed Jan 16, 2025
1 parent 989f186 commit 66f5a3b
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {
} from '@/core/application/use-cases/accounts-with-portfolios/fetch-accounts-with-portfolios-use-case'
import { applyMiddleware } from '@/lib/applymiddleware/apply-middleware'
import { loggerMiddleware } from '@/utils/logger-middleware-config'
import { LoggerAggregator } from '@/core/application/logger/logger-aggregator'

const midazLogger = container.get(LoggerAggregator)

export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAccountsWithPortfolios',
method: 'GET',
useCase: 'FetchAccountsWithPortfoliosUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand All @@ -41,6 +42,13 @@ export const GET = applyMiddleware(
page
)

midazLogger.debug('Accounts with portfolios fetched', {
organizationId,
ledgerId: params.ledgerId,
portfolioId: params.portfolioId,
accountsWithPortfolios
})

return NextResponse.json(accountsWithPortfolios)
} catch (error: any) {
const { message, status } = await apiErrorHandler(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
import { NextResponse, NextRequest } from 'next/server'
import { applyMiddleware } from '@/lib/applymiddleware/apply-middleware'
import { loggerMiddleware } from '@/utils/logger-middleware-config'
import { LoggerAggregator } from '@/core/application/logger/logger-aggregator'

const midazLogger = container.get(LoggerAggregator)

export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'getAccountById',
method: 'GET',
useCase: 'FetchAccountByIdUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand Down Expand Up @@ -62,9 +63,7 @@ export const PATCH = applyMiddleware(
[
loggerMiddleware({
operationName: 'updateAccount',
method: 'PATCH',
useCase: 'UpdateAccountUseCase',
logLevel: 'info'
method: 'PATCH'
})
],
async (
Expand Down Expand Up @@ -105,9 +104,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deleteAccount',
method: 'DELETE',
useCase: 'DeleteAccountUseCase',
logLevel: 'info'
method: 'DELETE'
})
],
async (
Expand All @@ -128,7 +125,7 @@ export const DELETE = applyMiddleware(
const { id: organizationId, ledgerId, accountId } = params

await deleteAccountUseCase.execute(organizationId, ledgerId, accountId)

midazLogger.audit('Account deleted', { accountId })
return NextResponse.json({}, { status: 200 })
} catch (error: any) {
const { message, status } = await apiErrorHandler(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
import { NextResponse, NextRequest } from 'next/server'
import { applyMiddleware } from '@/lib/applymiddleware/apply-middleware'
import { loggerMiddleware } from '@/utils/logger-middleware-config'
import { LoggerAggregator } from '@/core/application/logger/logger-aggregator'


const midazLogger = container.get(LoggerAggregator)

export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllAccounts',
method: 'GET',
useCase: 'FetchAllAccountsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand Down Expand Up @@ -67,9 +69,7 @@ export const POST = applyMiddleware(
[
loggerMiddleware({
operationName: 'createAccount',
method: 'POST',
useCase: 'CreateAccountUseCase',
logLevel: 'info'
method: 'POST'
})
],
async (
Expand All @@ -90,6 +90,8 @@ export const POST = applyMiddleware(
body
)

midazLogger.info('Account created', { account })

return NextResponse.json(account)
} catch (error: any) {
const { message, status } = await apiErrorHandler(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAssetById',
method: 'GET',
useCase: 'FetchAssetByIdUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand All @@ -49,9 +47,7 @@ export const PATCH = applyMiddleware(
[
loggerMiddleware({
operationName: 'updateAsset',
method: 'PATCH',
useCase: 'UpdateAssetUseCase',
logLevel: 'info'
method: 'PATCH'
})
],
async (
Expand Down Expand Up @@ -84,9 +80,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deleteAsset',
method: 'DELETE',
useCase: 'DeleteAssetUseCase',
logLevel: 'info'
method: 'DELETE'
})
],
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const POST = applyMiddleware(
[
loggerMiddleware({
operationName: 'createAsset',
method: 'POST',
useCase: 'CreateAssetUseCase',
logLevel: 'info'
method: 'POST'
})
],
async (
Expand Down Expand Up @@ -51,9 +49,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllAssets',
method: 'GET',
useCase: 'FetchAllAssetsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchPortfoliosWithAccounts',
method: 'GET',
useCase: 'FetchPortfoliosWithAccountsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deletePortfolio',
method: 'DELETE',
useCase: 'DeletePortfolioUseCase',
logLevel: 'audit'
method: 'DELETE'
})
],
async (
Expand Down Expand Up @@ -53,9 +51,7 @@ export const PATCH = applyMiddleware(
[
loggerMiddleware({
operationName: 'updatePortfolio',
method: 'PATCH',
useCase: 'UpdatePortfolioUseCase',
logLevel: 'audit'
method: 'PATCH'
})
],
async (
Expand Down Expand Up @@ -89,9 +85,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchPortfolioById',
method: 'GET',
useCase: 'FetchPortfolioByIdUseCase',
logLevel: 'debug'
method: 'GET'
})
],
async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllPortfolios',
method: 'GET',
method: 'GET'
})
],
async (request: NextRequest, { params }: { params: PortfolioParams }) => {
Expand All @@ -49,6 +49,11 @@ export const GET = applyMiddleware(
)


midazLogger.debug('Portfolios fetched', {
organizationId,
ledgerId,
portfolios
})

return NextResponse.json(portfolios)
} catch (error: any) {
Expand All @@ -62,7 +67,7 @@ export const POST = applyMiddleware(
[
loggerMiddleware({
operationName: 'createPortfolio',
method: 'POST',
method: 'POST'
})
],
async (request: NextRequest, { params }: { params: PortfolioParams }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deleteProduct',
method: 'DELETE',
useCase: 'DeleteProductUseCase',
logLevel: 'info'
method: 'DELETE'
})
],
async (request: Request, { params }: { params: ProductParams }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export const POST = applyMiddleware(
[
loggerMiddleware({
operationName: 'createProduct',
method: 'POST',
useCase: 'CreateProductUseCase',
logLevel: 'info'
method: 'POST'
})
],
async (request: NextRequest, { params }: { params: ProductParams }) => {
Expand Down Expand Up @@ -54,9 +52,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllProducts',
method: 'GET',
useCase: 'FetchAllProductsUseCase',
logLevel: 'debug'
method: 'GET'
})
],
async (request: NextRequest, { params }: { params: ProductParams }) => {
Expand Down
12 changes: 3 additions & 9 deletions src/app/api/organizations/[id]/ledgers/[ledgerId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchLedgerById',
method: 'GET',
useCase: 'FetchLedgerByIdUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (_, { params }: { params: { id: string; ledgerId: string } }) => {
Expand Down Expand Up @@ -50,9 +48,7 @@ export const PATCH = applyMiddleware(
[
loggerMiddleware({
operationName: 'updateLedger',
method: 'PATCH',
useCase: 'UpdateLedgerUseCase',
logLevel: 'info'
method: 'PATCH'
})
],
async (
Expand Down Expand Up @@ -86,9 +82,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deleteLedger',
method: 'DELETE',
useCase: 'DeleteLedgerUseCase',
logLevel: 'info'
method: 'DELETE'
})
],
async (_, { params }: { params: { id: string; ledgerId: string } }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllLedgersAssets',
method: 'GET',
useCase: 'FetchAllLedgersAssetsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (request: Request, { params }: { params: { id: string } }) => {
Expand Down
12 changes: 3 additions & 9 deletions src/app/api/organizations/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchOrganizationById',
method: 'GET',
useCase: 'FetchOrganizationByIdUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (request: Request, { params }: { params: { id: string } }) => {
Expand All @@ -47,9 +45,7 @@ export const PATCH = applyMiddleware(
[
loggerMiddleware({
operationName: 'updateOrganization',
method: 'PATCH',
useCase: 'UpdateOrganizationUseCase',
logLevel: 'info'
method: 'PATCH'
})
],
async (request: Request, { params }: { params: { id: string } }) => {
Expand All @@ -74,9 +70,7 @@ export const DELETE = applyMiddleware(
[
loggerMiddleware({
operationName: 'deleteOrganization',
method: 'DELETE',
useCase: 'DeleteOrganizationUseCase',
logLevel: 'info'
method: 'DELETE'
})
],
async (_, { params }: { params: { id: string } }) => {
Expand Down
4 changes: 1 addition & 3 deletions src/app/api/organizations/parentOrganizations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchParentOrganizations',
method: 'GET',
useCase: 'FetchParentOrganizationsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (request: Request) => {
Expand Down
8 changes: 2 additions & 6 deletions src/app/api/organizations/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const GET = applyMiddleware(
[
loggerMiddleware({
operationName: 'fetchAllOrganizations',
method: 'GET',
useCase: 'FetchAllOrganizationsUseCase',
logLevel: 'info'
method: 'GET'
})
],
async (request: Request) => {
Expand Down Expand Up @@ -47,9 +45,7 @@ export const POST = applyMiddleware(
[
loggerMiddleware({
operationName: 'createOrganization',
method: 'POST',
useCase: 'CreateOrganizationUseCase',
logLevel: 'info'
method: 'POST'
})
],
async (request: Request) => {
Expand Down
Loading

0 comments on commit 66f5a3b

Please sign in to comment.