kibae / typeorm-auditing

TypeORM Auditing: Create history tables and manage changes of entity automatically.
https://www.npmjs.com/package/typeorm-auditing
MIT License
25 stars 3 forks source link

Error on boolean type #10

Open kamal-mnrb opened 1 year ago

kamal-mnrb commented 1 year ago

Environment

Describe the bug I have a user entity with "status" column, which is a boolean

@Column({ default: true, }) status: boolean;

When i tried to insert data, the auditing try inserting "1" or "0", then it returns error

QueryFailedError: invalid input value for enum audit_trail.auditing_user_status_enum: "0" at PostgresQueryRunner.query (~/project/node_modules/typeorm/src/driver/postgres/PostgresQueryRunner.ts:299:19) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async InsertQueryBuilder.execute (~/project/node_modules/src/query-builder/InsertQueryBuilder.ts:163:33) at async SubjectExecutor.executeInsertOperations (~/project/node_modules/src/persistence/SubjectExecutor.ts:428:42) at async SubjectExecutor.execute (~/project/node_modules/src/persistence/SubjectExecutor.ts:137:9) at async EntityPersistExecutor.execute (~/project/node_modules/src/persistence/EntityPersistExecutor.ts:194:21) { query: 'INSERT INTO "audit_trail"."auditing_user"("_action", "_modified_at", "id", "status", "first_name", "last_name", "gender", "race", "birthday", "phone", "email", "image", "id_no", "farm_no", "additional_info", "settings", "sepakat_id", "created_at", "updated_at", "address_id") VALUES ($1, DEFAULT, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, DEFAULT) RETURNING "_seq", "_modified_at", "status"', parameters: [ 'Create', 1, 0, 'Super Admin', 'Super Admin', 'male', 'race', '1987-02-02', '0111111111', null, null, null, null, null, null, '11-1111-11-1111', 2022-12-28T22:13:54.593Z, 2022-12-28T22:13:54.593Z ], driverError: error: invalid input value for enum audit_trail.auditing_user_status_enum: "0" at Parser.parseErrorMessage (~/project/node_modules/pg-protocol/src/parser.ts:369:69) at Parser.handlePacket (~/project/node_modules/pg-protocol/src/parser.ts:188:21) at Parser.parse (~/project/node_modules/pg-protocol/src/parser.ts:103:30) at Socket. (~/project/node_modules/pg-protocol/src/index.ts:7:48) at Socket.emit (node:events:527:28) at Socket.emit (node:domain:475:12) at addChunk (node:internal/streams/readable:324:12) at readableAddChunk (node:internal/streams/readable:297:9) at Socket.Readable.push (node:internal/streams/readable:234:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { length: 121, severity: 'ERROR', code: '22P02', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'enum.c', line: '129', routine: 'enum_in' }, length: 121, severity: 'ERROR', code: '22P02', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'enum.c', line: '129', routine: 'enum_in' }

kibae commented 1 year ago

@kamal-mnrb Thanks for reporting the bug. Sorry for the late reply, I was on vacation. I'll try to figure out the problem.

kibae commented 1 year ago

@kamal-mnrb I tested it and it works fine for boolean columns. Could you please show me the code to save the origin entity?

https://github.com/kibae/typeorm-auditing/blob/79419c21c752382357455e4bdfb29619bc8de49f/src/test/entity/case4.ts#L34-L35

https://github.com/kibae/typeorm-auditing/blob/79419c21c752382357455e4bdfb29619bc8de49f/src/test/case4.spec.ts#L20-L63