Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error "Invalid value" when sending a number to the filter in v4.0.0 #97

Closed
salomaosnff opened this issue Jun 13, 2019 · 1 comment · Fixed by #99
Closed

Error "Invalid value" when sending a number to the filter in v4.0.0 #97

salomaosnff opened this issue Jun 13, 2019 · 1 comment · Fixed by #99
Assignees

Comments

@salomaosnff
Copy link
Contributor

// user.controller.ts

import { Controller } from '@nestjs/common';
import { ApiUseTags } from '@nestjs/swagger';
import { Crud, CrudController } from '@nestjsx/crud';

import { User } from './user.entity';
import { UsersService } from './users.service';

@Crud({
  model: {
    type: User,
  }
})
@ApiUseTags('users')
@Controller('/users')
export class UsersController implements CrudController<User> {
  constructor(public service: UsersService) {}
}
// user.entity.ts

import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';

@Entity('users')
export class User  {
  @PrimaryGeneratedColumn()
  id:number;

  @Column()
  name: string;

  @Column()
  score:number;
}
// user.service.ts

import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { TypeOrmCrudService } from '@nestjsx/crud-typeorm';

import { User } from './user.entity';

@Injectable()
export class UsersService extends TypeOrmCrudService<User> {
  constructor(@InjectRepository(User) repo) {
    super(repo);
  }
}

Open http://localhost:3000/users?filter=score||eq||0

@salomaosnff
Copy link
Contributor Author

const parsed = JSON.parse(val);

The cause is JSON.parse (), because, ?filter=score||eq||"0" works perfectly.
I believe converting the returned value to string solves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants