From 6a9ebf37dab09b46e0760d942e81f8a244f0beec Mon Sep 17 00:00:00 2001 From: Benjamin Piouffle Date: Fri, 17 Jan 2025 14:19:06 +0100 Subject: [PATCH] feat(Transactions): add transactions import fields --- src/graphql/schema.graphql | 18 +- src/graphql/schemaV2.graphql | 485 +++++++++++------- .../controllers/account-transactions.ts | 37 ++ 3 files changed, 352 insertions(+), 188 deletions(-) diff --git a/src/graphql/schema.graphql b/src/graphql/schema.graphql index 889fb725..a22fcf7c 100644 --- a/src/graphql/schema.graphql +++ b/src/graphql/schema.graphql @@ -132,6 +132,7 @@ interface CollectiveInterface { stats: CollectiveStatsType transactions(type: String, limit: Int, offset: Int, includeExpenseTransactions: Boolean): [Transaction] expenses(type: String, limit: Int, offset: Int, status: String, includeHostedCollectives: Boolean): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -371,7 +372,7 @@ type OrderType { """ Whether this subscription is past due or not """ - isPastDue: Boolean + isPastDue: Boolean @deprecated(reason: "2024-12-13: Not used, so we stop returning it.") """ If there is a subscription, is it active? @@ -895,9 +896,9 @@ type ExpenseType { tags: [String] status: String type: String - PayoutMethod: PayoutMethod + PayoutMethod: PayoutMethod @deprecated(reason: "2024-12-13: Please move to GraphQL v2") privateMessage: String - items: [ExpenseItem] + items: [ExpenseItem] @deprecated(reason: "2024-12-13: Please move to GraphQL v2") attachedFiles: [ExpenseAttachedFile!] user: UserDetails fromCollective: CollectiveInterface @@ -1982,7 +1983,7 @@ type CollectiveStatsType { """ Breakdown of expenses submitted to this collective by type (ALL/PENDING/APPROVED/PAID/REJECTED) """ - expenses: ExpensesStatsType + expenses: ExpensesStatsType @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ Number of transactions @@ -2295,6 +2296,7 @@ type Collective implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -2564,6 +2566,7 @@ type Event implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -2833,6 +2836,7 @@ type Fund implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -3102,6 +3106,7 @@ type Organization implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -3371,6 +3376,7 @@ type Project implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -3551,7 +3557,7 @@ type Expense implements Transaction { paymentMethod: PaymentMethodType invoiceTemplate: String description: String - expense: ExpenseType + expense: ExpenseType @deprecated(reason: "2024-12-13: Please move to GraphQL v2") } """ @@ -3935,6 +3941,7 @@ type User implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account @@ -4206,6 +4213,7 @@ type Vendor implements CollectiveInterface { includeExpenseTransactions: Boolean ): [Transaction] expenses(type: String, limit: Int, offset: Int, includeHostedCollectives: Boolean, status: String): [ExpenseType] + @deprecated(reason: "2024-12-13: Please move to GraphQL v2") """ The list of expense types supported by this account diff --git a/src/graphql/schemaV2.graphql b/src/graphql/schemaV2.graphql index e2f68a65..d7c873de 100644 --- a/src/graphql/schemaV2.graphql +++ b/src/graphql/schemaV2.graphql @@ -416,6 +416,11 @@ interface Account { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -551,7 +556,7 @@ interface Account { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -608,6 +613,7 @@ interface Account { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -1983,6 +1989,11 @@ type Order { WARNING: Total amount donated between collectives, though there will be edge cases especially when looking on the Order level, as the order id is not used in calculating this. """ totalDonations: Amount! + + """ + Total amount contributed with this order. + """ + totalContributed: Amount! paymentMethod: PaymentMethod paymentProcessorUrl: String @@ -2931,6 +2942,11 @@ type Host implements Account & AccountWithContributions { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -3066,7 +3082,7 @@ type Host implements Account & AccountWithContributions { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -3123,6 +3139,7 @@ type Host implements Account & AccountWithContributions { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -4585,6 +4602,23 @@ enum AccountOrdersFilter { OUTGOING } +input TierReferenceInput { + """ + The id assigned to the Tier + """ + id: String + + """ + The DB id assigned to the Tier + """ + legacyId: Int + + """ + Pass this flag to reference the custom tier (/donate) + """ + isCustom: Boolean +} + """ Expected funds filter (ALL_EXPECTED_FUNDS, ONLY_PENDING, ONLY_MANUAL) """ @@ -4681,6 +4715,11 @@ enum LastCommentBy { """ HOST_ADMIN + """ + Not a Fiscal Host Admin + """ + NON_HOST_ADMIN + """ Collective Admin """ @@ -4748,6 +4787,11 @@ type Comment { Returns the list of reactions added to this comment by logged in user """ userReactions: [String] + conversation: Conversation + expense: Expense + hostApplication: HostApplication + order: Order + update: Update } """ @@ -4765,6 +4809,56 @@ enum CommentType { PRIVATE_NOTE } +type HostApplication { + id: String! + + """ + The account who applied to this host + """ + account: Account! + + """ + The host the collective applied to + """ + host: Host! + + """ + The date on which the item was created + """ + createdAt: DateTime! + + """ + The date on which the item was updated + """ + updatedAt: DateTime! + status: HostApplicationStatus + message: String + customData: JSON + + """ + Returns the list of comments for this host application, or `null` if user is not allowed to see them + """ + comments( + """ + The number of results to fetch (default 10, max 1000) + """ + limit: Int! = 10 + + """ + The offset to use to fetch + """ + offset: Int! = 0 + orderBy: ChronologicalOrderInput = { field: CREATED_AT, direction: ASC } + ): CommentCollection +} + +enum HostApplicationStatus { + PENDING + APPROVED + REJECTED + EXPIRED +} + """ A collection of "Comments" """ @@ -4775,6 +4869,105 @@ type CommentCollection implements Collection { nodes: [Comment] } +""" +This represents an Update +""" +type Update { + id: String! + legacyId: Int + slug: String! + + """ + Indicates whether or not the user is allowed to see the content of this update + """ + userCanSeeUpdate: Boolean! + + """ + Indicates whether or not the user is allowed to publish this update + """ + userCanPublishUpdate: Boolean! + isPrivate: Boolean! + isChangelog: Boolean! + title: String! + createdAt: DateTime! + updatedAt: DateTime! + publishedAt: DateTime + notificationAudience: UpdateAudience + + """ + Some stats about the target audience. Will be null if the update is already published or if you don't have enough permissions so see this information. Not backed by a loader, avoid using this field in lists. + """ + audienceStats( + """ + To override the default notificationAudience + """ + audience: UpdateAudience + ): UpdateAudienceStats + makePublicOn: DateTime + summary: String + html: String + tags: [String] + fromAccount: Account + account: Account + + """ + Returns a map of reactions counts for this update + """ + reactions: JSON + + """ + Returns the list of reactions added to this update by logged in user + """ + userReactions: [String] + + """ + List the comments for this update. Not backed by a loader, don't use this in lists. + """ + comments(limit: Int! = 150, offset: Int! = 0): CommentCollection +} + +""" +Defines targets for an update +""" +enum UpdateAudience { + """ + Will be sent to collective admins and financial contributors + """ + ALL + + """ + Will be sent to collective admins + """ + COLLECTIVE_ADMINS + + """ + Will be sent to financial contributors + """ + FINANCIAL_CONTRIBUTORS + + """ + Will be sent to no one + """ + NO_ONE +} + +""" +Stats about the potential audience of an update +""" +type UpdateAudienceStats { + id: String! + coreContributors: Int! + individuals: Int! + organizations: Int! + collectives: Int! + hosted: Int! + + """ + The total number of emails to send + """ + total: Int! +} + type ConversationStats { id: String! @@ -4926,7 +5119,7 @@ type PaymentMethod { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -4983,6 +5176,7 @@ type PaymentMethod { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -5712,105 +5906,6 @@ type UpdateCollection implements Collection { nodes: [Update!] } -""" -This represents an Update -""" -type Update { - id: String! - legacyId: Int - slug: String! - - """ - Indicates whether or not the user is allowed to see the content of this update - """ - userCanSeeUpdate: Boolean! - - """ - Indicates whether or not the user is allowed to publish this update - """ - userCanPublishUpdate: Boolean! - isPrivate: Boolean! - isChangelog: Boolean! - title: String! - createdAt: DateTime! - updatedAt: DateTime! - publishedAt: DateTime - notificationAudience: UpdateAudience - - """ - Some stats about the target audience. Will be null if the update is already published or if you don't have enough permissions so see this information. Not backed by a loader, avoid using this field in lists. - """ - audienceStats( - """ - To override the default notificationAudience - """ - audience: UpdateAudience - ): UpdateAudienceStats - makePublicOn: DateTime - summary: String - html: String - tags: [String] - fromAccount: Account - account: Account - - """ - Returns a map of reactions counts for this update - """ - reactions: JSON - - """ - Returns the list of reactions added to this update by logged in user - """ - userReactions: [String] - - """ - List the comments for this update. Not backed by a loader, don't use this in lists. - """ - comments(limit: Int! = 150, offset: Int! = 0): CommentCollection -} - -""" -Defines targets for an update -""" -enum UpdateAudience { - """ - Will be sent to collective admins and financial contributors - """ - ALL - - """ - Will be sent to collective admins - """ - COLLECTIVE_ADMINS - - """ - Will be sent to financial contributors - """ - FINANCIAL_CONTRIBUTORS - - """ - Will be sent to no one - """ - NO_ONE -} - -""" -Stats about the potential audience of an update -""" -type UpdateAudienceStats { - id: String! - coreContributors: Int! - individuals: Int! - organizations: Int! - collectives: Int! - hosted: Int! - - """ - The total number of emails to send - """ - total: Int! -} - """ Input to order updates chronologically """ @@ -6064,56 +6159,6 @@ type HostApplicationCollection implements Collection { nodes: [HostApplication] } -type HostApplication { - id: String! - - """ - The account who applied to this host - """ - account: Account! - - """ - The host the collective applied to - """ - host: Host! - - """ - The date on which the item was created - """ - createdAt: DateTime! - - """ - The date on which the item was updated - """ - updatedAt: DateTime! - status: HostApplicationStatus - message: String - customData: JSON - - """ - Returns the list of comments for this host application, or `null` if user is not allowed to see them - """ - comments( - """ - The number of results to fetch (default 10, max 1000) - """ - limit: Int! = 10 - - """ - The offset to use to fetch - """ - offset: Int! = 0 - orderBy: ChronologicalOrderInput = { field: CREATED_AT, direction: ASC } - ): CommentCollection -} - -enum HostApplicationStatus { - PENDING - APPROVED - REJECTED - EXPIRED -} - """ An activity describing something that happened on the platform """ @@ -8082,6 +8127,11 @@ type Bot implements Account { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -8217,7 +8267,7 @@ type Bot implements Account { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -8274,6 +8324,7 @@ type Bot implements Account { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -8949,6 +9000,11 @@ type Collective implements Account & AccountWithHost & AccountWithContributions """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -9084,7 +9140,7 @@ type Collective implements Account & AccountWithHost & AccountWithContributions """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -9141,6 +9197,7 @@ type Collective implements Account & AccountWithHost & AccountWithContributions """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -10365,6 +10422,11 @@ type Event implements Account & AccountWithHost & AccountWithContributions & Acc """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -10500,7 +10562,7 @@ type Event implements Account & AccountWithHost & AccountWithContributions & Acc """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -10557,6 +10619,7 @@ type Event implements Account & AccountWithHost & AccountWithContributions & Acc """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -11501,6 +11564,11 @@ type Individual implements Account { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -11636,7 +11704,7 @@ type Individual implements Account { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -11693,6 +11761,7 @@ type Individual implements Account { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -12574,6 +12643,11 @@ type Organization implements Account & AccountWithContributions { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -12709,7 +12783,7 @@ type Organization implements Account & AccountWithContributions { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -12766,6 +12840,7 @@ type Organization implements Account & AccountWithContributions { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -13554,6 +13629,11 @@ type Vendor implements Account & AccountWithContributions { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -13689,7 +13769,7 @@ type Vendor implements Account & AccountWithContributions { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -13746,6 +13826,7 @@ type Vendor implements Account & AccountWithContributions { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -14912,7 +14993,7 @@ type Query { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -14969,6 +15050,7 @@ type Query { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -15193,6 +15275,11 @@ type Query { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -17173,6 +17260,11 @@ type Fund implements Account & AccountWithHost & AccountWithContributions { """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -17308,7 +17400,7 @@ type Fund implements Account & AccountWithHost & AccountWithContributions { """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -17365,6 +17457,7 @@ type Fund implements Account & AccountWithHost & AccountWithContributions { """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -18187,6 +18280,11 @@ type Project implements Account & AccountWithHost & AccountWithContributions & A """ searchTerm: String + """ + If true, return transactions with debt attached, if false transactions without debt attached. + """ + hasDebt: Boolean + """ Only return transactions with an Expense attached """ @@ -18322,7 +18420,7 @@ type Project implements Account & AccountWithHost & AccountWithContributions & A """ Use this field to filter orders on their frequency (ONETIME, MONTHLY or YEARLY) """ - frequency: ContributionFrequency + frequency: [ContributionFrequency] """ Use this field to filter orders on their statuses @@ -18379,6 +18477,7 @@ type Project implements Account & AccountWithHost & AccountWithContributions & A """ searchTerm: String tierSlug: String @deprecated(reason: "2022-02-25: Should be replaced by a tier reference. Not existing yet.") + tier: [TierReferenceInput] """ Only returns orders that have a subscription (monthly/yearly). Don't use together with frequency. @@ -18991,67 +19090,82 @@ type SearchResults { type SearchResultsAccounts { collection: AccountCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsComments { collection: CommentCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsExpenses { collection: ExpenseCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsHostApplications { collection: HostApplicationCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsOrders { collection: OrderCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsTiers { collection: TierCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsTransactions { collection: TransactionCollection! - highlights: JSONObject maxScore: Float! + + """ + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } + """ + highlights: JSONObject } type SearchResultsUpdates { collection: UpdateCollection! - highlights: JSONObject maxScore: Float! -} - -input TierReferenceInput { - """ - The id assigned to the Tier - """ - id: String """ - The DB id assigned to the Tier + Details about the matches typed as: { [id]: { score: number, fields: { [field]: [highlight] } } } """ - legacyId: Int - - """ - Pass this flag to reference the custom tier (/donate) - """ - isCustom: Boolean + highlights: JSONObject } input TransactionReferenceInput { @@ -19212,6 +19326,11 @@ type Mutation { Set to true to disable contributions to this project. Host admins will still be able to add funds. """ disableContributions: Boolean! = false + + """ + Set to true to disable expenses for this project. + """ + disableExpenses: Boolean! = false ): Project """ diff --git a/src/server/controllers/account-transactions.ts b/src/server/controllers/account-transactions.ts index fbd5f395..e8a20ca8 100644 --- a/src/server/controllers/account-transactions.ts +++ b/src/server/controllers/account-transactions.ts @@ -118,6 +118,17 @@ export const transactionsFragment = gqlV2` code name } + transactionImportRow @include(if: $hasTransactionImportRowField) { + id + sourceId + description + date + rawValue + amount { + value + currency + } + } } paymentMethod { service @@ -143,6 +154,17 @@ export const transactionsFragment = gqlV2` code name } + transactionImportRow @include(if: $hasTransactionImportRowField) { + id + sourceId + description + date + rawValue + amount { + value + currency + } + } approvedBy { slug } @@ -182,6 +204,7 @@ const transactionsQuery = gqlV2/* GraphQL */ ` $fullDescription: Boolean $group: [String] $hasAccountingCategoryField: Boolean! + $hasTransactionImportRowField: Boolean! $includeChildrenTransactions: Boolean $includeGiftCardTransactions: Boolean $includeIncognitoTransactions: Boolean @@ -252,6 +275,7 @@ const hostTransactionsQuery = gqlV2/* GraphQL */ ` $fullDescription: Boolean $group: [String] $hasAccountingCategoryField: Boolean! + $hasTransactionImportRowField: Boolean! $includeChildrenTransactions: Boolean $includeHost: Boolean $isRefund: Boolean @@ -376,6 +400,16 @@ const csvMapping = { expensePaidByHandle: (t) => get(t, 'expense.paidBy.slug'), expenseReference: (t) => get(t, 'expense.reference'), expenseTransferReference: (t) => get(t, 'expense.transferReference'), + // Transactions import + importSourceId: (t) => get(getTransactionImportRowFromTransaction(t), 'sourceId'), + importSourceDescription: (t) => get(getTransactionImportRowFromTransaction(t), 'description'), + importSourceAmount: (t) => get(getTransactionImportRowFromTransaction(t), 'amount.value'), + importSourceDate: (t) => get(getTransactionImportRowFromTransaction(t), 'date'), + importSourceData: (t) => get(getTransactionImportRowFromTransaction(t), 'rawValue'), +}; + +const getTransactionImportRowFromTransaction = (transaction) => { + return get(transaction, 'expense.transactionImportRow') || get(transaction, 'order.transactionImportRow'); }; const allKinds = [ @@ -660,6 +694,8 @@ const accountTransactions: RequestHandler = async (req, res) => { // Add fields info to the query, to prevent fetching what's not needed variables.hasAccountingCategoryField = fields.some((field) => field.startsWith('accountingCategory')); + variables.hasTransactionImportRowField = fields.some((field) => field.startsWith('importSource')); + try { // Forward Api Key or Authorization header const headers = {}; @@ -717,6 +753,7 @@ const accountTransactions: RequestHandler = async (req, res) => { const mapping = pick(csvMapping, fields); const mappedTransactions = result.transactions.nodes.map((t) => applyMapping(mapping, t)); + console.log(result.transactions.nodes[0], mappedTransactions[0]); res.write(json2csv(mappedTransactions, {})); res.write(`\n`);