feat(Chat): implement chat incident reporting feature
All checks were successful
Deploy to production / deploy (push) Successful in 1m57s
All checks were successful
Deploy to production / deploy (push) Successful in 1m57s
- Added reportChatIncident method in ChatController to handle reporting of chat incidents. - Introduced a new API route for reporting incidents in chatRouter. - Implemented chatService methods to ensure the chat report table is created and to handle incident data storage. - Enhanced frontend components to allow users to report incidents in both multi and random chat dialogs. - Updated internationalization files to include new strings for reporting functionality in multiple languages.
This commit is contained in:
@@ -784,9 +784,36 @@ class AdminService {
|
||||
|
||||
const types = await RegionType.findAll({
|
||||
attributes: ['id', 'labelTr', 'parentId'],
|
||||
order: [['labelTr', 'ASC']],
|
||||
});
|
||||
return types;
|
||||
|
||||
const byId = new Map(types.map((t) => [t.id, t]));
|
||||
const depthCache = new Map();
|
||||
const computeDepth = (typeId, visiting = new Set()) => {
|
||||
if (depthCache.has(typeId)) return depthCache.get(typeId);
|
||||
if (visiting.has(typeId)) {
|
||||
// Cycle guard: treat as root-ish to avoid infinite recursion
|
||||
depthCache.set(typeId, 0);
|
||||
return 0;
|
||||
}
|
||||
visiting.add(typeId);
|
||||
const t = byId.get(typeId);
|
||||
const parentId = t?.parentId ?? null;
|
||||
const depth = parentId ? (computeDepth(parentId, visiting) + 1) : 0;
|
||||
visiting.delete(typeId);
|
||||
depthCache.set(typeId, depth);
|
||||
return depth;
|
||||
};
|
||||
|
||||
// Sort by hierarchical level: roots (no parent) first, then children.
|
||||
// Tie-breaker: labelTr for stable ordering.
|
||||
const sorted = [...types].sort((a, b) => {
|
||||
const da = computeDepth(a.id);
|
||||
const db = computeDepth(b.id);
|
||||
if (da !== db) return da - db;
|
||||
return String(a.labelTr).localeCompare(String(b.labelTr));
|
||||
});
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
async createFalukantRegion(userId, { name, regionTypeId, parentId } = {}) {
|
||||
|
||||
Reference in New Issue
Block a user