简体   繁体   中英

Post error when i try to insert data into Database with knex (Node.js)

Basically i am trying to add data into my database with POST. I cant figure out where my mistake is .Thanks in advance for any idea.

My error:
[enter image description here][1]

**type script**

Here all parameter is provided(pha_id,per_id,month,year...)

     this.http.post('/api/auslastung/addAuslastung', {

              hidden_id_phase: pha_id,
              personen_id:per_id,
              personen_wunsch_id:0,
              Monat: month,
              Jahr: year,
              Auslastung:newauslastung_value,
              Rolle:rolle

          },{ responseType: 'text' }).subscribe(data => {
          this.getAuslastung(); 
         } ,
         err => {console.log(err)}); 

///////////////

This is my Api controller

@Post()
public async addAuslastung(req: Request, res: Response) {
    await new AuslastungRepository().addAuslastung(
       req.body['hidden_id_phase']  ,req.body['Personen_ID']  ,
    req.body['Personen_Wunsch_ID'], 
       req.body['Monat'], req.body['Jahr'], 
       req.body['Auslastung'], req.body['Rolle']
    )
    res.send(200);
}

///////////////////// Repository

 public async addAuslastung(phaseId:number,personenenid:number,
personenwunschid:number,Monat : string , Year: string ,auslastung:Float32Array,rolle: string){

                        await Database.knex('Ressource')
                        .insert(({
                            hidden_id_phase:phaseId,
                             Personen_ID:personenenid, 
                            Personen_Wunsch_ID:personenwunschid,
                            Monat:Monat,
                            Jahr:Year,
                            Auslastung:auslastung ,
                            Rolle:rolle
        }

//and my GetAuslastung funstion works well.So I assume problem is not that.

    public async getAuslastung(state: 'ongoing' | 'completed'): Promise<auslastungListItemViewModel[]> {
            const auslastung = await Database.executeFile('GetAuslastung.sql','auslastung',{
            showOngoing: state === 'ongoing',
            showCompleted: state === 'completed'
        });
            return auslastung;
        }

所以我意识到没有错。但是我只需要用ng build -w来重建项目。但是我会保留这个职位,以防有人在某个地方使用它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM