Skip to content

Commit

Permalink
Merge staging into master (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnwebdev authored Oct 20, 2023
2 parents b6969eb + 1e4d463 commit 773acb9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
10 changes: 8 additions & 2 deletions src/modules/netvisor/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@nestjs/common';
import get from 'lodash/get';

import { XmlJsService } from '../xml-js/service';

Expand Down Expand Up @@ -109,8 +110,13 @@ export class NetvisorFetcher {
xmlString,
);

if (Array.isArray(data.Root.PurchaseInvoiceList[0].PurchaseInvoice)) {
return data.Root.PurchaseInvoiceList[0].PurchaseInvoice.map((invoice) => {
const purchaseInvoice = get(
data,
'Root.PurchaseInvoiceList[0].PurchaseInvoice',
);

if (Array.isArray(purchaseInvoice)) {
return purchaseInvoice.map((invoice) => {
return invoice.NetvisorKey[0];
});
}
Expand Down
51 changes: 33 additions & 18 deletions src/modules/netvisor/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { PaidStatus } from 'hero24-types';

import { CustomScheduleService } from '../custom-schedule/service';
Expand All @@ -14,6 +14,8 @@ import { OfferRequestService } from '$modules/offer-request/offer-request.servic

@Injectable()
export class NetvisorSchedule {
private readonly logger = new Logger(NetvisorSchedule.name);

constructor(
private readonly netvisorFetcher: NetvisorFetcher,
private readonly offerService: OfferService,
Expand All @@ -32,27 +34,40 @@ export class NetvisorSchedule {
}

async updatePaidStatus(): Promise<void> {
const startDate = getScheduleFetchDate(
this.customScheduleService.getLastJobDate(NETVISOR_FETCH_JOB),
);
try {
const startDate = getScheduleFetchDate(
this.customScheduleService.getLastJobDate(NETVISOR_FETCH_JOB),
);

const paidInvoices = await this.netvisorFetcher.fetchPurchaseInvoiceList(
startDate,
);
const paidInvoices = await this.netvisorFetcher.fetchPurchaseInvoiceList(
startDate,
);

if (!paidInvoices) {
return;
}
if (!paidInvoices) {
return;
}

const offers = await this.offerService.getOffersByInvoiceIds(paidInvoices);
const offers = await this.offerService.getOffersByInvoiceIds(
paidInvoices,
);

offers.forEach((offer) => {
const { offerRequestId } = offer.data.initial;
const promises = offers.map(async (offer) => {
try {
const { offerRequestId } = offer.data.initial;

void this.offerRequestService.updatePaidStatus(
offerRequestId,
PaidStatus.PAID,
);
});
await this.offerRequestService.updatePaidStatus(
offerRequestId,
PaidStatus.PAID,
);
} catch (error) {
this.logger.error(error);
this.logger.debug(offer);
}
});

await Promise.all(promises);
} catch (error) {
this.logger.error(error);
}
}
}

0 comments on commit 773acb9

Please sign in to comment.