Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Nov 9, 2023
1 parent 5883ade commit 17d969d
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 575 deletions.
5 changes: 0 additions & 5 deletions src/database/entities/category.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
UpdateDateColumn,
OneToMany,
} from 'typeorm';
import { Exclude } from 'class-transformer';
import { typeImg } from '@models/type-img';
import { Product } from './product.entity';
import { Field, ID, ObjectType } from '@nestjs/graphql';

Expand All @@ -26,9 +24,6 @@ export class Category {
@Column()
image: string;

@Exclude()
keyLoremSpace: typeImg;

@Field()
@CreateDateColumn({
name: 'creation_at',
Expand Down
12 changes: 0 additions & 12 deletions src/database/factories/category.factory.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/database/factories/product.factory.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/database/factories/user.factory.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/database/seeds/category.seeder.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/database/seeds/products.seeder.ts

This file was deleted.

40 changes: 0 additions & 40 deletions src/database/seeds/user.seeder.ts

This file was deleted.

100 changes: 25 additions & 75 deletions src/services/seed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Category } from '@db/entities/category.entity';
import { Product } from '@db/entities/product.entity';
import { User } from '@db/entities/user.entity';
import { Role } from '@models/roles';
import { generateImage } from '@utils/generate-img';
import { generateAvatar } from '@utils/generate-img';
import { CATEGORIES } from '@utils/images';

@Injectable()
export class SeedService {
Expand All @@ -31,103 +32,52 @@ export class SeedService {
password: 'changeme',
name: 'Jhon',
role: Role.customer,
avatar: generateImage('face'),
avatar: generateAvatar(),
},
{
id: 2,
email: '[email protected]',
password: '12345',
name: 'Maria',
role: Role.customer,
avatar: generateImage('face'),
avatar: generateAvatar(),
},
{
id: 3,
email: '[email protected]',
password: 'admin123',
name: 'Admin',
role: Role.admin,
avatar: generateImage('face'),
avatar: generateAvatar(),
},
]);

// -------- CATEGORIES --------

const categoriesRta = await categoriesRepo.save([
{
id: 1,
name: 'Clothes',
keyLoremSpace: 'fashion',
image: generateImage('fashion'),
},
{
id: 2,
name: 'Electronics',
keyLoremSpace: 'watch',
image: generateImage('watch'),
},
{
id: 3,
name: 'Furniture',
keyLoremSpace: 'furniture',
image: generateImage('furniture'),
},
{
id: 4,
name: 'Shoes',
keyLoremSpace: 'shoes',
image: generateImage('shoes'),
},
{
id: 5,
name: 'Others',
keyLoremSpace: 'random',
image: generateImage('random'),
},
]);
const categoriesData = CATEGORIES.map((item) => ({
id: item.id,
name: item.name,
image: item.image,
}));
const categoriesRta = await categoriesRepo.save(categoriesData);

// -------- Products --------

const productsData: Array<Partial<Product>> = [];
const size = 200;
const category = faker.helpers.arrayElement(categoriesRta);
productsData.push({
title: faker.commerce.productName(),
price: parseInt(faker.commerce.price(), 10),
description: faker.commerce.productDescription(),
category,
images: JSON.stringify([
'https://i.imgur.com/wUBxCQh.jpeg',
'https://i.imgur.com/9aM8pz3.jpeg',
'https://i.imgur.com/ZDMM36B.jpeg',
]),
});
productsData.push({
title: faker.commerce.productName(),
price: parseInt(faker.commerce.price(), 10),
description: faker.commerce.productDescription(),
category,
images: JSON.stringify([
'https://i.imgur.com/CCnU4YX.jpeg',
'https://i.imgur.com/JANnz25.jpeg',
'https://i.imgur.com/ioc7lwM.jpeg',
]),
});
for (let index = 0; index < size; index++) {
const category = faker.helpers.arrayElement(categoriesRta);
const images = [
generateImage(category.keyLoremSpace),
generateImage(category.keyLoremSpace),
generateImage(category.keyLoremSpace),
];
productsData.push({
title: faker.commerce.productName(),
price: parseInt(faker.commerce.price(), 10),
description: faker.commerce.productDescription(),
category,
images: JSON.stringify(images),
CATEGORIES.forEach((category) => {
category.products.forEach((images) => {
const categoryEntity = categoriesRta.find(
(item) => item.id === category.id,
);
productsData.push({
title: faker.commerce.productName(),
price: parseInt(faker.commerce.price(), 10),
description: faker.commerce.productDescription(),
category: categoryEntity,
images: JSON.stringify(images),
});
});
}
});

await productsRepo.save(productsData);

// -------- COUNTERS --------
Expand Down
Loading

0 comments on commit 17d969d

Please sign in to comment.