Skip to content

Commit 5c746f4

Browse files
committed
Add category to favourite transactions
1 parent dab0e2a commit 5c746f4

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

app/graphql/mutations/favourite_transaction_upsert.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class FavouriteTransactionUpsert < BaseMutation
1313
argument :memo, String, required: false
1414
argument :price_cents, Integer, required: false
1515
argument :account_id, ID, required: false
16+
argument :category_id, ID, required: false
1617

17-
def resolve(name:, shop:, memo: nil, price_cents: nil, account_id: nil)
18+
def resolve(name:, shop:, memo: nil, price_cents: nil, account_id: nil, category_id: nil)
1819
record = current_user.favourite_transactions.new
19-
record.update!(name:, shop:, memo: memo || "", price_cents:, account_id:)
20+
record.update!(name:, shop:, memo: memo || "", price_cents:, account_id:, category_id:)
2021

2122
{ favourite_transaction: record }
2223
end

app/graphql/types/favourite_transaction_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FavouriteTransactionType < Types::BaseObject
88
field :memo, String, null: false
99
field :price_cents, Integer, null: true
1010
field :account, Types::AccountType, null: true
11+
field :category, Types::CategoryType, null: true
1112
end
1213
end
1314

app/models/favourite_transaction.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class FavouriteTransaction < ApplicationRecord
22
belongs_to :user
33
belongs_to :account, optional: true
4+
belongs_to :category, optional: true
45

56
validates :name, presence: true
67
validates :shop, presence: true
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class AddCategoryToFavouriteTransactions < ActiveRecord::Migration[7.1]
2+
def change
3+
add_reference :favourite_transactions, :category, type: :uuid
4+
end
5+
end
6+
7+
8+

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ type FavouriteCurrencyTogglePayload {
470470

471471
type FavouriteTransaction {
472472
account: Account
473+
category: Category
473474
id: ID!
474475
memo: String!
475476
name: String!
@@ -504,6 +505,7 @@ Autogenerated input type of FavouriteTransactionUpsert
504505
"""
505506
input FavouriteTransactionUpsertInput {
506507
accountId: ID
508+
categoryId: ID
507509

508510
"""
509511
A unique identifier for the client performing the mutation.

web/src/graphql-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ export type FavouriteCurrencyTogglePayload = {
398398
export type FavouriteTransaction = {
399399
__typename?: 'FavouriteTransaction';
400400
account?: Maybe<Account>;
401+
category?: Maybe<Category>;
401402
id: Scalars['ID']['output'];
402403
memo: Scalars['String']['output'];
403404
name: Scalars['String']['output'];
@@ -423,6 +424,7 @@ export type FavouriteTransactionDeletePayload = {
423424
/** Autogenerated input type of FavouriteTransactionUpsert */
424425
export type FavouriteTransactionUpsertInput = {
425426
accountId?: InputMaybe<Scalars['ID']['input']>;
427+
categoryId?: InputMaybe<Scalars['ID']['input']>;
426428
/** A unique identifier for the client performing the mutation. */
427429
clientMutationId?: InputMaybe<Scalars['String']['input']>;
428430
memo?: InputMaybe<Scalars['String']['input']>;

0 commit comments

Comments
 (0)