remove product attribute
This commit is contained in:
@@ -107,12 +107,14 @@ export class CreateOrderAsAdminDto {
|
||||
{
|
||||
productId: 1,
|
||||
designerId: '',
|
||||
// print: [{ fieldId: '', value: '' }],
|
||||
// printAttachments: [{ url: '', type: '' }],
|
||||
attachments: [{ url: '', type: '' }],
|
||||
quantity: 100,
|
||||
attributes: [],
|
||||
attributes: [{ fieldId: 10, value: 'blue' }],
|
||||
unitPrice: 150000,
|
||||
discount: 20000
|
||||
discount: 20000,
|
||||
adminDescription: '',
|
||||
description:'توضیحات کاربر',
|
||||
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Category } from './category.entity';
|
||||
import { Attribute } from './attribute.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'products' })
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ProductsSeeder } from './product.seeder';
|
||||
import { AdminsSeeder } from './admins.seeder';
|
||||
import { UsersSeeder } from './users.seeder';
|
||||
import { CategoriesSeeder } from './categories.seeder';
|
||||
import { AttributesSeeder } from './attribute.seeder';
|
||||
import { AttributeValueSeeder } from './attribute-value.seeder';
|
||||
// import { AttributesSeeder } from './attribute.seeder';
|
||||
// import { AttributeValueSeeder } from './attribute-value.seeder';
|
||||
|
||||
// import { NotificationsSeeder } from './notifications.seeder';
|
||||
|
||||
@@ -43,16 +43,16 @@ export class DatabaseSeeder extends Seeder {
|
||||
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Done`);
|
||||
|
||||
// 10. Create products
|
||||
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Creating attributes`);
|
||||
const attributesSeeder = new AttributesSeeder();
|
||||
await attributesSeeder.run(em);
|
||||
console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Done`);
|
||||
// console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Creating attributes`);
|
||||
// const attributesSeeder = new AttributesSeeder();
|
||||
// await attributesSeeder.run(em);
|
||||
// console.info(`[Seeder] Step 9/${TOTAL_STEPS}: Done`);
|
||||
|
||||
// 11. Create products
|
||||
console.info(`[Seeder] Step 10/${TOTAL_STEPS}: Creating attributes`);
|
||||
const attributesValueSeeder = new AttributeValueSeeder();
|
||||
await attributesValueSeeder.run(em);
|
||||
console.info(`[Seeder] Step 11/${TOTAL_STEPS}: Done`);
|
||||
// console.info(`[Seeder] Step 10/${TOTAL_STEPS}: Creating attributes`);
|
||||
// const attributesValueSeeder = new AttributeValueSeeder();
|
||||
// await attributesValueSeeder.run(em);
|
||||
// console.info(`[Seeder] Step 11/${TOTAL_STEPS}: Done`);
|
||||
|
||||
// 12. Create Admins
|
||||
console.info(`[Seeder] Step 12/${TOTAL_STEPS}: Creating admins`);
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { Attribute } from 'src/modules/product/entities/attribute.entity';
|
||||
import { attributeValueData } from './data/attribute-value.data';
|
||||
import { AttributeValue } from 'src/modules/product/entities/attribute-value.entity';
|
||||
// import type { EntityManager } from '@mikro-orm/core';
|
||||
// import { attributeValueData } from './data/attribute-value.data';
|
||||
|
||||
export class AttributeValueSeeder {
|
||||
async run(
|
||||
em: EntityManager,
|
||||
// export class AttributeValueSeeder {
|
||||
// async run(
|
||||
// em: EntityManager,
|
||||
|
||||
): Promise<void> {
|
||||
const attributes = await em.findAll(Attribute)
|
||||
for (const attr of attributes) {
|
||||
// ): Promise<void> {
|
||||
// const attributes = await em.findAll(Attribute)
|
||||
// for (const attr of attributes) {
|
||||
|
||||
const attrValues = attributeValueData.filter(a => a.attributeName === attr.name)
|
||||
// const attrValues = attributeValueData.filter(a => a.attributeName === attr.name)
|
||||
|
||||
for (const av of attrValues) {
|
||||
// for (const av of attrValues) {
|
||||
|
||||
const a= em.create(AttributeValue, {
|
||||
value: av.value,
|
||||
attribute: attr
|
||||
});
|
||||
// const a= em.create(AttributeValue, {
|
||||
// value: av.value,
|
||||
// attribute: attr
|
||||
// });
|
||||
|
||||
em.persist(a)
|
||||
}
|
||||
// em.persist(a)
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
await em.flush();
|
||||
}
|
||||
}
|
||||
// await em.flush();
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { Product } from '../modules/product/entities/product.entity';
|
||||
import { attributeData } from './data/attribute.data';
|
||||
import { Attribute } from 'src/modules/product/entities/attribute.entity';
|
||||
// import type { EntityManager } from '@mikro-orm/core';
|
||||
// import { Product } from '../modules/product/entities/product.entity';
|
||||
// import { attributeData } from './data/attribute.data';
|
||||
// // import { Attribute } from 'src/modules/product/entities/attribute.entity';
|
||||
|
||||
export class AttributesSeeder {
|
||||
async run(
|
||||
em: EntityManager,
|
||||
// export class AttributesSeeder {
|
||||
// async run(
|
||||
// em: EntityManager,
|
||||
|
||||
): Promise<void> {
|
||||
const products = await em.findAll(Product)
|
||||
for (const product of products) {
|
||||
for (const attrData of attributeData) {
|
||||
const attr = em.create(Attribute, {
|
||||
name: attrData.name,
|
||||
type: attrData.type,
|
||||
isRequired: attrData.isRequired,
|
||||
order: 1,
|
||||
product
|
||||
});
|
||||
// ): Promise<void> {
|
||||
// const products = await em.findAll(Product)
|
||||
// for (const product of products) {
|
||||
// for (const attrData of attributeData) {
|
||||
// const attr = em.create(Attribute, {
|
||||
// name: attrData.name,
|
||||
// type: attrData.type,
|
||||
// isRequired: attrData.isRequired,
|
||||
// order: 1,
|
||||
// product
|
||||
// });
|
||||
|
||||
em.persist(attr);
|
||||
}
|
||||
}
|
||||
// em.persist(attr);
|
||||
// }
|
||||
// }
|
||||
|
||||
await em.flush();
|
||||
}
|
||||
}
|
||||
// await em.flush();
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user