Skip to content

Commit

Permalink
feat: 상품 정보 갱신 promise 실패 경우 고려하여 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Muungi committed May 27, 2024
1 parent 6eaf4ab commit 615ba43
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 12 additions & 3 deletions backend/src/cron/cron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Redis from 'ioredis';
import { InjectRedis } from '@songkeys/nestjs-redis';
import { getProductInfo } from 'src/utils/product.info';
import { CacheService } from 'src/cache/cache.service';
import { RecentProductInfoMap } from 'src/types/product';

@Injectable()
export class CronService {
Expand Down Expand Up @@ -70,10 +71,18 @@ export class CronService {
}
}

const recentProductInfoMap: RecentProductInfoMap = recentProductInfo.reduce((map, product) => {
map[product.productId] = { productName: product.productName, imageUrl: product.imageUrl };
return map;
}, {} as RecentProductInfoMap);

totalProducts.sort((a, b) => a.id.localeCompare(b.id));
recentProductInfo.sort((a, b) => a.productId.localeCompare(b.productId));
const infoUpdatedProducts = totalProducts.filter((product, idx) => {
const recentInfo = recentProductInfo[idx];
const infoUpdatedProducts = totalProducts.filter((product) => {
const recentInfo = recentProductInfoMap[product.id];
if (recentInfo === undefined) {
console.log('fail', product.productCode);
return false;
}
if (product.productName !== recentInfo.productName || product.imageUrl !== recentInfo.imageUrl) {
product.productName = recentInfo.productName;
product.imageUrl = recentInfo.imageUrl;
Expand Down
6 changes: 6 additions & 0 deletions backend/src/types/product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type RecentProductInfoMap = {
[key: string]: {
productName: string;
imageUrl: string;
};
};

0 comments on commit 615ba43

Please sign in to comment.