From d4bde28eece774e49cc6a80c8350ad411536c0ff Mon Sep 17 00:00:00 2001 From: RexBearIU Date: Thu, 15 Aug 2024 17:43:27 +0800 Subject: [PATCH 1/2] fix: report formatter fixed --- package.json | 2 +- src/lib/utils/formatter/report.formatter.ts | 12 ++-------- src/lib/utils/repo/report.repo.ts | 3 +-- .../[companyId]/report/[reportId]/index.ts | 22 +++++++++++-------- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 8d83c2ddc..b2693f385 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iSunFA", - "version": "0.8.0+7", + "version": "0.8.0+8", "private": false, "scripts": { "dev": "next dev", diff --git a/src/lib/utils/formatter/report.formatter.ts b/src/lib/utils/formatter/report.formatter.ts index fed53df1b..c6849a8dd 100644 --- a/src/lib/utils/formatter/report.formatter.ts +++ b/src/lib/utils/formatter/report.formatter.ts @@ -1,8 +1,6 @@ import { ReportSheetType, ReportType } from '@/constants/report'; import { IPaginatedReport, IReport, IReportIncludeCompanyProject } from '@/interfaces/report'; import { isReportSheetType, isReportType } from '@/lib/utils/type_guard/report'; -import { IAccountReadyForFrontend } from '@/interfaces/accounting_account'; -import { isIAccountReadyForFrontendArray } from '@/lib/utils/type_guard/account'; export function formatIReport(report: IReportIncludeCompanyProject): IReport { const type: ReportType = isReportType(report.reportType) @@ -12,14 +10,8 @@ export function formatIReport(report: IReportIncludeCompanyProject): IReport { ? report.reportType : ReportSheetType.BALANCE_SHEET; const reportContent = JSON.parse(report.content as string); - - // Info: (20240729 - Murky) Bad code, not robust - const content: IAccountReadyForFrontend[] = isIAccountReadyForFrontendArray(reportContent.content) - ? reportContent.content - : []; - + const { content, otherInfo, ...rest } = reportContent; // Info: (20240729 - Murky) Bad code, not robust - const otherInfo = reportContent.otherInfo || {}; const project = report.project ? { id: report.project.id.toString(), @@ -47,7 +39,7 @@ export function formatIReport(report: IReportIncludeCompanyProject): IReport { downloadLink: report.downloadLink || '', blockChainExplorerLink: report.blockChainExplorerLink || '', evidenceId: report.evidenceId || '', - content, + content: content ?? rest, otherInfo, createdAt: report.createdAt, updatedAt: report.updatedAt, diff --git a/src/lib/utils/repo/report.repo.ts b/src/lib/utils/repo/report.repo.ts index 076a49c64..2a658ecc8 100644 --- a/src/lib/utils/repo/report.repo.ts +++ b/src/lib/utils/repo/report.repo.ts @@ -34,14 +34,13 @@ export async function findFirstReportByFromTo( return report; } -export async function findUniqueReportById(companyId: number, reportId: number) { +export async function findUniqueReportById(reportId: number) { let report: IReportIncludeCompanyProject | null = null; try { report = await prisma.report.findUnique({ where: { id: reportId, - companyId, OR: [{ deletedAt: 0 }, { deletedAt: null }], }, include: { diff --git a/src/pages/api/v1/company/[companyId]/report/[reportId]/index.ts b/src/pages/api/v1/company/[companyId]/report/[reportId]/index.ts index a04885e0c..c0d06da62 100644 --- a/src/pages/api/v1/company/[companyId]/report/[reportId]/index.ts +++ b/src/pages/api/v1/company/[companyId]/report/[reportId]/index.ts @@ -49,8 +49,8 @@ export function getReportTypeFromReport(report: IReport | null) { return reportType; } -export async function getPeriodReport(companyId: number, reportId: number) { - const curPeriodReportFromDB = await findUniqueReportById(companyId, reportId); +export async function getPeriodReport(reportId: number) { + const curPeriodReportFromDB = await findUniqueReportById(reportId); let curPeriodReport: IReport | null = null; let company: Company | null = null; if (curPeriodReportFromDB) { @@ -209,16 +209,17 @@ export function formatPayloadFromIReport(report: IReport, company: Company): Fin export async function handleGETRequest( companyId: number, req: NextApiRequest -): Promise { +): Promise { const { reportIdNumber } = formatGetRequestQueryParams(req); let payload = null; if (reportIdNumber !== null) { - const { curPeriodReport, company } = await getPeriodReport(companyId, reportIdNumber); - - if (curPeriodReport && company) { + const { curPeriodReport, company } = await getPeriodReport(reportIdNumber); + if (curPeriodReport && company && curPeriodReport.reportType !== ReportSheetType.REPORT_401) { payload = formatPayloadFromIReport(curPeriodReport, company); + } else { + payload = curPeriodReport; } } @@ -227,10 +228,10 @@ export async function handleGETRequest( export default async function handler( req: NextApiRequest, - res: NextApiResponse> + res: NextApiResponse> ) { let statusMessage: string = STATUS_MESSAGE.BAD_REQUEST; - let payload: FinancialReport | null = null; + let payload: FinancialReport | IReport | null = null; try { const session = await getSession(req, res); const { userId, companyId } = session; @@ -258,6 +259,9 @@ export default async function handler( console.log(error); statusMessage = error.message; } - const { httpCode, result } = formatApiResponse(statusMessage, payload); + const { httpCode, result } = formatApiResponse( + statusMessage, + payload + ); res.status(httpCode).json(result); } From fecf870810eb4f9eb4551aec3ca970cdd89e8b3c Mon Sep 17 00:00:00 2001 From: Luphia Chang Date: Thu, 15 Aug 2024 20:28:17 +0800 Subject: [PATCH 2/2] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b2693f385..e946ef1a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iSunFA", - "version": "0.8.0+8", + "version": "0.8.0+9", "private": false, "scripts": { "dev": "next dev",