feat(customer): Introduce customer group (#6137)

**What**
Methods for:
- Bulk create customers
- Bulk and single create of customer groups
- Assigning customer <> group relationships
- listing of customers and customer groups

++ Uses new repository loading mechanism
This commit is contained in:
Sebastian Rindom
2024-01-22 11:24:22 +00:00
committed by GitHub
parent fd78f5e242
commit a52586880c
18 changed files with 632 additions and 119 deletions
@@ -12,7 +12,7 @@ import {
import Customer from "./customer"
import CustomerGroup from "./customer-group"
type OptionalGroupProps = DAL.EntityDateColumns // TODO: To be revisited when more clear
type OptionalGroupProps = "customer_group" | "customer" | DAL.EntityDateColumns // TODO: To be revisited when more clear
@Entity({ tableName: "customer_group_customer" })
export default class CustomerGroupCustomer {
@@ -21,19 +21,27 @@ export default class CustomerGroupCustomer {
@PrimaryKey({ columnType: "text" })
id!: string
@Property({ columnType: "text" })
customer_id: string
@Property({ columnType: "text" })
customer_group_id: string
@ManyToOne({
entity: () => Customer,
fieldName: "customer__id",
fieldName: "customer_id",
index: "IDX_customer_group_customer_customer_id",
nullable: true,
})
customer: Customer
customer: Customer | null
@ManyToOne({
entity: () => CustomerGroup,
fieldName: "customer_group_id",
index: "IDX_customer_group_customer_group_id",
nullable: true,
})
customer_group: CustomerGroup
customer_group: CustomerGroup | null
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@@ -53,6 +61,9 @@ export default class CustomerGroupCustomer {
})
updated_at: Date
@Property({ columnType: "text", nullable: true })
created_by: string | null = null
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "cusgc")
@@ -34,6 +34,9 @@ export default class CustomerGroup {
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({ columnType: "text", nullable: true })
created_by: string | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
+1 -1
View File
@@ -71,7 +71,7 @@ export default class Customer {
metadata: Record<string, unknown> | null = null
@ManyToMany({
inversedBy: (group) => group.customers,
mappedBy: "customers",
entity: () => CustomerGroup,
pivotEntity: () => CustomerGroupCustomer,
})