Skip to content

Commit cf8dc65

Browse files
authored
fix: import string with zero (#1852)
* fix: import string with zero * perf: checkbox typecase support `false` and `true` string
1 parent 74b1f80 commit cf8dc65

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎apps/nestjs-backend/src/features/import/open-api/import-csv.processor.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class ImportTableCsvQueueProcessor extends WorkerHost {
181181
return new Promise((resolve, reject) => {
182182
Papa.parse(stream, {
183183
download: false,
184-
dynamicTyping: true,
184+
dynamicTyping: false,
185185
complete: (result) => {
186186
resolve(result.data as unknown[][]);
187187
},

‎apps/nestjs-backend/src/features/import/open-api/import.class.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export abstract class Importer {
218218
}
219219

220220
export class CsvImporter extends Importer {
221-
public static readonly CHECK_LINES = 5000;
221+
public static readonly CHECK_LINES = 500;
222222
public static readonly DEFAULT_SHEETKEY = 'Import Table';
223223

224224
parse(): Promise<IParseResult>;
@@ -249,7 +249,7 @@ export class CsvImporter extends Importer {
249249

250250
Papa.parse(toLineDelimitedStream(stream), {
251251
download: false,
252-
dynamicTyping: true,
252+
dynamicTyping: false,
253253
chunk: (chunk, parser) => {
254254
(async () => {
255255
const newChunk = [...chunk.data] as unknown[][];
@@ -332,7 +332,7 @@ export class CsvImporter extends Importer {
332332
return new Promise<IParseResult>((resolve, reject) => {
333333
Papa.parse(stream, {
334334
download: false,
335-
dynamicTyping: true,
335+
dynamicTyping: false,
336336
preview: limit,
337337
complete: (result) => {
338338
resolve({

‎packages/core/src/models/field/derivate/checkbox.field.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ describe('CheckboxFieldCore', () => {
5555
it('should repair invalid value', () => {
5656
expect(field.repair('1.234')).toBe(true);
5757
expect(field.repair(false)).toBeNull();
58+
expect(field.repair('false')).toBeNull();
59+
expect(field.repair('true')).toBe(true);
60+
expect(field.repair('True')).toBe(true);
5861
});
5962

6063
it('should validate value', () => {

‎packages/core/src/models/field/derivate/checkbox.field.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ export class CheckboxFieldCore extends FieldCore {
4949
return null;
5050
}
5151

52+
if (typeof value === 'string') {
53+
const lowercase = value.toLowerCase();
54+
if (lowercase === 'true') {
55+
return true;
56+
}
57+
if (lowercase === 'false') {
58+
return null;
59+
}
60+
}
61+
5262
return value ? true : null;
5363
}
5464

0 commit comments

Comments
 (0)