I am getting the following error: Inconsistent co...
# orm-help
c
I am getting the following error: Inconsistent column data: Could not convert value "110015 " of the field
ClientNumber
to type
Int
. The database has a ClientNumber, but it's a string with spaces at the end. I can convert the Parameter to an int, but it doesn't work. Controller:
Copy code
@Get(`${Route}/client/:id`)
  byclient(@Param('id') id: number  ) {
    let tempID  = id.toString();
    tempID = tempID.slice(0,6);
    return this.MatterService.MatterbyClient(+tempID);
  }
I have also tried:
Copy code
@Get(`${Route}/client/:id`)
  byclient(@Param('id') id: string  ) {
    let tempID = id.slice(0,6);
    return this.MatterService.MatterbyClient(+tempID);
  }
Service:
Copy code
MatterbyClient( clientid: any) {
    return Promise.all([
      this.prisma.matter.findMany({
        where: { ClientNumber: clientid  },
        select: defaultSelectQuery
      })
  }
Schema:
Copy code
model Matter {
  MatterPKID              Int       @id @default(autoincrement())
  ClientNumber            String    @db.VarChar(16)
  MatterNumber            String    @db.VarChar(16)
  MatterUno               Int
  ClientUno               Int
  MatterName              String    @db.VarChar(250)
  MatterDescription       String?   @db.VarChar(Max)
  OpenDate                DateTime? @db.Date
  CloseDate               DateTime? @db.Date
  

  @@index([ApprovalDate], name: "ncl_Matter_ApprovalDate")
  @@index([ClientNumber], name: "ncl_Matter_ClientNumber")
}
I've tried setting the schema: ClientNumber Int but with no success.
Tried the following:
Copy code
@Get(`${Route}/client/:id`)
  byclient(@Param('id') id: number  ) {
    console.log("\n\nid: " + id + " |");
    if (isNaN(id)) {
      console.log("\n\nid is NOT a number");
    } 
    return this.MatterService.MatterbyClient(+id);
  }
Console displays id: 110015 | but not the other log, so id IS a number at this point. Not sure why the data needs conversion.
Overthinking the problem: service:
Copy code
MatterbyClient( clientid: any) {
    return Promise.all([
      this.prisma.matter.findMany({
        where: { ClientNumber: { startsWith: clientid } },
        select: defaultSelectQuery
      })
    ])
  }
controller:
Copy code
@Get(`${Route}/client/:id`)
  byclient(@Param('id') id: string  ) {
    return this.MatterService.MatterbyClient(id);
  }
schema:
Copy code
ClientNumber            String    @db.VarChar(16)
j
Did you get it working?
n
Are you still facing the issue and are you on the latest version of
@prisma/client
?