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:
@@ -0,0 +1,21 @@
|
||||
import {
|
||||
CreateDateColumn,
|
||||
PrimaryColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { DbAwareColumn, resolveDbType } from "../../utils/db-aware-column"
|
||||
|
||||
/**
|
||||
* Base abstract entity for all entities
|
||||
*/
|
||||
export abstract class BaseEntity {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { BaseEntity } from "./base-entity"
|
||||
import { DeleteDateColumn } from "typeorm"
|
||||
import { resolveDbType } from "../../utils/db-aware-column"
|
||||
|
||||
export abstract class SoftDeletableEntity extends BaseEntity {
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date | null
|
||||
}
|
||||
Reference in New Issue
Block a user