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

TypeError: Cannot read properties of undefined(reading 'number') #214

Open
andi-faizal94 opened this issue Mar 28, 2022 · 3 comments
Open

Comments

@andi-faizal94
Copy link

andi-faizal94 commented Mar 28, 2022

#edited

I have entity:

Screen Shot 2022-03-28 at 17 54 28

user.factory.ts

Screen Shot 2022-03-27 at 22 26 55

I have problem with file user.factory.ts:

const gender = faker.random.number(1)

To solve my problem i change:

  1. Change column User entity:

@PrimaryGeneratedColumn("uuid")
id: string;

  1. Change in user.factory.ts :
  • const gender = faker.random.number(1)
  • const age = faker.random.number(1)

change with:

  • const gender = faker.random.uuid();
  • const age = faker.random.number({ min: 10, max: 20 });
  1. Change In Package.json:
    "seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"

change with:

"seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js --configName ./ormconfig.json seed"

this is work to me.

Thank you.

@jorgebodega
Copy link
Collaborator

Hi! Can you just put some more explicit example, or maybe create a repo to reproduce this? Just because you talked about gender but I cannot see that on entity

@andi-faizal94
Copy link
Author

Hi! Can you just put some more explicit example, or maybe create a repo to reproduce this? Just because you talked about gender but I cannot see that on entity

Hi
I'm sorry about it:

my case in Entity:
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm";

@entity()
export class User extends BaseEntity {
@PrimaryGeneratedColumn()
id: number;

@column()
firstName: string;

@column()
lastName: string;

@column()
age: number;

@column({ nullable: true })
addres: string;
}

And I have a file user.factory.ts :

import * as Faker from "faker";
import { define } from "typeorm-seeding";
import { User } from "../../entity/User";

define(User, (faker: typeof Faker) => {
const gender = faker.datatype.number(1);
const firstName = faker.name.firstName(gender);
const lastName = faker.name.lastName(gender);
const age = faker.datatype.number(1);
const addres = faker.random.word();

const user = new User();
user.firstName = firstName;
user.lastName = lastName;
user.age = age;
user.addres = addres;
return user;
});

I fix with :

Change column User entity:
@PrimaryGeneratedColumn("uuid")
id: string;

Change faker.random.number:
const gender = faker.random.uuid();
const age = faker.random.number({ min: 10, max: 20 });
Change In Package.json:
"seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js seed"
change with:

"seed:run": "ts-node ./node_modules/typeorm-seeding/dist/cli.js --configName ./ormconfig.json seed"

this is work to me.

My Repository:

https://github.com/andi-faizal94/RESTfull-API-TYPEORM-Express-PostgreSQL/blob/main/src/database/factories/user.factory.ts

@richoandika
Copy link

@andi-faizal94 Hi,
I think there's your problem bro
image
just adding ./ into path of module like import { UserEntity } from './../entities/user.entity'

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

No branches or pull requests

3 participants