Skip to content

Commit 5b0c94d

Browse files
Hotfix data seeding (#715)
2 parents ef3ec50 + 299eda3 commit 5b0c94d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

apps/api/src/app/column/usecases/update-column/update-column.usecase.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ export class UpdateColumn {
2121
}
2222

2323
const columns = await this.columnRepository.find({ _templateId: column._templateId });
24-
const sameKeyColumns = columns
25-
.map((columnItem) => (columnItem._id === _id ? { ...command, ...columnItem } : columnItem))
26-
.filter((columnItem) => columnItem.key === command.key);
24+
const updatedColumns = columns.map((columnItem) =>
25+
columnItem._id === _id ? { ...command, _templateId: columnItem._templateId } : columnItem
26+
);
27+
const sameKeyColumns = updatedColumns.filter((columnItem) => columnItem.key === command.key);
2728
if (sameKeyColumns.length > 1) {
2829
throw new UniqueColumnException();
2930
}
@@ -34,12 +35,13 @@ export class UpdateColumn {
3435
const isFieldConditionUpdated =
3536
JSON.stringify(column.selectValues) !== JSON.stringify(command.selectValues) ||
3637
JSON.stringify(column.dateFormats) !== JSON.stringify(command.dateFormats) ||
37-
column.isRequired !== command.isRequired;
38+
column.isRequired !== command.isRequired ||
39+
column.delimiter !== command.delimiter;
3840

3941
column = await this.columnRepository.findOneAndUpdate({ _id }, command);
4042

4143
if (isKeyUpdated || isTypeUpdated || isFieldConditionUpdated) {
42-
await this.saveSampleFile.execute(columns, column._templateId);
44+
await this.saveSampleFile.execute(updatedColumns, column._templateId);
4345
}
4446

4547
if (isKeyUpdated) {

apps/api/src/app/shared/services/file/file.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ export class ExcelFileService {
135135
}
136136
});
137137
const headingNames = headings.map((heading) => heading.key);
138-
const endColumnPosition = this.getExcelColumnNameFromIndex(headings.length + 1) + '2';
139-
const range = workbook.sheet(0).range(`A2:${endColumnPosition}`);
138+
const endColumnPosition = this.getExcelColumnNameFromIndex(headings.length + 1);
140139
if (Array.isArray(data) && data.length > 0) {
141140
const rows: string[][] = data.reduce<string[][]>((acc: string[][], rowItem: Record<string, any>) => {
142141
acc.push(headingNames.map((headingKey) => rowItem[headingKey]));
143142

144143
return acc;
145144
}, []);
145+
const rangeKey = `A2:${endColumnPosition}${rows.length + 1}`;
146+
const range = workbook.sheet(0).range(rangeKey);
146147
range.value(rows);
147148
}
148149
const buffer = await workbook.outputAsync();

0 commit comments

Comments
 (0)