From e97ebcbfecb8a5f7e0fe114abec8658075c63d9f Mon Sep 17 00:00:00 2001 From: devsoopark Date: Thu, 28 May 2020 01:17:40 +0900 Subject: [PATCH 1/3] Remove return value from addLikeField method --- server/src/services/product.ts | 13 +++++-------- server/src/services/user.ts | 14 +++++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/server/src/services/product.ts b/server/src/services/product.ts index 94922c70..60ac78e9 100644 --- a/server/src/services/product.ts +++ b/server/src/services/product.ts @@ -54,7 +54,7 @@ export default class ProductService { product.productInfoProvidedNoticeView.basic, })); - products = await this.addLikeField(products); + await this.addLikeField(products); return { products }; } catch (e) { @@ -104,7 +104,7 @@ export default class ProductService { throw new NotFoundError('Product is not exist'); } let products: IProductDTO[] = [productRecord.toObject()]; - products = await this.addLikeField(products); + await this.addLikeField(products); const product = products[0]; return { @@ -125,7 +125,7 @@ export default class ProductService { } } - public async addLikeField(products: IProductDTO[]): Promise { + public async addLikeField(products: IProductDTO[]): Promise { try { const userLikeRecord = await this.userModel .findOne({ @@ -146,12 +146,9 @@ export default class ProductService { ); const likeSet = new Set(likeList); - products = products.map((product) => { + for (const product of products) { product.like = likeSet.has(product.productNo as number) ? true : false; - return product as IProductDTO; - }); - - return products; + } } catch (e) { this.logger.error(e); throw e; diff --git a/server/src/services/user.ts b/server/src/services/user.ts index 1c8ba3a8..26ff3ff5 100644 --- a/server/src/services/user.ts +++ b/server/src/services/user.ts @@ -59,7 +59,9 @@ export default class UserService { weight, }: any): Promise => { return new Promise(async (resolve, reject) => { - const userRecord = await this.userModel.findOne({ userName: config.personaName }); + const userRecord = await this.userModel.findOne({ + userName: config.personaName, + }); if (!userRecord) { reject('User is not exist'); } @@ -138,17 +140,19 @@ export default class UserService { * @param productNo */ public async clickLog(productNo: number): Promise { - const userLog: UserLog = { userName: config.personaName, type: 'click_log', item: String(productNo) }; + const userLog: UserLog = { + userName: config.personaName, + type: 'click_log', + item: String(productNo), + }; try { const result = await this.addWeight(productNo, config.clicklogWeight); await kafka(config.personaId, userLog); return result; - } catch (e) { this.logger.error(e); } - } /** @@ -317,7 +321,7 @@ export default class UserService { result = await addRemainder(remainder, result); } - result = await this.productService.addLikeField(result); + await this.productService.addLikeField(result); return result; } catch (e) { From bb94b0ed8a1d50d9ae6413409282e5e478c691ee Mon Sep 17 00:00:00 2001 From: devsoopark Date: Thu, 28 May 2020 15:25:16 +0900 Subject: [PATCH 2/3] Add chageImageUrl method --- server/src/interfaces/product.ts | 4 ++-- server/src/services/product.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/src/interfaces/product.ts b/server/src/interfaces/product.ts index 1619777f..f1116a44 100644 --- a/server/src/interfaces/product.ts +++ b/server/src/interfaces/product.ts @@ -10,10 +10,10 @@ export interface IProduct { export interface IProductDTO { category: Object; - productNo: Number; + productNo: number; name: String; salePrice: Number; - productImages: Object; + productImages: any; productInfoProvidedNoticeView: any; like?: Boolean; } diff --git a/server/src/services/product.ts b/server/src/services/product.ts index 60ac78e9..cbcf5806 100644 --- a/server/src/services/product.ts +++ b/server/src/services/product.ts @@ -155,6 +155,13 @@ export default class ProductService { } } + public changeImageUrl(products: IProductDTO[]): void { + for (const product of products) { + const index = product.productNo % 61; + product.productImages[0].url = `https://naver.github.io/egjs-infinitegrid/assets/image/${index}.jpg`; + } + } + public async create(productDTO: IProductDTO): Promise<{ product: IProduct }> { try { this.logger.silly('Creating user db record'); From 49a7d872a4c3a4a0396dfc97e7eeb0c743a95c54 Mon Sep 17 00:00:00 2001 From: devsoopark Date: Thu, 28 May 2020 15:45:39 +0900 Subject: [PATCH 3/3] Apply chageImageUrl method --- server/src/services/product.ts | 21 +++++++++++++++------ server/src/services/user.ts | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/server/src/services/product.ts b/server/src/services/product.ts index cbcf5806..f8ae02d3 100644 --- a/server/src/services/product.ts +++ b/server/src/services/product.ts @@ -55,6 +55,7 @@ export default class ProductService { })); await this.addLikeField(products); + this.changeImageUrl(products); return { products }; } catch (e) { @@ -82,12 +83,18 @@ export default class ProductService { .skip(skip); const products = productRecords .map((record) => record.toObject()) - .map((product) => ({ - productId: product._id, - productName: product.name, - productImages: product.productImages[0], - salePrice: Number(product.salePrice), - })); + .map((product) => { + const index = product.productNo % 61; + product.productImages[0].url = `https://naver.github.io/egjs-infinitegrid/assets/image/${index}.jpg`; + + return { + productId: product._id, + productName: product.name, + productImages: product.productImages[0], + salePrice: Number(product.salePrice), + }; + }); + return { products }; } catch (e) { this.logger.error(e); @@ -105,6 +112,8 @@ export default class ProductService { } let products: IProductDTO[] = [productRecord.toObject()]; await this.addLikeField(products); + this.changeImageUrl(products); + const product = products[0]; return { diff --git a/server/src/services/user.ts b/server/src/services/user.ts index 26ff3ff5..36b4bcc3 100644 --- a/server/src/services/user.ts +++ b/server/src/services/user.ts @@ -322,6 +322,7 @@ export default class UserService { } await this.productService.addLikeField(result); + this.productService.changeImageUrl(result); return result; } catch (e) {