feat: Refactor duplicate handling in InterestDuplicateNotificationBanner and update merge API for better access control

This commit is contained in:
2025-07-09 16:11:37 -04:00
parent 85ec5100f3
commit bf24dc9103
4 changed files with 223 additions and 22 deletions

View File

@@ -4,7 +4,7 @@
v-model="drawer"
:location="mdAndDown ? 'bottom' : undefined"
>
<v-img v-if="!mdAndDown" src="/Port_Nimara_Logo_2_Colour_New_Transparent.png" height="75" class="my-6" />
<v-img v-if="!mdAndDown" src="/Port_Nimara_Logo_2_Colour_New_Transparent.png" height="110" class="my-6" contain />
<v-list color="primary" lines="two">
<v-list-item

View File

@@ -63,12 +63,12 @@
<v-row>
<v-col cols="6">
<strong>Name:</strong> {{ group.master['Full Name'] }}<br>
<strong>Email:</strong> {{ group.master['Email'] || 'N/A' }}<br>
<strong>Phone:</strong> {{ group.master['Phone'] || 'N/A' }}
<strong>Email:</strong> {{ group.master['Email Address'] || 'N/A' }}<br>
<strong>Phone:</strong> {{ group.master['Phone Number'] || 'N/A' }}
</v-col>
<v-col cols="6">
<strong>Address:</strong> {{ group.master['Address'] || 'N/A' }}<br>
<strong>Created:</strong> {{ group.master['CreatedAt'] || 'N/A' }}<br>
<strong>Created:</strong> {{ group.master['Created At'] || 'N/A' }}<br>
<strong>ID:</strong> {{ group.master.Id }}
</v-col>
</v-row>
@@ -87,12 +87,12 @@
<v-row>
<v-col cols="6">
<strong>Name:</strong> {{ duplicate.record['Full Name'] }}<br>
<strong>Email:</strong> {{ duplicate.record['Email'] || 'N/A' }}<br>
<strong>Phone:</strong> {{ duplicate.record['Phone'] || 'N/A' }}
<strong>Email:</strong> {{ duplicate.record['Email Address'] || 'N/A' }}<br>
<strong>Phone:</strong> {{ duplicate.record['Phone Number'] || 'N/A' }}
</v-col>
<v-col cols="6">
<strong>Address:</strong> {{ duplicate.record['Address'] || 'N/A' }}<br>
<strong>Created:</strong> {{ duplicate.record['CreatedAt'] || 'N/A' }}<br>
<strong>Created:</strong> {{ duplicate.record['Created At'] || 'N/A' }}<br>
<strong>Similarity:</strong> {{ Math.round(duplicate.similarity) }}%
</v-col>
</v-row>
@@ -134,14 +134,15 @@ const error = ref('');
const hasScanned = ref(false);
const threshold = ref(80);
const { isAdmin } = useAuthorization();
const { hasRole } = useAuthorization();
// Check admin access
onMounted(() => {
if (!isAdmin()) {
// Check sales or admin access
onMounted(async () => {
const canAccess = await hasRole(['sales', 'admin']);
if (!canAccess) {
throw createError({
statusCode: 403,
statusMessage: 'Access denied. Admin privileges required.'
statusMessage: 'Access denied. Sales or admin privileges required.'
});
}
});
@@ -152,15 +153,27 @@ const findDuplicates = async () => {
duplicateGroups.value = [];
try {
const response = await $fetch('/api/admin/duplicates/find', {
method: 'POST',
body: {
threshold: threshold.value
const response = await $fetch('/api/interests/duplicates/find', {
method: 'GET',
query: {
threshold: threshold.value / 100, // Convert percentage to decimal
dateRange: 365
}
});
if (response.success) {
duplicateGroups.value = response.data.duplicateGroups || [];
// Convert the new API format to the format expected by the UI
const convertedGroups = response.data.duplicateGroups.map(group => ({
master: group.masterCandidate,
duplicates: group.interests.filter(interest => interest.Id !== group.masterCandidate.Id).map(interest => ({
record: interest,
similarity: group.confidence * 100 // Convert back to percentage
})),
similarity: group.confidence * 100,
matchReason: group.matchReason
}));
duplicateGroups.value = convertedGroups;
hasScanned.value = true;
} else {
error.value = response.error || 'Failed to find duplicates';
@@ -179,7 +192,7 @@ const mergeDuplicates = async (group, index) => {
try {
const duplicateIds = group.duplicates.map(d => d.record.Id);
const response = await $fetch('/api/admin/duplicates/merge', {
const response = await $fetch('/api/interests/duplicates/merge', {
method: 'POST',
body: {
masterId: group.master.Id,