typeorm / typeorm-routing-controllers-extensions

TypeORM and Routing-Controllers integration library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Do postData fields have to be exactly the same as the entity columns in order to use @EntityFromBody()?

laukaichung opened this issue · comments

I have this entity

@Entity()
export class Post{
    @PrimaryGeneratedColumn()
    post_id: number;

    @Column({type:'string'})
    comment:string;

    @Column({type:'smallint'})
    category:number;

    
    @AfterLoad()
    convertsth(){
    }

    @BeforeInsert()
    async purifyInsert() {
    }

    @BeforeUpdate()
    async purifyUpdate(){
    }
}

It seems that @EntityFromBody won't work when there are extra unrelated fields. The post body has to be entirely the same as the entity. I can't pass extra fields for non database stuff like a form token alongside the entity data or it will throw TypeError: Cannot read property 'prototype' of undefined. Is that true?

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="post_id"

11
------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="comment"

some comment.....

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="category"

2

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="token"

dfsfdsdsfdsfdfsdsf

Error:

TypeError: Cannot read property 'prototype' of undefined
    at Broadcaster.isAllowedListener (/home/node/src/subscriber/Broadcaster.ts:247:71)
    at /home/node/src/subscriber/Broadcaster.ts:58:92
    at Array.filter (native)
    at Broadcaster.<anonymous> (/home/node/src/subscriber/Broadcaster.ts:58:14)
    at step (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:13:53)
    at /home/node/node_modules/typeorm/subscriber/Broadcaster.js:7:71
    at __awaiter (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:3:12)
    at Broadcaster.broadcastBeforeInsertEvent (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:104:16)
    at /home/node/src/subscriber/Broadcaster.ts:31:67
    at Array.map (native)
    at Broadcaster.<anonymous> (/home/node/src/subscriber/Broadcaster.ts:31:47)
    at step (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:13:53)
    at /home/node/node_modules/typeorm/subscriber/Broadcaster.js:7:71
    at __awaiter (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:3:12)
    at Broadcaster.broadcastBeforeEventsForAll (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:57:16)
    at SubjectOperationExecutor.<anonymous> (/home/node/src/persistence/SubjectOperationExecutor.ts:111:47)
    at step (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:13:53)
    at fulfilled (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:4:58)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)

Its not suppose to work with form data. It suppose to work with json data.