fix: lưu ghi chú ở địa điểm vào ghi chú

This commit is contained in:
2026-06-24 17:05:21 +07:00
parent b998833371
commit 9dc1faee6f
8 changed files with 491 additions and 260 deletions
+51 -17
View File
@@ -789,29 +789,14 @@ class TourController {
}
});
// Auto-create default note template for new tour
const noteContent = `<h2>${filteredTitle} - Initial Planning</h2>
<p><strong>Start Date:</strong> ${startDate ? new Date(startDate).toLocaleDateString() : 'TBD'}</p>
<p><strong>End Date:</strong> ${endDate ? new Date(endDate).toLocaleDateString() : 'TBD'}</p>
<p><strong>Adult Participants:</strong> ${adultCount || 1}</p>
<p><strong>Child Participants:</strong> ${childCount || 0}</p>
<h3>Key Items to Plan:</h3>
<ul>
<li>Accommodations</li>
<li>Transportation</li>
<li>Activities & Attractions</li>
<li>Budget & Expenses</li>
<li>Important Contact Numbers</li>
<li>Special Requirements & Notes</li>
</ul>
<p><em>Add your planning notes here...</em></p>`;
const noteContent = `<h1>${filteredTitle}</h1><h2>Ghi chú chung</h2><p><em>Nội dung ghi chú tổng quan của chuyến đi...</em></p>`;
try {
await this.prisma.tourNote.create({
data: {
tourId: tour.id,
userId: req.user.id,
title: `[${filteredTitle}] - Initial Planning`,
title: `Ghi chú: ${filteredTitle}`,
content: noteContent
}
});
@@ -4110,6 +4095,55 @@ class TourNoteController {
});
return { success: true };
}
@Roles(ParticipantRole.OWNER, ParticipantRole.MANAGER, ParticipantRole.MEMBER, ParticipantRole.MEMBER_NO_FINANCE)
@Post('insert')
async insertSection(
@Param('tourId') tourId: string,
@Body() body: { legId: string; noteSnippet: string },
@Req() req: any
) {
const tour = await this.prisma.tour.findUnique({ where: { id: tourId } });
if (!tour) throw new NotFoundException('Không tìm thấy tour');
const masterNote = await this.prisma.tourNote.findFirst({
where: { tourId, title: `Ghi chú: ${tour.title}`, isDeleted: false, userId: req.user.id }
});
let note = masterNote;
if (!note) {
note = await this.prisma.tourNote.create({
data: {
tourId,
userId: req.user.id,
title: `Ghi chú: ${tour.title}`,
content: `# ${tour.title}\n\n## Ghi chú chung\n\n*(Nội dung ghi chú tổng quan của chuyến đi...)*\n\n`
}
});
}
const leg = await this.prisma.leg.findUnique({ where: { id: body.legId } });
const stageHeader = leg ? `<h2>Ghi chú: ${leg.note || `Chặng ${leg.sequence}`}</h2>` : '<h2>Ghi chú:</h2>';
let content = note.content;
const stageIndex = content.indexOf(stageHeader);
if (stageIndex === -1) {
content += `<br><br>${stageHeader}${body.noteSnippet}`;
} else {
const nextHeaderIndex = content.indexOf('<h2>', stageIndex + stageHeader.length);
if (nextHeaderIndex !== -1) {
content = content.slice(0, nextHeaderIndex) + body.noteSnippet + content.slice(nextHeaderIndex);
} else {
content += body.noteSnippet;
}
}
return this.prisma.tourNote.update({
where: { id: note.id },
data: { content }
});
}
}
@Controller('admin/notes')