-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
711 additions
and
4 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
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
73 changes: 73 additions & 0 deletions
73
pages/api/Schema/reports/financialAccounts/financialEntries/datahandler.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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
FinancialAccountEntry, | ||
FinancialAccountMetaData, | ||
} from 'src/graphql/types.generated'; | ||
import { fetchAllData } from 'src/lib/deserializeJsonApi'; | ||
import { snakeToCamel } from 'src/lib/snakeToCamel'; | ||
import { FinancialAccountEntriesResponse } from '../../../../graphql-rest.page.generated'; | ||
|
||
export interface FinancialAccountEntriesRest { | ||
id: string; | ||
attributes: { | ||
amount: string; | ||
code: string; | ||
currency: string; | ||
description: string; | ||
entry_date: string; | ||
type: string; | ||
}; | ||
relationships: { | ||
category: { data: IdType[] }; | ||
}; | ||
} | ||
|
||
export interface FinancialAccountMetaRest { | ||
id: string; | ||
pagination: { | ||
page: string; | ||
per_page: number; | ||
total_count: number; | ||
total_pages: number; | ||
}; | ||
sort: string; | ||
filter: string; | ||
credits: string; | ||
debits: string; | ||
difference: string; | ||
currency: string; | ||
closing_balance: string; | ||
opening_balance: string; | ||
} | ||
|
||
interface IdType { | ||
id: string; | ||
type: string; | ||
} | ||
|
||
export const financialAccountEntriesHandler = ({ | ||
data, | ||
included, | ||
meta, | ||
}: { | ||
data: FinancialAccountEntriesRest[]; | ||
included: unknown[]; | ||
meta: FinancialAccountMetaRest; | ||
}): FinancialAccountEntriesResponse => { | ||
const entries = data.map((item) => { | ||
return fetchAllData(item, included); | ||
}) as FinancialAccountEntry[]; | ||
|
||
// Remove pagination as it's not needed since we get all transactions | ||
const metaData = {} as FinancialAccountMetaData; | ||
Object.keys(meta).forEach((key) => { | ||
if (key === 'pagination') { | ||
return; | ||
} | ||
metaData[snakeToCamel(key)] = meta[key]; | ||
}); | ||
|
||
return { | ||
entries, | ||
metaData, | ||
}; | ||
}; |
40 changes: 40 additions & 0 deletions
40
pages/api/Schema/reports/financialAccounts/financialEntries/financialEntries.graphql
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
extend type Query { | ||
financialAccountEntries( | ||
input: FinancialAccountEntriesInput! | ||
): FinancialAccountEntriesResponse! | ||
} | ||
|
||
input FinancialAccountEntriesInput { | ||
accountListId: ID! | ||
financialAccountId: ID! | ||
dateRange: String! | ||
categoryId: ID | ||
wildcardSearch: String | ||
} | ||
|
||
type FinancialAccountEntriesResponse { | ||
entries: [FinancialAccountEntry!]! | ||
metaData: FinancialAccountMetaData! | ||
} | ||
|
||
type FinancialAccountEntry { | ||
id: ID! | ||
amount: String! | ||
currency: String! | ||
code: String! | ||
description: String! | ||
entryDate: ISO8601Date! | ||
type: String! | ||
category: FinancialAccountCategory! | ||
} | ||
|
||
type FinancialAccountMetaData { | ||
sort: String | ||
filter: String | ||
credits: String | ||
debits: String | ||
difference: String | ||
currency: String | ||
closingBalance: String | ||
openingBalance: String | ||
} |
27 changes: 27 additions & 0 deletions
27
pages/api/Schema/reports/financialAccounts/financialEntries/resolvers.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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Resolvers } from '../../../../graphql-rest.page.generated'; | ||
|
||
export const financialAccountEntriesResolvers: Resolvers = { | ||
Query: { | ||
financialAccountEntries: ( | ||
_source, | ||
{ | ||
input: { | ||
accountListId, | ||
financialAccountId, | ||
dateRange, | ||
categoryId, | ||
wildcardSearch, | ||
}, | ||
}, | ||
{ dataSources }, | ||
) => { | ||
return dataSources.mpdxRestApi.financialAccountEntries( | ||
accountListId, | ||
financialAccountId, | ||
dateRange, | ||
categoryId, | ||
wildcardSearch, | ||
); | ||
}, | ||
}, | ||
}; |
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
Oops, something went wrong.