Skip to content

Commit

Permalink
confirm/provider fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed May 13, 2024
1 parent 71f8b06 commit 69f1313
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/features/children/children.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 0 additions & 2 deletions src/features/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion src/features/gateway/gatway.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions src/features/need/need.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
{},
Expand Down Expand Up @@ -377,7 +376,7 @@ export class NeedController {
toBeConfirmed.list.push({
limit: null,
validCount: null,
need,
need:fetchedNeed,
duplicates: null,
errorMsg: validatedNeed.message,
});
Expand Down Expand Up @@ -462,7 +461,7 @@ export class NeedController {
myList.push({
limit,
validCount,
need,
need: fetchedNeed,
duplicates: validatedDups,
errorMsg,
possibleMissMatch: diffCatSimilarity.map((n) => {
Expand Down
5 changes: 3 additions & 2 deletions src/features/provider/provider.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ export class ProviderService {
flaskNeedId: number,
nestProviderId: string,
): Promise<ProviderJoinNeedEntity> {
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<ProviderEntity> {
const newProvider = this.providerRepository.create({
Expand Down
91 changes: 61 additions & 30 deletions src/features/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/features/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69f1313

Please sign in to comment.