feat(fulfillment): Module service implementation first iteration (#6381)

This commit is contained in:
Adrien de Peretti
2024-02-14 18:43:42 +01:00
committed by GitHub
parent 02c53ec93f
commit fafde4f54d
18 changed files with 3986 additions and 74 deletions
@@ -6,11 +6,12 @@ import {
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
Index,
ManyToMany,
OneToMany,
OnInit,
OptionalProps,
PrimaryKey,
@@ -29,6 +30,15 @@ const deletedAtIndexStatement = createPsqlIndexStatementHelper({
where: "deleted_at IS NOT NULL",
})
const nameIndexName = "IDX_fulfillment_set_name_unique"
const nameIndexStatement = createPsqlIndexStatementHelper({
name: nameIndexName,
tableName: "fulfillment_set",
columns: "name",
unique: true,
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class FulfillmentSet {
@@ -38,6 +48,10 @@ export default class FulfillmentSet {
id: string
@Property({ columnType: "text" })
@Index({
name: nameIndexName,
expression: nameIndexStatement,
})
name: string
@Property({ columnType: "text" })
@@ -46,11 +60,9 @@ export default class FulfillmentSet {
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@ManyToMany(() => ServiceZone, "fulfillment_sets", {
owner: true,
pivotTable: "fulfillment_set_service_zones",
joinColumn: "fulfillment_set_id",
inverseJoinColumn: "service_zone_id",
@OneToMany(() => ServiceZone, "fulfillment_set", {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
orphanRemoval: true,
})
service_zones = new Collection<ServiceZone>(this)
+22 -4
View File
@@ -7,12 +7,11 @@ import {
import {
BeforeCreate,
Collection,
Entity,
Enum,
Filter,
Index,
ManyToMany,
ManyToOne,
OnInit,
OptionalProps,
PrimaryKey,
@@ -55,6 +54,14 @@ const cityIndexStatement = createPsqlIndexStatementHelper({
where: "deleted_at IS NULL AND city IS NOT NULL",
})
const serviceZoneIdIndexName = "IDX_geo_zone_service_zone_id"
const serviceZoneIdStatement = createPsqlIndexStatementHelper({
name: serviceZoneIdIndexName,
tableName: "geo_zone",
columns: "service_zone_id",
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class GeoZone {
@@ -87,6 +94,13 @@ export default class GeoZone {
@Property({ columnType: "text", nullable: true })
city: string | null = null
@Property({ columnType: "text" })
@Index({
name: serviceZoneIdIndexName,
expression: serviceZoneIdStatement,
})
service_zone_id: string
// TODO: Do we have an example or idea of what would be stored in this field? like lat/long for example?
@Property({ columnType: "jsonb", nullable: true })
postal_expression: Record<string, unknown> | null = null
@@ -94,8 +108,10 @@ export default class GeoZone {
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@ManyToMany(() => ServiceZone, (serviceZone) => serviceZone.geo_zones)
service_zones = new Collection<ServiceZone>(this)
@ManyToOne(() => ServiceZone, {
persist: false,
})
service_zone: ServiceZone
@Property({
onCreate: () => new Date(),
@@ -122,10 +138,12 @@ export default class GeoZone {
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, " fgz")
this.service_zone_id ??= this.service_zone?.id
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "fgz")
this.service_zone_id ??= this.service_zone?.id
}
}
+37 -11
View File
@@ -6,11 +6,12 @@ import {
import {
BeforeCreate,
Cascade,
Collection,
Entity,
Filter,
Index,
ManyToMany,
ManyToOne,
OneToMany,
OnInit,
OptionalProps,
@@ -32,6 +33,23 @@ const deletedAtIndexStatement = createPsqlIndexStatementHelper({
where: "deleted_at IS NOT NULL",
})
const nameIndexName = "IDX_service_zone_name_unique"
const nameIndexStatement = createPsqlIndexStatementHelper({
name: nameIndexName,
tableName: "service_zone",
columns: "name",
unique: true,
where: "deleted_at IS NULL",
})
const fulfillmentSetIdIndexName = "IDX_service_zone_fulfillment_set_id"
const fulfillmentSetIdIndexStatement = createPsqlIndexStatementHelper({
name: fulfillmentSetIdIndexName,
tableName: "service_zone",
columns: "fulfillment_set_id",
where: "deleted_at IS NULL",
})
@Entity()
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
export default class ServiceZone {
@@ -41,22 +59,28 @@ export default class ServiceZone {
id: string
@Property({ columnType: "text" })
@Index({
name: nameIndexName,
expression: nameIndexStatement,
})
name: string
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@ManyToMany(
() => FulfillmentSet,
(fulfillmentSet) => fulfillmentSet.service_zones
)
fulfillment_sets = new Collection<FulfillmentSet>(this)
@Property({ columnType: "text" })
@Index({
name: fulfillmentSetIdIndexName,
expression: fulfillmentSetIdIndexStatement,
})
fulfillment_set_id: string
@ManyToMany(() => GeoZone, "service_zones", {
owner: true,
pivotTable: "service_zone_geo_zones",
joinColumn: "service_zone_id",
inverseJoinColumn: "geo_zone_id",
@ManyToOne(() => FulfillmentSet, { persist: false })
fulfillment_set: FulfillmentSet
@OneToMany(() => GeoZone, "service_zone", {
cascade: [Cascade.PERSIST, "soft-remove"] as any,
orphanRemoval: true,
})
geo_zones = new Collection<GeoZone>(this)
@@ -91,10 +115,12 @@ export default class ServiceZone {
@BeforeCreate()
onCreate() {
this.id = generateEntityId(this.id, "serzo")
this.fulfillment_set_id ??= this.fulfillment_set?.id
}
@OnInit()
onInit() {
this.id = generateEntityId(this.id, "serzo")
this.fulfillment_set_id ??= this.fulfillment_set?.id
}
}