-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #622 from 1ifeworld/salief/adjust-profile-item-count
salief/adjust profile item count
- Loading branch information
Showing
6 changed files
with
129 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'server-only' | ||
|
||
import pg from 'pg' | ||
|
||
const { Pool } = pg | ||
|
||
export const pgPool = new Pool({ | ||
connectionString: process.env.DATABASE_URL, | ||
}) |
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,16 @@ | ||
'use server' | ||
|
||
import { pgPool } from '@/config/pgPool' | ||
|
||
export async function getItemsWithUserId(createdById: number) { | ||
try { | ||
await pgPool.connect() | ||
const query = | ||
'SELECT COUNT(*) FROM "public"."Item" WHERE "createdById" = $1;' | ||
const res = await pgPool.query(query, [createdById]) | ||
return { itemsWithUserId: res.rows[0].count } | ||
} catch (err) { | ||
console.error(err) | ||
return { itemsWithUserId: 0 } // Ensure a return on error | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './getItemsWithUserId' | ||
export * from './revalidationHelper' |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.