nestjsx/crud

ERROR [ExceptionsHandler] Cannot read properties of null (reading 'options')

nguyennhukhanh opened this issue ยท 9 comments

Bug Report

[Nest] 14964  - 08/24/2023, 12:15:56 AM   ERROR [ExceptionsHandler] Cannot read properties of null (reading 'options')
TypeError: Cannot read properties of null (reading 'options')
    at CategoryService.createOne (\node_modules\@nestjsx\crud-typeorm\src\typeorm-crud.service.ts:118:35)
    at CategoryController.createOneBase (\node_modules\@nestjsx\crud\src\crud\crud-routes.factory.ts:227:27)
    at \node_modules\@nestjs\core\router\router-execution-context.js:38:29
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

Current behavior

I use to create a new Category. Here is describing it in json:

{
  "name": "New Category"
}

Input Code

Entity

import {
  Column,
  Entity,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  DeleteDateColumn,
  OneToMany,
} from 'typeorm';

import { Product } from './product.entity';

@Entity('category')
export class Category {
  @Column({ name: 'id', type: 'bigint' })
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'name', nullable: false })
  name: string;

  @CreateDateColumn({ name: 'created_at', type: 'timestamp' })
  CreatedAt: Date;

  @CreateDateColumn({ name: 'updated_at', type: 'timestamp' })
  UpdatedAt: Date;

  @DeleteDateColumn({ name: 'deleted_at', nullable: true })
  DeletedAt?: Date;

  @OneToMany(() => Product, (product) => product.category)
  products: Product[];
}

Controller

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

import { CategoryService } from './category.service';
import { CreateCategoryDto, UpdateCategoryDto } from './dto/category.dto';

import { Category } from '../../database/entity/category.entity';

@ApiTags('category')
@Crud({
  model: {
    type: Category,
  },
  dto: {
    create: CreateCategoryDto,
    update: UpdateCategoryDto,
  },
  query: {
    join: {
      products: {
        eager: true,
      },
    },
  },
  routes: {
    only: [
      'getManyBase',
      'getOneBase',
      'createOneBase',
      'updateOneBase',
      'deleteOneBase',
    ],
  },
})
@Controller('category')
export class CategoryController implements CrudController<Category> {
  constructor(public service: CategoryService) {}
}

Service

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

import { Category } from '../../database/entity/category.entity';

@Injectable()
export class CategoryService extends TypeOrmCrudService<Category> {
  constructor(@InjectRepository(Category) repository: Repository<Category>) {
    super(repository);
  }
}

Module

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { CategoryController } from './category.controller';
import { CategoryService } from './category.service';

import { Category } from '../../database/entity/category.entity';

@Module({
  imports: [TypeOrmModule.forFeature([Category])],
  controllers: [CategoryController],
  providers: [CategoryService],
})
export class CategoryModule {}

DTO

import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

export class CreateCategoryDto {
  @ApiProperty()
  @IsNotEmpty()
  @IsString()
  name: string;
}

export class UpdateCategoryDto {
  @ApiProperty()
  @IsOptional()
  @IsString()
  name?: string;
}

Expected behavior

I expected it to create a new category with the corresponding name!

Environment


Package version: 0.0.1

 
For Tooling issues:
- Node version: v18.16.0
- Platform:  Windows
- Database: Postgres

Other:
- "@nestjs/common": "^10.0.0"
- "@nestjs/core": "^10.0.0"
- "@nestjs/typeorm": "^10.0.0"
- "pg": "^8.11.2"
- "@nestjsx/crud": "^5.0.0-alpha.3"
- "@nestjsx/crud-typeorm": "^5.0.0-alpha.3"

Error has been successfully fixed!

I downgraded nestjs ver and it's accessible.

     "@nestjs/common": "^9.0.0",
     "@nestjs/core": "^9.0.0",
     "@nestjs/typeorm": "^9.0.0",
     "@nestjs/platform-express": "^9.0.0",

Can we reopen this? I don't think that a downgrade of nestjs should be the solution to this.
I am trying to make this work using nestjs 10 but without success. Seems like the library has to be adjusted to the changes made in nestjs 10

Can we reopen this? I don't think that a downgrade of nestjs should be the solution to this. I am trying to make this work using nestjs 10 but without success. Seems like the library has to be adjusted to the changes made in nestjs 10

Ok, I will reopen this issue! Hopefully it will update to version 10 of NestJs

I'm having the same problem. nestjsx/crud doesn't work with NestJS v10 ๐Ÿ˜ข

Same problem here! I see the commit, does someone know release date?

We have switched to https://github.com/gid-oss/dataui-nestjs-crud which is a fork and works for us with nestjs 10.

Switching to @dataui/crud as @ckaeslin suggests fixed this for me.

The problem is an unmaintained, unofficial package that has fallen out of sync with nestjs.

I personally took over a project from other people and didn't notice the x in @nestjsx which was a cause of a lot of confusion here ๐Ÿ˜„

any update on this issue ? should i switch to other forked repo ?

@geek-sajjad this repo isn't maintained anymore. See the latest comments and switch to @dataui/crud