Feat: Create customer group (#1074)
* fix babel transform-runtime regenerator required for migrations * add customer group model * add migration for customer group * add customer group model export * add customer group repository * add customer group service * add CustomerGroupRepository to "withTransaction" in CustomerGroupService * remove unnecessary argument to runtime plugin * service export ordering * add create customer group endpoint * add customergroup to route index in admin * add customer group service * add customer groups test * cleanup * duplicate error handling * ducplicate name integration test * add jsdoc * customergroup not customer * pr feedback * pipeline test * fix weird merge Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
This commit is contained in:
co-authored by
Sebastian Rindom
parent
22d387dcce
commit
b16976a6f4
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
BeforeInsert,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
DeleteDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinTable,
|
||||
ManyToMany,
|
||||
PrimaryColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { Customer } from ".."
|
||||
import { DbAwareColumn, resolveDbType } from "../utils/db-aware-column"
|
||||
|
||||
@Entity()
|
||||
export class CustomerGroup {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Index({ unique: true, where: "deleted_at IS NULL" })
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@ManyToMany(() => Customer, { cascade: true })
|
||||
@JoinTable({
|
||||
name: "customer_group_customers",
|
||||
joinColumn: {
|
||||
name: "customer_group_id",
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
inverseJoinColumn: {
|
||||
name: "customer_id",
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
})
|
||||
customers: Customer[]
|
||||
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
|
||||
deleted_at: Date
|
||||
|
||||
@DbAwareColumn({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) {
|
||||
return
|
||||
}
|
||||
const id = ulid()
|
||||
this.id = `cgrp_${id}`
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,14 @@ import {
|
||||
OneToOne,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
|
||||
|
||||
import { Address } from "./address"
|
||||
import { CustomerGroup } from "./customer-group"
|
||||
import { Order } from "./order"
|
||||
|
||||
@Entity()
|
||||
@@ -40,10 +43,7 @@ export class Customer {
|
||||
@JoinColumn({ name: "billing_address_id" })
|
||||
billing_address: Address
|
||||
|
||||
@OneToMany(
|
||||
() => Address,
|
||||
address => address.customer
|
||||
)
|
||||
@OneToMany(() => Address, (address) => address.customer)
|
||||
shipping_addresses: Address[]
|
||||
|
||||
@Column({ nullable: true, select: false })
|
||||
@@ -55,12 +55,12 @@ export class Customer {
|
||||
@Column({ default: false })
|
||||
has_account: boolean
|
||||
|
||||
@OneToMany(
|
||||
() => Order,
|
||||
order => order.customer
|
||||
)
|
||||
@OneToMany(() => Order, (order) => order.customer)
|
||||
orders: Order[]
|
||||
|
||||
@ManyToMany(() => CustomerGroup, { cascade: true })
|
||||
groups: CustomerGroup[]
|
||||
|
||||
@CreateDateColumn({ type: resolveDbType("timestamptz") })
|
||||
created_at: Date
|
||||
|
||||
@@ -75,7 +75,9 @@ export class Customer {
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
if (this.id) {
|
||||
return
|
||||
}
|
||||
const id = ulid()
|
||||
this.id = `cus_${id}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user