Skip to content

Commit

Permalink
Merge pull request #51 from donghquinn/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
donghquinn authored Feb 17, 2024
2 parents 0f44124 + fca3d94 commit 135b96a
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 13 deletions.
24 changes: 20 additions & 4 deletions src/providers/news/geek/geek-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)),
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/providers/news/geek/geek.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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', {
Expand Down
24 changes: 20 additions & 4 deletions src/providers/news/hacker/hacker-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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)),
);
}
Expand Down
10 changes: 8 additions & 2 deletions src/providers/news/hacker/hacker.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ 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,
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);

NewsLogger.info('[Hackers] Get Total Count: %o', {
total,
});

return { result, total };
} catch (error) {
Expand Down
7 changes: 6 additions & 1 deletion src/providers/news/ml/machine.pvd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ 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);

NewsLogger.info('[ML] Get Total Count: %o', {
total,
});

return { result, total };
} catch (error) {
Expand Down
18 changes: 17 additions & 1 deletion src/providers/news/ml/ml-prisma.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand Down

0 comments on commit 135b96a

Please sign in to comment.