From 69f131392f620d9f88572ce591f055d4ca57b3b4 Mon Sep 17 00:00:00 2001 From: G Date: Mon, 13 May 2024 14:16:47 +0330 Subject: [PATCH] confirm/provider fix --- src/features/children/children.controller.ts | 1 - src/features/comment/comment.service.ts | 2 - src/features/gateway/gatway.controller.ts | 1 - src/features/need/need.controller.ts | 5 +- src/features/provider/provider.service.ts | 5 +- src/features/sync/sync.service.ts | 91 +++++++++++++------- src/features/user/user.controller.ts | 2 - 7 files changed, 66 insertions(+), 41 deletions(-) diff --git a/src/features/children/children.controller.ts b/src/features/children/children.controller.ts index 7032b83c0..75dcdae67 100644 --- a/src/features/children/children.controller.ts +++ b/src/features/children/children.controller.ts @@ -696,7 +696,6 @@ export class ChildrenController { ); const names = confirmedNames.concat(preNames); - console.log(names); // to minimize human mistakes, we also compare the last 3 chars - همادخت vs هُمادخت const found = names.filter((n) => diff --git a/src/features/comment/comment.service.ts b/src/features/comment/comment.service.ts index 5d7f1d278..b90f85f28 100644 --- a/src/features/comment/comment.service.ts +++ b/src/features/comment/comment.service.ts @@ -60,8 +60,6 @@ export class CommentService { content: details.message, flaskNeedId: details.flaskNeedId, }); - console.log('theNeed.id'); - console.log(theComment); theComment.need = theNeed; theComment.user = theUser; return await this.commentRepository.save(theComment); diff --git a/src/features/gateway/gatway.controller.ts b/src/features/gateway/gatway.controller.ts index e4067ae2f..6680cc6bb 100644 --- a/src/features/gateway/gatway.controller.ts +++ b/src/features/gateway/gatway.controller.ts @@ -85,7 +85,6 @@ export class GateWayController implements OnModuleInit { this.checkConnection(); console.log('\x1b[36m%s\x1b[0m', `Checking Unread Tickets...`); const myTickets = await this.ticketService.getUserTickets(body.flaskUserId); - console.log(myTickets.length); const unReads = ticketNotifications(myTickets, body.flaskUserId); if (unReads && unReads.length > 0) { diff --git a/src/features/need/need.controller.ts b/src/features/need/need.controller.ts index 406e2fc64..0d31580f7 100644 --- a/src/features/need/need.controller.ts +++ b/src/features/need/need.controller.ts @@ -261,7 +261,6 @@ export class NeedController { contentType: false, }, }; - // create flask child const { data } = await axios.patch( `https://api.sayapp.company/api/v2/need/confirm/needId=${needId}`, {}, @@ -377,7 +376,7 @@ export class NeedController { toBeConfirmed.list.push({ limit: null, validCount: null, - need, + need:fetchedNeed, duplicates: null, errorMsg: validatedNeed.message, }); @@ -462,7 +461,7 @@ export class NeedController { myList.push({ limit, validCount, - need, + need: fetchedNeed, duplicates: validatedDups, errorMsg, possibleMissMatch: diffCatSimilarity.map((n) => { diff --git a/src/features/provider/provider.service.ts b/src/features/provider/provider.service.ts index 3fe47c4c6..ffe59bd45 100644 --- a/src/features/provider/provider.service.ts +++ b/src/features/provider/provider.service.ts @@ -72,12 +72,13 @@ export class ProviderService { flaskNeedId: number, nestProviderId: string, ): Promise { - const newProvider = this.providerJoinNeedRepository.create({ + const rel = this.providerJoinNeedRepository.create({ flaskNeedId, nestProviderId, }); - return this.providerJoinNeedRepository.save(newProvider); + return this.providerJoinNeedRepository.save(rel); } + // -------------------------------------------------------------------------------- // createProvider(providerDetails: ProviderParams): Promise { const newProvider = this.providerRepository.create({ diff --git a/src/features/sync/sync.service.ts b/src/features/sync/sync.service.ts index 32470ca74..5fd7205fd 100644 --- a/src/features/sync/sync.service.ts +++ b/src/features/sync/sync.service.ts @@ -599,42 +599,73 @@ export class SyncService { } //--------------------------------------------Provider------------------------------------- + // Social worker add the relationship when adding flask need at panel. + // We fetch the created relation to attach that provider to the nest need let theNestProvider: ProviderEntity; const nestProviderNeedRelation = await this.providerService.getProviderNeedRelationById(flaskNeed.id); // Needs before panel version 2.0.0 does not have providers, we create them here! sry :( - if (!nestProviderNeedRelation && flaskNeed.type === NeedTypeEnum.PRODUCT) { - theNestProvider = await this.providerService.getProviderByName( - 'Digikala', - ); - if (!theNestProvider) { - console.log('\x1b[36m%s\x1b[0m', 'Creating a provider ...\n'); - - theNestProvider = await this.providerService.createProvider({ - name: 'Digikala', - description: 'N/A', - address: 'N/A', - website: 'https://digikala.com', - type: NeedTypeEnum.PRODUCT, - typeName: NeedTypeDefinitionEnum.PRODUCT, - city: 135129, - state: 3945, - country: 103, - logoUrl: 'N/A', - isActive: true, - }); - console.log('\x1b[36m%s\x1b[0m', 'Created a provider ...\n'); + if (flaskNeed.type === NeedTypeEnum.PRODUCT) { + if (!nestProviderNeedRelation) { + theNestProvider = await this.providerService.getProviderByName( + 'Digikala', + ); + if (!theNestProvider) { + console.log('\x1b[36m%s\x1b[0m', 'Creating a provider ...\n'); + + theNestProvider = await this.providerService.createProvider({ + name: 'Digikala', + description: 'N/A', + address: 'N/A', + website: 'https://digikala.com', + type: NeedTypeEnum.PRODUCT, + typeName: NeedTypeDefinitionEnum.PRODUCT, + city: 135129, + state: 3945, + country: 103, + logoUrl: 'N/A', + isActive: true, + }); + console.log('\x1b[36m%s\x1b[0m', 'Created a provider ...\n'); + } + } else if (nestProviderNeedRelation) { + theNestProvider = await this.providerService.getProviderById( + nestProviderNeedRelation.nestProviderId, + ); + } else if (theNestProvider) { + console.log('\x1b[36m%s\x1b[0m', 'Skipped provider ...\n'); + } + } else if (flaskNeed.type === NeedTypeEnum.SERVICE) { + if (!nestProviderNeedRelation) { + theNestProvider = await this.providerService.getProviderByName( + 'NoName', + ); + if (!theNestProvider) { + console.log('\x1b[36m%s\x1b[0m', 'Creating a provider ...\n'); + + theNestProvider = await this.providerService.createProvider({ + name: 'NoName', + description: 'N/A', + address: 'N/A', + website: 'https://saydao.org', + type: NeedTypeEnum.SERVICE, + typeName: NeedTypeDefinitionEnum.PRODUCT, + city: 135129, + state: 3945, + country: 103, + logoUrl: 'N/A', + isActive: true, + }); + console.log('\x1b[36m%s\x1b[0m', 'Created a provider ...\n'); + } + } else if (nestProviderNeedRelation) { + theNestProvider = await this.providerService.getProviderById( + nestProviderNeedRelation.nestProviderId, + ); + } else if (theNestProvider) { + console.log('\x1b[36m%s\x1b[0m', 'Skipped provider ...\n'); } - } else if ( - nestProviderNeedRelation && - flaskNeed.type === NeedTypeEnum.PRODUCT - ) { - theNestProvider = await this.providerService.getProviderById( - nestProviderNeedRelation.nestProviderId, - ); - } else if (theNestProvider) { - console.log('\x1b[36m%s\x1b[0m', 'Skipped provider ...\n'); } //--------------------------------------------Need------------------------------------- let nestNeed = await this.needService.getNeedByFlaskId(flaskNeed.id); diff --git a/src/features/user/user.controller.ts b/src/features/user/user.controller.ts index ffb026ab1..92f5d5dd0 100644 --- a/src/features/user/user.controller.ts +++ b/src/features/user/user.controller.ts @@ -325,8 +325,6 @@ export class UserController { const needTickets = tickets.filter( (t) => allNeeds[i][k].id === t.flaskNeedId, ); - console.log(needTickets); - // signatures only at the my page last column // UPDATE: we decided to snot show signatures on page reload since they have a dedicated page // If you removing the code, remember need.signatures must be fixed on front-end side as well