How to query type enum in nestjs

Viewed 442

i try to run query graphql:

projects(input:{
    nameTerm:""
    projectTypeTerm:""
    statusTerm:"Initiation Phase"

  })
  {
    id
    name
    status
  }
}

and after that it return message operator does not exist: project_status_enum ~~ unknown" file resolver:

 @Query(() => [Project], { name: 'projects' })
  getProjects(@Args('input') input: GetProjectsInput, ) {
    const query = this.mapper.map(input, GetProjectsQuery, GetProjectsInput);
    return this.queryBus.execute(query);
  }

file enum:

export enum statusProject {
  Initiation = 'Initiation Phase',
  Planning = 'Planning Phase',
  Execution = 'Execution Phase',
  ProjectClosure = 'Project Closure',
}

file handle query:

 async execute(query: GetProjectsQuery): Promise<Project[]> {
    return await this.ProjectRepository.find({
      where: {
        name: Like(`%${query.nameTerm}%`),
        status: Like(`%${query.statusTerm}%`),
        projectType: Like(`%${query.projectTypeTerm}%`)
      },
    });
  }

I try to add {enum:statusProject} in @Query but not work and hope result is:

"projects": \[
{
"id": "77b7134f-270a-4a41-a85a-377311fdbb91",
"name": "Time ABCDFG",
"status": "Initiation Phase"
},\]
1 Answers

I have fixed the problem by changing status: Like(`%${query.statusTerm}%`)
to status: {query.statusTerm}

Like cannot be used with enum.

Related