Skip to content

Commit 31b1e6c

Browse files
committed
fix: missing request body schema for excel generator
1 parent 91741e4 commit 31b1e6c

File tree

2 files changed

+85
-7
lines changed

2 files changed

+85
-7
lines changed

src/routes/excelGenerator/excelGeneratorModel.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,87 @@ export const ExcelGeneratorResponseSchema = z.object({
1212
});
1313

1414
// Request Body Schema
15-
export const ExcelGeneratorRequestBodySchema = z.object({});
15+
export const ExcelGeneratorRequestBodySchema = z
16+
.object({
17+
sheetsData: z
18+
.array(
19+
z.object({
20+
sheetName: z.string().openapi({
21+
description: 'The name of the sheet to be created in the Excel file.',
22+
}),
23+
tables: z
24+
.array(
25+
z.object({
26+
title: z.string().optional().openapi({
27+
description: 'The title of the table, which will be displayed in the first row.',
28+
}),
29+
startCell: z.string().openapi({
30+
description: "The starting cell (e.g., 'A1') where the table will begin.",
31+
}),
32+
columns: z
33+
.array(
34+
z.object({
35+
name: z.string().openapi({
36+
description: 'The name of the column.',
37+
}),
38+
type: z.enum(['string', 'number', 'boolean', 'percent', 'currency', 'date']).openapi({
39+
description: 'The data type of the column.',
40+
}),
41+
format: z.string().optional().openapi({
42+
description: "The format of the column (e.g., '0.00%', '$#,##0', etc.).",
43+
}),
44+
})
45+
)
46+
.openapi({
47+
description: 'The list of columns in the table, each with a name, type, and optional format.',
48+
}),
49+
rows: z
50+
.array(
51+
z.array(
52+
z.object({
53+
type: z.enum(['static_value', 'formula']).openapi({
54+
description: 'Indicates whether the cell contains a static value or a formula.',
55+
}),
56+
value: z.string().openapi({
57+
description: 'The actual value or formula for the cell.',
58+
}),
59+
})
60+
)
61+
)
62+
.openapi({
63+
description: 'Array of rows in the table, where each row is an array of cells.',
64+
}),
65+
skipHeader: z.boolean().optional().openapi({
66+
description: 'Whether to skip the header row for this table.',
67+
}),
68+
})
69+
)
70+
.openapi({
71+
description: 'The tables to include in the sheet.',
72+
}),
73+
})
74+
)
75+
.openapi({
76+
description: 'An array of sheet data, where each sheet contains a name and an array of tables to generate.',
77+
}),
78+
excelConfigs: z
79+
.object({
80+
fontFamily: z.string().optional(),
81+
fontSize: z.number().optional(),
82+
headerFontSize: z.number().optional(),
83+
tableTitleFontSize: z.number().optional(),
84+
borderStyle: z.enum(['none', 'thin', 'double', 'dashed', 'thick']).optional(),
85+
autoFitColumnWidth: z.boolean().optional(),
86+
autoFilter: z.boolean().optional(),
87+
wrapText: z.boolean().optional(),
88+
})
89+
.optional()
90+
.openapi({
91+
description: 'Configuration for the Excel file.',
92+
}),
93+
})
94+
.openapi({
95+
description: 'Request body for generating an Excel file.',
96+
});
1697

1798
export type ExcelGeneratorRequestBody = z.infer<typeof ExcelGeneratorRequestBodySchema>;

src/routes/excelGenerator/excelGeneratorRouter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,11 @@ export const excelGeneratorRouter: Router = (() => {
376376
return handleServiceResponse(serviceResponse, res);
377377
} catch (error) {
378378
const errorMessage = (error as Error).message;
379-
let responseObject = '';
380-
if (errorMessage.includes('')) {
381-
responseObject = `Sorry, we couldn't generate excel file.`;
382-
}
379+
console.error('Excel generation error:', error);
383380
const errorServiceResponse = new ServiceResponse(
384381
ResponseStatus.Failed,
385-
`Error ${errorMessage}`,
386-
responseObject,
382+
`Error generating Excel: ${errorMessage}`,
383+
`Sorry, we couldn't generate the Excel file: ${errorMessage}`,
387384
StatusCodes.INTERNAL_SERVER_ERROR
388385
);
389386
return handleServiceResponse(errorServiceResponse, res);

0 commit comments

Comments
 (0)