Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
Web-CoreX
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hendrik Garske
Web-CoreX
Commits
b092c6c3
Commit
b092c6c3
authored
Dec 27, 2025
by
Hendrik Garske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: Customer-Query korrigiert - separate TimeEntries-Abfrage für TypeScript-Kompatibilität
parent
c2f2c5ce
Pipeline
#22
failed with stages
in 25 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
39 deletions
+45
-39
route.ts
app/api/customers/route.ts
+45
-39
No files found.
app/api/customers/route.ts
View file @
b092c6c3
...
@@ -8,57 +8,63 @@ export async function GET(request: NextRequest) {
...
@@ -8,57 +8,63 @@ export async function GET(request: NextRequest) {
const
search
=
searchParams
.
get
(
"search"
)
const
search
=
searchParams
.
get
(
"search"
)
let
customersQuery
=
`
let
customersQuery
=
`
SELECT c.*,
SELECT c.*
COALESCE(
json_agg(
json_build_object(
'id', te.id,
'description', te.description,
'startTime', te."startTime",
'endTime', te."endTime",
'duration', te.duration,
'createdAt', te."createdAt",
'updatedAt', te."updatedAt",
'customerId', te."customerId",
'userId', te."userId",
'user', json_build_object(
'name', u.name,
'email', u.email
)
)
) FILTER (WHERE te.id IS NOT NULL),
'[]'::json
) as "timeEntries"
FROM customers c
FROM customers c
LEFT JOIN time_entries te ON te."customerId" = c.id
LEFT JOIN users u ON u.id = te."userId"
`
`
const
params
:
string
[]
=
[]
const
params
:
string
[]
=
[]
if
(
search
)
{
if
(
search
)
{
customersQuery
+=
`
customersQuery
+=
` WHERE c.name ILIKE $1 OR c.email ILIKE $1 OR c.company ILIKE $1`
WHERE c.name ILIKE $1 OR c.email ILIKE $1 OR c.company ILIKE $1
`
params
.
push
(
`%
${
search
}
%`
)
params
.
push
(
`%
${
search
}
%`
)
}
}
customersQuery
+=
`
customersQuery
+=
` ORDER BY c."createdAt" DESC`
GROUP BY c.id
ORDER BY c."createdAt" DESC
`
const
result
=
await
query
(
customersQuery
,
params
.
length
>
0
?
params
:
undefined
)
const
result
=
await
query
(
customersQuery
,
params
.
length
>
0
?
params
:
undefined
)
const
customers
=
result
.
rows
.
map
((
row
:
{
timeEntries
:
string
|
unknown
[]
})
=>
{
// Get time entries for each customer
const
customer
=
rowToCustomer
(
row
)
const
customers
=
await
Promise
.
all
(
return
{
result
.
rows
.
map
(
async
(
row
)
=>
{
...
customer
,
const
customer
=
rowToCustomer
(
row
)
timeEntries
:
typeof
row
.
timeEntries
===
'string'
const
timeEntriesResult
=
await
query
(
?
JSON
.
parse
(
row
.
timeEntries
)
`SELECT te.*,
:
(
Array
.
isArray
(
row
.
timeEntries
)
?
row
.
timeEntries
:
[]),
json_build_object('name', u.name, 'email', u.email) as user
}
FROM time_entries te
})
LEFT JOIN users u ON u.id = te."userId"
WHERE te."customerId" = $1
ORDER BY te."createdAt" DESC`
,
[
customer
.
id
]
)
const
timeEntries
=
timeEntriesResult
.
rows
.
map
((
entry
:
{
id
:
string
description
:
string
startTime
:
Date
endTime
:
Date
duration
:
number
createdAt
:
Date
updatedAt
:
Date
customerId
:
string
userId
:
string
user
:
unknown
})
=>
({
id
:
entry
.
id
,
description
:
entry
.
description
,
startTime
:
entry
.
startTime
,
endTime
:
entry
.
endTime
,
duration
:
entry
.
duration
,
createdAt
:
entry
.
createdAt
,
updatedAt
:
entry
.
updatedAt
,
customerId
:
entry
.
customerId
,
userId
:
entry
.
userId
,
user
:
typeof
entry
.
user
===
'string'
?
JSON
.
parse
(
entry
.
user
)
:
entry
.
user
,
}))
return
{
...
customer
,
timeEntries
,
}
})
)
return
NextResponse
.
json
(
customers
)
return
NextResponse
.
json
(
customers
)
}
catch
(
error
)
{
}
catch
(
error
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment