diff --git a/src/features/need/need.controller.ts b/src/features/need/need.controller.ts index d5cf4c7d9..f1841f825 100644 --- a/src/features/need/need.controller.ts +++ b/src/features/need/need.controller.ts @@ -314,9 +314,14 @@ export class NeedController { // 1- sync & validate need let fetchedNeed = await this.needService.getNeedByFlaskId(need.id); + // Just in case + const fetchedProviderRel = + await this.providerService.getProviderNeedRelationById(need.id); if ( !fetchedNeed || !fetchedNeed.provider || + (fetchedProviderRel && + fetchedNeed.provider.id != fetchedProviderRel.nestProviderId) || fetchedNeed.status !== need.status || fetchedNeed.category !== need.category || fetchedNeed.type !== need.type || @@ -342,12 +347,13 @@ export class NeedController { // 0- ticket if not a valid need and not ticketed yet if (!validatedNeed.isValidNeed) { - const needTickets = await this.ticketService.getTicketsByNeed( + let needTickets = await this.ticketService.getTicketsByNeed( validatedNeed.needId, ); const ticketError = needTickets.find( (t) => t.lastAnnouncement === AnnouncementEnum.ERROR, ); + // create ticket if already has not if (!ticketError) { console.log('\x1b[36m%s\x1b[0m', 'Creating Ticket Content ...\n'); @@ -379,12 +385,20 @@ export class NeedController { 'Need will be deleted from front-end...\n', ); } - toBeConfirmed.list.push({ + needTickets = await this.ticketService.getTicketsByNeed( + validatedNeed.needId, + ); + ticket = needTickets.find( + (t) => t.lastAnnouncement === AnnouncementEnum.ERROR, + ); + myList.push({ limit: null, validCount: null, need: fetchedNeed, duplicates: null, errorMsg: validatedNeed.message, + possibleMissMatch: [], + ticket, }); console.log('\x1b[36m%s\x1b[0m', 'Skipping need...\n'); continue; @@ -480,6 +494,7 @@ export class NeedController { isConfirmed: n.confirmDate && true, }; }), + ticket, }); } diff --git a/src/utils/needConfirm.ts b/src/utils/needConfirm.ts index f44aefd7a..e1f7a8d93 100644 --- a/src/utils/needConfirm.ts +++ b/src/utils/needConfirm.ts @@ -29,7 +29,7 @@ const BASE_AGE_OF_DUPLICATE_2 = 30; const BASE_AGE_OF_DUPLICATE_3 = 30; const SIMILAR_URL_PERCENTAGE = 57; // percentage -const SIMILAR_TXT_PERCENTAGE = 15; // percentage +const SIMILAR_TXT_PERCENTAGE = 10; // percentage export const SIMILAR_NAME_LIMIT_PRODUCT = 20; export const SIMILAR_NAME_LIMIT_SERVICE = 10; export const GRACE_PERIOD = 15; // days left after ticket to fix the problem mentioned in ticket @@ -84,7 +84,7 @@ export async function validateNeed( }; return result; } - // validate SW information/details + // validate need information/details const list = [ 'شلوار', 'لباس زیر', @@ -110,9 +110,9 @@ export async function validateNeed( if ( type === NeedTypeEnum.PRODUCT && category === CategoryEnum.GROWTH && - Math.max(...listResult) > SIMILAR_TXT_PERCENTAGE && - !details && - !information + Math.max(...listResult) >= SIMILAR_TXT_PERCENTAGE && + (!details || details.split(' ').join('').length < 3) && + (!information || information.split(' ').join('').length < 3) ) { const createTicketDetails: CreateTicketParams = { title: `More info`,