Refactor(medusa): Create a BaseEntity and SoftDeletableEntity base class for common columns (#1315)
* refactor(medusa): Move some column to a base entity to make it easier to add new models without forgetting some columns * styles(medusa): Cleanup models * fix(medusa): typings due to model typings update * feat(medusa): Cleanup models * fix(medusa): A model must not return the generateId as part of the entity * fix(medusa): Plugin integration snapshot * fix(medusa): Typings from discount-rule-migration scripts * refactor(medusa): Introduct BaseEntity/SoftDeletableEntity that the entity extends * styles(medusa): Fix models linting * test(medusa): Fix integration plugin tests * feat(medusa): Create generateEntityId standalong function utility and update config to properly supprt ts spec files * feat(medusa): Update entities to use the new utils to generate and apply the id * test(medusa): Fix test suits * feat(medusa): Improve generateEntityId utility
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
|
||||
import dotenv from "dotenv"
|
||||
import { createConnection } from "typeorm"
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"
|
||||
import Logger from "../loaders/logger"
|
||||
import {
|
||||
DiscountCondition,
|
||||
@@ -8,6 +10,7 @@ import {
|
||||
} from "../models/discount-condition"
|
||||
import { DiscountConditionProduct } from "../models/discount-condition-product"
|
||||
import { DiscountRule } from "../models/discount-rule"
|
||||
import { DiscountConditionRepository } from "../repositories/discount-condition"
|
||||
dotenv.config()
|
||||
|
||||
const typeormConfig = {
|
||||
@@ -48,18 +51,18 @@ const migrate = async function ({ typeormConfig }): Promise<void> {
|
||||
.offset(offset)
|
||||
.getRawMany()
|
||||
|
||||
const discountConditionRepo = manager
|
||||
.getCustomRepository(DiscountConditionRepository)
|
||||
await manager
|
||||
.createQueryBuilder()
|
||||
.insert()
|
||||
.into(DiscountCondition)
|
||||
.values(
|
||||
discountRules.map((dr) =>
|
||||
Object.assign(new DiscountCondition(), {
|
||||
type: DiscountConditionType.PRODUCTS,
|
||||
operator: DiscountConditionOperator.IN,
|
||||
discount_rule_id: dr.dr_id,
|
||||
})
|
||||
)
|
||||
discountRules.map((dr) => discountConditionRepo.create({
|
||||
type: DiscountConditionType.PRODUCTS,
|
||||
operator: DiscountConditionOperator.IN,
|
||||
discount_rule_id: dr.dr_id,
|
||||
}) as QueryDeepPartialEntity<DiscountCondition>)
|
||||
)
|
||||
.orIgnore()
|
||||
.execute()
|
||||
|
||||
Reference in New Issue
Block a user