Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add brand transactions count #71

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Brand {
id: ID!
name: String!
category: Category @belongsTo
transactionsCount: Int! @count(relation: "transactions")
}

type Transaction {
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=0963ef1b2fcfa369c748a1a5a46bea15",
"/js/app.js": "/js/app.js?id=aaed4ea9a4458f0ffc7b2ccc09ad9a30",
"/css/app.css": "/css/app.css?id=8ea8b151e2750543926523d987c91ce8"
}
3 changes: 3 additions & 0 deletions resources/js/Api/brands.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const getBrands = (page, searchQuery) => {
name
color
}
transactionsCount
}
paginatorInfo {
hasMorePages
Expand All @@ -51,6 +52,7 @@ export const createBrand = ({name, categoryId}) => {
id
name
}
transactionsCount
}
}
`)
Expand All @@ -68,6 +70,7 @@ export const updateBrand = ({id, name, categoryId}) => {
id
name
}
transactionsCount
}
}
`)
Expand Down
4 changes: 4 additions & 0 deletions resources/js/Pages/Brand/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export default function Index({auth}) {
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Category
</th>
<th scope="col" className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
Total Transactions
</th>
<th scope="col" className="relative py-3">
<span className="sr-only">Edit</span>
</th>
Expand All @@ -167,6 +170,7 @@ export default function Index({auth}) {
<td className="px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-800">{item.id}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-800">{item.name}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-800">{item.category ? <span className={"badge badge-" + item.category.color}>{item.category.name}</span> : '-'}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-800">{item.transactionsCount}</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button onClick={() => setEditItem(item)} type="button">
<span className="sr-only">Edit</span>
Expand Down
6 changes: 5 additions & 1 deletion tests/Feature/Brands/BrandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class BrandsTest extends TestCase
public function it_returns_correct_data()
{
$brand = Brand::factory()->create();
$brand->transactions()->create(['amount' => 1000]);
$brand->transactions()->create(['amount' => 233]);

$this->graphQL(/** @lang GraphQL */ '
{
Expand All @@ -25,6 +27,7 @@ public function it_returns_correct_data()
id
name
}
transactionsCount
}
paginatorInfo {
hasMorePages
Expand All @@ -41,7 +44,8 @@ public function it_returns_correct_data()
"category" => [
"id" => $brand->category->id,
"name" => $brand->category->name,
]
],
"transactionsCount" => 2,
],
],
"paginatorInfo" => [
Expand Down
Loading