Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Unike
/
UnikeInspection-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
933b118d
authored
Sep 18, 2025
by
Augusto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small partners fixes
parent
1ae1b266
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
147 additions
and
37 deletions
+147
-37
cleanup_hardcoded_comments.sql
+12
-4
src/modules/inspection/dto/find-inspection.dto.ts
+9
-0
src/modules/inspection/inspection.controller.ts
+11
-0
src/modules/inspection/inspection.service.ts
+59
-1
src/modules/partners/dto/partner-response.dto.ts
+3
-3
src/modules/partners/partners.service.ts
+53
-29
No files found.
cleanup_hardcoded_comments.sql
View file @
933b118d
...
...
@@ -11,6 +11,7 @@ FROM "Inspection"
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%Generated inspection%'
OR
comment
LIKE
'%pending completion%'
OR
comment
LIKE
'%Automatically added for new question%'
ORDER
BY
"createdAt"
DESC
;
-- Count how many records will be affected
...
...
@@ -18,20 +19,23 @@ SELECT COUNT(*) as affected_inspections
FROM
"Inspection"
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%Generated inspection%'
OR
comment
LIKE
'%pending completion%'
;
OR
comment
LIKE
'%pending completion%'
OR
comment
LIKE
'%Automatically added for new question%'
;
-- Clean up inspection comments
UPDATE
"Inspection"
SET
comment
=
NULL
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%Generated inspection%'
OR
comment
LIKE
'%pending completion%'
;
OR
comment
LIKE
'%pending completion%'
OR
comment
LIKE
'%Automatically added for new question%'
;
-- Clean up inspection response comments
UPDATE
"InspectionResponse"
SET
comment
=
NULL
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%to be completed%'
;
OR
comment
LIKE
'%to be completed%'
OR
comment
LIKE
'%Automatically added for new question%'
;
-- Show results after cleanup
SELECT
...
...
@@ -41,6 +45,7 @@ FROM "Inspection"
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%Generated inspection%'
OR
comment
LIKE
'%pending completion%'
OR
comment
LIKE
'%Automatically added for new question%'
UNION
ALL
...
...
@@ -49,7 +54,8 @@ SELECT
COUNT
(
*
)
as
remaining_records
FROM
"InspectionResponse"
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%to be completed%'
;
OR
comment
LIKE
'%to be completed%'
OR
comment
LIKE
'%Automatically added for new question%'
;
-- Verify cleanup was successful
SELECT
...
...
@@ -63,10 +69,12 @@ FROM (
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%Generated inspection%'
OR
comment
LIKE
'%pending completion%'
OR
comment
LIKE
'%Automatically added for new question%'
UNION
ALL
SELECT
id
FROM
"InspectionResponse"
WHERE
comment
LIKE
'%Auto-generated%'
OR
comment
LIKE
'%to be completed%'
OR
comment
LIKE
'%Automatically added for new question%'
)
as
remaining_comments
;
src/modules/inspection/dto/find-inspection.dto.ts
View file @
933b118d
...
...
@@ -43,4 +43,13 @@ export class FindInspectionDto {
@
IsEnum
(
inspectionStatusEnum
.
enumValues
)
@
IsOptional
()
status
?:
(
typeof
inspectionStatusEnum
.
enumValues
)[
number
];
@
ApiPropertyOptional
({
description
:
'Filter inspection records by deadline date'
,
example
:
'2025-12-31T23:59:59.000Z'
,
type
:
String
,
})
@
IsDateString
()
@
IsOptional
()
deadline
?:
string
;
}
src/modules/inspection/inspection.controller.ts
View file @
933b118d
...
...
@@ -170,6 +170,17 @@ export class InspectionController {
);
}
@
Get
(
'debug/schema'
)
@
UseGuards
(
JwtAuthGuard
,
RolesGuard
)
@
Roles
(
Role
.
ADMIN
,
Role
.
SUPERADMIN
)
@
ApiOperation
({
summary
:
'Debug endpoint to check database schema'
,
description
:
'Debug endpoint to verify database connection and schema'
,
})
async
debugSchema
()
{
return
this
.
inspectionService
.
debugSchema
();
}
@
Get
()
@
UseGuards
(
JwtAuthGuard
)
@
ApiOperation
({
...
...
src/modules/inspection/inspection.service.ts
View file @
933b118d
...
...
@@ -24,6 +24,8 @@ import {
asc
,
desc
,
inArray
,
gte
,
lte
,
SQL
,
}
from
'drizzle-orm'
;
import
{
QuestionsService
}
from
'../questions/questions.service'
;
...
...
@@ -239,6 +241,18 @@ export class InspectionService {
conditions
.
push
(
eq
(
inspections
.
status
,
dto
.
status
as
any
));
}
if
(
dto
.
startDate
)
{
conditions
.
push
(
gte
(
inspections
.
date
,
new
Date
(
dto
.
startDate
)));
}
if
(
dto
.
endDate
)
{
conditions
.
push
(
lte
(
inspections
.
date
,
new
Date
(
dto
.
endDate
)));
}
if
(
dto
.
deadline
)
{
conditions
.
push
(
eq
(
inspections
.
deadline
,
new
Date
(
dto
.
deadline
)));
}
const
whereCondition
=
conditions
.
length
>
0
?
and
(...
conditions
)
:
undefined
;
...
...
@@ -789,6 +803,50 @@ export class InspectionService {
return
this
.
mapToInspectionDto
(
updatedInspection
);
}
async
debugSchema
()
{
try
{
// Test 1: Check if deadline column exists
const
columnCheck
=
await
this
.
databaseService
.
db
.
execute
(
`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'Inspection' AND column_name = 'deadline'
`
);
// Test 2: Try to select from Inspection table with deadline
let
testQuery
;
try
{
testQuery
=
await
this
.
databaseService
.
db
.
execute
(
`
SELECT id, date, deadline, comment, "siteId"
FROM "Inspection"
LIMIT 1
`
);
}
catch
(
error
)
{
testQuery
=
{
error
:
error
.
message
};
}
// Test 3: Check all columns in Inspection table
const
allColumns
=
await
this
.
databaseService
.
db
.
execute
(
`
SELECT column_name, data_type, is_nullable
FROM information_schema.columns
WHERE table_name = 'Inspection'
ORDER BY ordinal_position
`
);
return
{
deadlineColumnExists
:
columnCheck
.
rows
.
length
>
0
,
deadlineColumnInfo
:
columnCheck
.
rows
,
testQueryResult
:
testQuery
.
rows
||
testQuery
.
error
,
allColumns
:
allColumns
.
rows
,
timestamp
:
new
Date
().
toISOString
(),
};
}
catch
(
error
)
{
return
{
error
:
error
.
message
,
timestamp
:
new
Date
().
toISOString
(),
};
}
}
private
mapToInspectionDto
(
inspection
:
any
,
responses
:
any
[]
=
[],
...
...
@@ -797,7 +855,7 @@ export class InspectionService {
return
{
id
:
inspection
.
id
,
date
:
inspection
.
date
,
deadline
:
inspection
.
deadline
,
deadline
:
inspection
.
deadline
||
null
,
// Handle missing deadline field
comment
:
inspection
.
comment
,
finalComment
:
inspection
.
finalComment
,
finalCommentStatus
:
inspection
.
finalCommentStatus
,
...
...
src/modules/partners/dto/partner-response.dto.ts
View file @
933b118d
...
...
@@ -16,10 +16,10 @@ export class PartnerUserDto {
export
class
PartnerCountDto
{
@
ApiProperty
({
description
:
'Number of
candida
tes associated with this partner'
,
example
:
42
,
description
:
'Number of
si
tes associated with this partner'
,
example
:
5
,
})
candida
tes
:
number
;
si
tes
:
number
;
}
export
class
PartnerResponseDto
{
...
...
src/modules/partners/partners.service.ts
View file @
933b118d
...
...
@@ -48,10 +48,23 @@ export class PartnersService {
.
where
(
eq
(
users
.
partnerId
,
partner
.
id
));
// Get site count for this partner
const
[{
siteCount
}]
=
await
this
.
databaseService
.
db
.
select
({
siteCount
:
count
(
partnerSites
.
id
)
})
.
from
(
partnerSites
)
.
where
(
eq
(
partnerSites
.
partnerId
,
partner
.
id
));
let
siteCount
=
0
;
try
{
const
result
=
await
this
.
databaseService
.
db
.
select
({
siteCount
:
count
(
partnerSites
.
id
)
})
.
from
(
partnerSites
)
.
where
(
eq
(
partnerSites
.
partnerId
,
partner
.
id
));
siteCount
=
result
[
0
]?.
siteCount
||
0
;
}
catch
(
error
)
{
console
.
error
(
'❌ [DEBUG] Error getting site count for partner'
,
partner
.
id
,
':'
,
error
.
message
,
);
// Set siteCount to 0 and continue
siteCount
=
0
;
}
return
{
...
partner
,
...
...
@@ -193,33 +206,44 @@ export class PartnersService {
async
getPartnerSites
(
partnerId
:
number
)
{
await
this
.
findOne
(
partnerId
);
// Get sites for this partner
const
partnerSitesList
=
await
this
.
databaseService
.
db
.
select
()
.
from
(
partnerSites
)
.
where
(
eq
(
partnerSites
.
partnerId
,
partnerId
));
try
{
// Get sites for this partner
const
partnerSitesList
=
await
this
.
databaseService
.
db
.
select
()
.
from
(
partnerSites
)
.
where
(
eq
(
partnerSites
.
partnerId
,
partnerId
));
// For each partner site, get the site details
const
sitesWithDetails
=
await
Promise
.
all
(
partnerSitesList
.
map
(
async
(
partnerSite
)
=>
{
const
siteList
=
await
this
.
databaseService
.
db
.
select
()
.
from
(
sites
)
.
where
(
eq
(
sites
.
id
,
partnerSite
.
siteId
))
.
limit
(
1
);
return
{
partnerSiteId
:
partnerSite
.
id
,
partnerId
:
partnerSite
.
partnerId
,
siteId
:
partnerSite
.
siteId
,
site
:
siteList
.
length
>
0
?
siteList
[
0
]
:
null
,
createdAt
:
partnerSite
.
createdAt
,
updatedAt
:
partnerSite
.
updatedAt
,
};
}),
);
// For each partner site, get the site details
const
sitesWithDetails
=
await
Promise
.
all
(
partnerSitesList
.
map
(
async
(
partnerSite
)
=>
{
const
siteList
=
await
this
.
databaseService
.
db
.
select
()
.
from
(
sites
)
.
where
(
eq
(
sites
.
id
,
partnerSite
.
siteId
))
.
limit
(
1
);
return
sitesWithDetails
;
}
catch
(
error
)
{
console
.
error
(
'❌ [DEBUG] Error in getPartnerSites:'
,
{
message
:
error
.
message
,
partnerId
:
partnerId
,
stack
:
error
.
stack
,
});
return
{
partnerSiteId
:
partnerSite
.
id
,
partnerId
:
partnerSite
.
partnerId
,
siteId
:
partnerSite
.
siteId
,
site
:
siteList
.
length
>
0
?
siteList
[
0
]
:
null
,
createdAt
:
partnerSite
.
createdAt
,
updatedAt
:
partnerSite
.
updatedAt
,
};
}),
);
return
sitesWithDetails
;
// Return empty array if there's an error
return
[];
}
}
async
addSiteToPartner
(
partnerId
:
number
,
siteId
:
number
)
{
...
...
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