From 247b1a6847663c98c19651fb17290db2312d7470 Mon Sep 17 00:00:00 2001 From: donghquinn Date: Sun, 18 Feb 2024 00:18:02 +0900 Subject: [PATCH 1/2] wip: total count --- src/providers/news/geek/geek-prisma.lib.ts | 24 +++++++++++++++---- src/providers/news/geek/geek.pvd.ts | 8 ++++++- .../news/hacker/hacker-prisma.lib.ts | 24 +++++++++++++++---- src/providers/news/hacker/hacker.pvd.ts | 4 +++- src/providers/news/ml/machine.pvd.ts | 3 ++- src/providers/news/ml/ml-prisma.lib.ts | 18 +++++++++++++- 6 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/providers/news/geek/geek-prisma.lib.ts b/src/providers/news/geek/geek-prisma.lib.ts index 359e16e..18cac20 100644 --- a/src/providers/news/geek/geek-prisma.lib.ts +++ b/src/providers/news/geek/geek-prisma.lib.ts @@ -21,6 +21,22 @@ export class GeekPrismaLibrary extends PrismaClient { skip: (Number(page) - 1) * Number(size), }); + return result; + } catch (error) { + NewsLogger.error('[HADA] Bring Geek News Error: %o', { + error, + }); + + throw new PrismaError( + '[HADA] Bring Geek News', + 'Bring Geek News Error. Please Try Again.', + error instanceof Error ? error : new Error(JSON.stringify(error)), + ); + } + } + + async geekNewsCount(startDate: Date, endDate: Date, size: number) { + try { const totalCounts = await this.geek.count({ where: { founded: { @@ -29,15 +45,15 @@ export class GeekPrismaLibrary extends PrismaClient { }, }, }); - return { result, total: Math.ceil(totalCounts / size) }; + return Math.ceil(totalCounts / size); } catch (error) { - NewsLogger.error('[HADA] Bring Geek News Error: %o', { + NewsLogger.error('[HADA] Bring Total Geek News Count Error: %o', { error, }); throw new PrismaError( - '[HADA] Bring Geek News', - 'Bring Geek News Error. Please Try Again.', + '[HADA] Bring Total Geek News Count', + 'Bring Total Geek News Count Error. Please Try Again.', error instanceof Error ? error : new Error(JSON.stringify(error)), ); } diff --git a/src/providers/news/geek/geek.pvd.ts b/src/providers/news/geek/geek.pvd.ts index d877977..278744c 100644 --- a/src/providers/news/geek/geek.pvd.ts +++ b/src/providers/news/geek/geek.pvd.ts @@ -32,7 +32,7 @@ export class GeekProvider { size, }); - const { result, total } = await this.prisma.bringHadaNews(startDate, endDate, page, size); + const result = await this.prisma.bringHadaNews(startDate, endDate, page, size); for (let i = 0; i <= result.length - 1; i += 1) { const isUrlUndefined = result[i].descLink.split('.io/')[1]; @@ -68,6 +68,12 @@ export class GeekProvider { } } + const total = await this.prisma.geekNewsCount(startDate, endDate, size); + + NewsLogger.info('[GEEK] Get Total Count: %o', { + total, + }); + return { result, total }; } catch (error) { NewsLogger.error('[GEEK] Bring Hada News Error: %o', { diff --git a/src/providers/news/hacker/hacker-prisma.lib.ts b/src/providers/news/hacker/hacker-prisma.lib.ts index 607b924..38744c5 100644 --- a/src/providers/news/hacker/hacker-prisma.lib.ts +++ b/src/providers/news/hacker/hacker-prisma.lib.ts @@ -21,6 +21,22 @@ export class HackerPrismaLibrary extends PrismaClient { skip: (Number(page) - 1) * Number(size), }); + return result; + } catch (error) { + NewsLogger.error('[ML] Bring Geek News Error: %o', { + error, + }); + + throw new PrismaError( + '[ML] Bring Geek News', + 'Bring Geek News Error. Please Try Again.', + error instanceof Error ? error : new Error(JSON.stringify(error)), + ); + } + } + + async hackerNewsCount(startDate: Date, endDate: Date, size: number) { + try { const totalCounts = await this.hackers.count({ where: { founded: { @@ -30,15 +46,15 @@ export class HackerPrismaLibrary extends PrismaClient { }, }); - return { result, total: Math.ceil(totalCounts / size) }; + return Math.ceil(totalCounts / size); } catch (error) { - NewsLogger.error('[ML] Bring Geek News Error: %o', { + NewsLogger.error('[HADA] Bring Total Geek News Count Error: %o', { error, }); throw new PrismaError( - '[ML] Bring Geek News', - 'Bring Geek News Error. Please Try Again.', + '[HADA] Bring Total Geek News Count', + 'Bring Total Geek News Count Error. Please Try Again.', error instanceof Error ? error : new Error(JSON.stringify(error)), ); } diff --git a/src/providers/news/hacker/hacker.pvd.ts b/src/providers/news/hacker/hacker.pvd.ts index 2fd7cc1..79d2823 100755 --- a/src/providers/news/hacker/hacker.pvd.ts +++ b/src/providers/news/hacker/hacker.pvd.ts @@ -47,7 +47,9 @@ export class HackersNewsProvider { size, }); - const { result, total } = await this.prisma.bringHackerNews(startDate, endDate, page, size); + const result = await this.prisma.bringHackerNews(startDate, endDate, page, size); + + const total = await this.prisma.hackerNewsCount(startDate, endDate, size); return { result, total }; } catch (error) { diff --git a/src/providers/news/ml/machine.pvd.ts b/src/providers/news/ml/machine.pvd.ts index 6af5b9b..17b795f 100644 --- a/src/providers/news/ml/machine.pvd.ts +++ b/src/providers/news/ml/machine.pvd.ts @@ -27,7 +27,8 @@ export class MachineLearningProvider { size, }); - const { result, total } = await this.prisma.bringMlNews(startDate, endDate, page, size); + const result = await this.prisma.bringMlNews(startDate, endDate, page, size); + const total = await this.prisma.mlTotalCount(startDate, endDate, size); return { result, total }; } catch (error) { diff --git a/src/providers/news/ml/ml-prisma.lib.ts b/src/providers/news/ml/ml-prisma.lib.ts index be5305a..d848287 100644 --- a/src/providers/news/ml/ml-prisma.lib.ts +++ b/src/providers/news/ml/ml-prisma.lib.ts @@ -26,6 +26,22 @@ export class MlPrismaLibrary extends PrismaClient { skip: (Number(page) - 1) * Number(size), }); + return result; + } catch (error) { + NewsLogger.error('[ML] Bring Geek News Error: %o', { + error, + }); + + throw new PrismaError( + '[ML] Bring Geek News', + 'Bring Geek News Error. Please Try Again.', + error instanceof Error ? error : new Error(JSON.stringify(error)), + ); + } + } + + async mlTotalCount(startDate: Date, endDate: Date, size: number) { + try { const totalCounts = await this.machineNews.count({ where: { founded: { @@ -35,7 +51,7 @@ export class MlPrismaLibrary extends PrismaClient { }, }); - return { result, total: Math.ceil(totalCounts / size) }; + return Math.ceil(totalCounts / size); } catch (error) { NewsLogger.error('[ML] Bring Geek News Error: %o', { error, From fca3d9458c235fb8d4160a6e7acda386a66d0692 Mon Sep 17 00:00:00 2001 From: donghquinn Date: Sun, 18 Feb 2024 00:18:47 +0900 Subject: [PATCH 2/2] wip: fixing --- src/providers/news/hacker/hacker.pvd.ts | 6 +++++- src/providers/news/ml/machine.pvd.ts | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/providers/news/hacker/hacker.pvd.ts b/src/providers/news/hacker/hacker.pvd.ts index 79d2823..832978e 100755 --- a/src/providers/news/hacker/hacker.pvd.ts +++ b/src/providers/news/hacker/hacker.pvd.ts @@ -40,7 +40,7 @@ export class HackersNewsProvider { const startDate = startOfDay(new Date(yesterday)); const endDate = endOfDay(new Date(yesterday)); - NewsLogger.info('[Hacker] YesterDay: %o', { + NewsLogger.info('[Hackers] YesterDay: %o', { start: startDate, end: endDate, page, @@ -51,6 +51,10 @@ export class HackersNewsProvider { const total = await this.prisma.hackerNewsCount(startDate, endDate, size); + NewsLogger.info('[Hackers] Get Total Count: %o', { + total, + }); + return { result, total }; } catch (error) { NewsLogger.error('[Hackers] Bring Hacker News Error: %o', { diff --git a/src/providers/news/ml/machine.pvd.ts b/src/providers/news/ml/machine.pvd.ts index 17b795f..4d6d2d8 100644 --- a/src/providers/news/ml/machine.pvd.ts +++ b/src/providers/news/ml/machine.pvd.ts @@ -30,6 +30,10 @@ export class MachineLearningProvider { const result = await this.prisma.bringMlNews(startDate, endDate, page, size); const total = await this.prisma.mlTotalCount(startDate, endDate, size); + NewsLogger.info('[ML] Get Total Count: %o', { + total, + }); + return { result, total }; } catch (error) { NewsLogger.error('[ML] Get Latest Machine Learning News Error: %o', {