dublicate excel
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class ServiceSkillDuplicateCountDto {
|
||||
@ApiProperty({ example: 3 })
|
||||
count: number;
|
||||
}
|
||||
@@ -36,6 +36,7 @@ import { CreateServiceSkillDto } from './dto/create-service-skill.dto';
|
||||
import { CreateServiceDto } from './dto/create-service.dto';
|
||||
import { ImportServiceSkillsResultDto } from './dto/import-service-skills-result.dto';
|
||||
import { RemoveDuplicateServiceSkillsResultDto } from './dto/remove-duplicate-service-skills-result.dto';
|
||||
import { ServiceSkillDuplicateCountDto } from './dto/service-skill-duplicate-count.dto';
|
||||
import {
|
||||
CreateSalonServiceDto,
|
||||
FindSalonServicesQueryDto,
|
||||
@@ -212,6 +213,14 @@ export class ServicesController {
|
||||
return this.servicesService.importSkillsFromExcel(serviceId, file, user);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SERVICES_WRITE)
|
||||
@ApiStandardOkResponse(ServiceSkillDuplicateCountDto)
|
||||
@Get(':serviceId/skills/duplicates/count')
|
||||
countDuplicateSkills(@Param('serviceId', ParseUUIDPipe) serviceId: string) {
|
||||
return this.servicesService.countDuplicateSkills(serviceId);
|
||||
}
|
||||
|
||||
@Roles(UserRole.ADMIN)
|
||||
@Permissions(PermissionCode.SERVICES_DELETE)
|
||||
@ApiStandardOkResponse(RemoveDuplicateServiceSkillsResultDto)
|
||||
|
||||
@@ -272,6 +272,26 @@ export class ServicesService {
|
||||
return { removed: duplicateIds.length };
|
||||
}
|
||||
|
||||
async countDuplicateSkills(serviceId: string): Promise<{ count: number }> {
|
||||
await this.ensureServiceExists(serviceId);
|
||||
|
||||
const skills = await this.findSkills(serviceId);
|
||||
const seenTitles = new Set<string>();
|
||||
let count = 0;
|
||||
|
||||
for (const skill of skills) {
|
||||
const normalizedTitle = this.normalizeSkillTitle(skill.title);
|
||||
if (seenTitles.has(normalizedTitle)) {
|
||||
count += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
seenTitles.add(normalizedTitle);
|
||||
}
|
||||
|
||||
return { count };
|
||||
}
|
||||
|
||||
async findSkills(serviceId: string): Promise<ServiceSkill[]> {
|
||||
await this.ensureServiceExists(serviceId);
|
||||
return this.serviceSkillsRepository.find({
|
||||
@@ -523,7 +543,13 @@ export class ServicesService {
|
||||
}
|
||||
|
||||
private normalizeSkillTitle(title: string): string {
|
||||
return normalizeDigits(title).trim().toLowerCase().replace(/\s+/g, ' ');
|
||||
return normalizeDigits(title)
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[يى]/g, 'ی')
|
||||
.replace(/ك/g, 'ک')
|
||||
.replace(/\u200c/g, '')
|
||||
.replace(/\s+/g, ' ');
|
||||
}
|
||||
|
||||
private async ensureUniqueSkillTitle(
|
||||
|
||||
Reference in New Issue
Block a user