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