Skip to content

Commit

Permalink
provider fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed May 26, 2024
1 parent d152653 commit 7af7543
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/features/need/need.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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');
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -480,6 +494,7 @@ export class NeedController {
isConfirmed: n.confirmDate && true,
};
}),
ticket,
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils/needConfirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,7 +84,7 @@ export async function validateNeed(
};
return result;
}
// validate SW information/details
// validate need information/details
const list = [
'شلوار',
'لباس زیر',
Expand All @@ -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`,
Expand Down

0 comments on commit 7af7543

Please sign in to comment.