fix(knowledge): fix type safety issues in entry CRUD API (KNOW-002)

- Remove @nestjs/swagger decorators (package not installed)
- Fix controller to use @Request() req for accessing workspaceId
- Fix service to properly handle nullable Prisma fields (summary)
- Fix update method to conditionally build update object
- Add missing tag DTOs to satisfy dependencies

Resolves compilation errors and ensures type safety.
This commit is contained in:
Jason Woltje
2026-01-29 16:16:49 -06:00
parent 4729f964f1
commit 81d426453a
4 changed files with 42 additions and 76 deletions

View File

@@ -188,7 +188,7 @@ export class KnowledgeService {
title: createDto.title,
content: createDto.content,
contentHtml,
summary: createDto.summary,
summary: createDto.summary ?? null,
status: createDto.status || EntryStatus.DRAFT,
visibility: createDto.visibility || "PRIVATE",
createdBy: userId,
@@ -302,6 +302,31 @@ export class KnowledgeService {
contentHtml = await marked.parse(updateDto.content);
}
// Build update data object conditionally
const updateData: any = {
updatedBy: userId,
};
if (newSlug !== slug) {
updateData.slug = newSlug;
}
if (updateDto.title !== undefined) {
updateData.title = updateDto.title;
}
if (updateDto.content !== undefined) {
updateData.content = updateDto.content;
updateData.contentHtml = contentHtml;
}
if (updateDto.summary !== undefined) {
updateData.summary = updateDto.summary ?? null;
}
if (updateDto.status !== undefined) {
updateData.status = updateDto.status;
}
if (updateDto.visibility !== undefined) {
updateData.visibility = updateDto.visibility;
}
// Use transaction to ensure atomicity
const result = await this.prisma.$transaction(async (tx) => {
// Update entry
@@ -312,16 +337,7 @@ export class KnowledgeService {
slug,
},
},
data: {
slug: newSlug,
title: updateDto.title,
content: updateDto.content,
contentHtml,
summary: updateDto.summary,
status: updateDto.status,
visibility: updateDto.visibility,
updatedBy: userId,
},
data: updateData,
});
// Create new version if content or title changed