feat(medusa,brightpearl,segment,webshipper): claims (#163)
* chore: create tests * chore: models * fix: passing initial tests * test: adds integration test * test: clean up integration implementation * fix: claims * fix: brightpearl + webshipper * tests: passing * fix: update claim items * fix: adds gitignore * fix: pr comments * fix: single migration * fix(medusa-plugin-segment): adds item claimed event to segment
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
Entity,
|
||||
BeforeInsert,
|
||||
DeleteDateColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Column,
|
||||
PrimaryColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
import { ClaimItem } from "./claim-item"
|
||||
|
||||
@Entity()
|
||||
export class ClaimImage {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column()
|
||||
claim_item_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => ClaimItem,
|
||||
ci => ci.images
|
||||
)
|
||||
@JoinColumn({ name: "claim_item_id" })
|
||||
claim_item: ClaimItem
|
||||
|
||||
@Column()
|
||||
url: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `cimg_${id}`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
Entity,
|
||||
BeforeInsert,
|
||||
DeleteDateColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Column,
|
||||
PrimaryColumn,
|
||||
Index,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
JoinTable,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
import { LineItem } from "./line-item"
|
||||
import { ClaimImage } from "./claim-image"
|
||||
import { ClaimTag } from "./claim-tag"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
|
||||
export enum ClaimReason {
|
||||
MISSING_ITEM = "missing_item",
|
||||
WRONG_ITEM = "wrong_item",
|
||||
PRODUCTION_FAILURE = "production_failure",
|
||||
OTHER = "other",
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ClaimItem {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@OneToMany(
|
||||
() => ClaimImage,
|
||||
ci => ci.claim_item,
|
||||
{ cascade: ["insert", "remove"] }
|
||||
)
|
||||
images: ClaimImage[]
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
claim_order_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => ClaimOrder,
|
||||
co => co.claim_items
|
||||
)
|
||||
@JoinColumn({ name: "claim_order_id" })
|
||||
claim_order: ClaimOrder
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
item_id: string
|
||||
|
||||
@ManyToOne(() => LineItem)
|
||||
@JoinColumn({ name: "item_id" })
|
||||
item: LineItem
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
variant_id: string
|
||||
|
||||
@ManyToOne(() => ProductVariant)
|
||||
@JoinColumn({ name: "variant_id" })
|
||||
variant: ProductVariant
|
||||
|
||||
@Column({ type: "enum", enum: ClaimReason })
|
||||
reason: ClaimReason
|
||||
|
||||
@Column({ nullable: true })
|
||||
note: string
|
||||
|
||||
@Column({ type: "int" })
|
||||
quantity: number
|
||||
|
||||
@ManyToMany(() => ClaimTag, { cascade: ["insert"] })
|
||||
@JoinTable({
|
||||
name: "claim_item_tags",
|
||||
joinColumn: {
|
||||
name: "item_id",
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
inverseJoinColumn: {
|
||||
name: "tag_id",
|
||||
referencedColumnName: "id",
|
||||
},
|
||||
})
|
||||
tags: ClaimTag[]
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `citm_${id}`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
import {
|
||||
Entity,
|
||||
BeforeInsert,
|
||||
DeleteDateColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Column,
|
||||
PrimaryColumn,
|
||||
Index,
|
||||
OneToOne,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
import { Fulfillment } from "./fulfillment"
|
||||
import { LineItem } from "./line-item"
|
||||
import { ClaimItem } from "./claim-item"
|
||||
import { Order } from "./order"
|
||||
import { Return } from "./return"
|
||||
import { ShippingMethod } from "./shipping-method"
|
||||
import { Address } from "./address"
|
||||
|
||||
export enum ClaimType {
|
||||
REFUND = "refund",
|
||||
REPLACE = "replace",
|
||||
}
|
||||
|
||||
export enum ClaimPaymentStatus {
|
||||
NA = "na",
|
||||
NOT_REFUNDED = "not_refunded",
|
||||
REFUNDED = "refunded",
|
||||
}
|
||||
|
||||
export enum ClaimFulfillmentStatus {
|
||||
NOT_FULFILLED = "not_fulfilled",
|
||||
PARTIALLY_FULFILLED = "partially_fulfilled",
|
||||
FULFILLED = "fulfilled",
|
||||
PARTIALLY_SHIPPED = "partially_shipped",
|
||||
SHIPPED = "shipped",
|
||||
PARTIALLY_RETURNED = "partially_returned",
|
||||
RETURNED = "returned",
|
||||
CANCELED = "canceled",
|
||||
REQUIRES_ACTION = "requires_action",
|
||||
}
|
||||
|
||||
@Entity()
|
||||
export class ClaimOrder {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: ClaimPaymentStatus,
|
||||
default: ClaimPaymentStatus.NA,
|
||||
})
|
||||
payment_status: ClaimPaymentStatus
|
||||
|
||||
@Column({
|
||||
type: "enum",
|
||||
enum: ClaimFulfillmentStatus,
|
||||
default: ClaimFulfillmentStatus.NOT_FULFILLED,
|
||||
})
|
||||
fulfillment_status: ClaimFulfillmentStatus
|
||||
|
||||
@OneToMany(
|
||||
() => ClaimItem,
|
||||
ci => ci.claim_order
|
||||
)
|
||||
claim_items: ClaimItem[]
|
||||
|
||||
@OneToMany(
|
||||
() => LineItem,
|
||||
li => li.claim_order,
|
||||
{ cascade: ["insert"] }
|
||||
)
|
||||
additional_items: LineItem[]
|
||||
|
||||
@Column({ type: "enum", enum: ClaimType })
|
||||
type: ClaimType
|
||||
|
||||
@Column()
|
||||
order_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => Order,
|
||||
o => o.claims
|
||||
)
|
||||
@JoinColumn({ name: "order_id" })
|
||||
order: Order
|
||||
|
||||
@OneToOne(
|
||||
() => Return,
|
||||
ret => ret.claim_order
|
||||
)
|
||||
return_order: Return
|
||||
|
||||
@Column({ nullable: true })
|
||||
shipping_address_id: string
|
||||
|
||||
@ManyToOne(() => Address, { cascade: ["insert"] })
|
||||
@JoinColumn({ name: "shipping_address_id" })
|
||||
shipping_address: Address
|
||||
|
||||
@OneToMany(
|
||||
() => ShippingMethod,
|
||||
method => method.claim_order,
|
||||
{ cascade: ["insert"] }
|
||||
)
|
||||
shipping_methods: ShippingMethod[]
|
||||
|
||||
@OneToMany(
|
||||
() => Fulfillment,
|
||||
fulfillment => fulfillment.claim_order,
|
||||
{ cascade: ["insert"] }
|
||||
)
|
||||
fulfillments: Fulfillment[]
|
||||
|
||||
@Column({ type: "int", nullable: true })
|
||||
refund_amount: number
|
||||
|
||||
@Column({ type: "timestamptz", nullable: true })
|
||||
canceled_at: Date
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@Column({ nullable: true })
|
||||
idempotency_key: string
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `claim_${id}`
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import {
|
||||
Entity,
|
||||
BeforeInsert,
|
||||
DeleteDateColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
Column,
|
||||
PrimaryColumn,
|
||||
Index,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
JoinColumn,
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
@Entity()
|
||||
export class ClaimTag {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Index()
|
||||
@Column()
|
||||
value: string
|
||||
|
||||
@CreateDateColumn({ type: "timestamptz" })
|
||||
created_at: Date
|
||||
|
||||
@UpdateDateColumn({ type: "timestamptz" })
|
||||
updated_at: Date
|
||||
|
||||
@DeleteDateColumn({ type: "timestamptz" })
|
||||
deleted_at: Date
|
||||
|
||||
@Column({ type: "jsonb", nullable: true })
|
||||
metadata: any
|
||||
|
||||
@BeforeInsert()
|
||||
private beforeInsert() {
|
||||
if (this.id) return
|
||||
const id = ulid()
|
||||
this.id = `ctag_${id}`
|
||||
}
|
||||
}
|
||||
@@ -20,12 +20,23 @@ import { Order } from "./order"
|
||||
import { FulfillmentProvider } from "./fulfillment-provider"
|
||||
import { FulfillmentItem } from "./fulfillment-item"
|
||||
import { Swap } from "./swap"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
|
||||
@Entity()
|
||||
export class Fulfillment {
|
||||
@PrimaryColumn()
|
||||
id: string
|
||||
|
||||
@Column({ nullable: true })
|
||||
claim_order_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => ClaimOrder,
|
||||
co => co.fulfillments
|
||||
)
|
||||
@JoinColumn({ name: "claim_order_id" })
|
||||
claim_order: ClaimOrder
|
||||
|
||||
@Column({ nullable: true })
|
||||
swap_id: string
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { ulid } from "ulid"
|
||||
import { Swap } from "./swap"
|
||||
import { Cart } from "./cart"
|
||||
import { Order } from "./order"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { ProductVariant } from "./product-variant"
|
||||
|
||||
@Check(`"fulfilled_quantity" <= "quantity"`)
|
||||
@@ -59,6 +60,17 @@ export class LineItem {
|
||||
@JoinColumn({ name: "swap_id" })
|
||||
swap: Swap
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: true })
|
||||
claim_order_id: string
|
||||
|
||||
@ManyToOne(
|
||||
() => ClaimOrder,
|
||||
co => co.additional_items
|
||||
)
|
||||
@JoinColumn({ name: "claim_order_id" })
|
||||
claim_order: ClaimOrder
|
||||
|
||||
@Column()
|
||||
title: string
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import { Fulfillment } from "./fulfillment"
|
||||
import { Return } from "./return"
|
||||
import { Refund } from "./refund"
|
||||
import { Swap } from "./swap"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { ShippingMethod } from "./shipping-method"
|
||||
|
||||
export enum OrderStatus {
|
||||
@@ -183,6 +184,13 @@ export class Order {
|
||||
)
|
||||
returns: Return[]
|
||||
|
||||
@OneToMany(
|
||||
() => ClaimOrder,
|
||||
co => co.order,
|
||||
{ cascade: ["insert"] }
|
||||
)
|
||||
claims: ClaimOrder[]
|
||||
|
||||
@OneToMany(
|
||||
() => Refund,
|
||||
ref => ref.order,
|
||||
|
||||
@@ -19,6 +19,7 @@ export enum RefundReason {
|
||||
DISCOUNT = "discount",
|
||||
RETURN = "return",
|
||||
SWAP = "swap",
|
||||
CLAIM = "claim",
|
||||
OTHER = "other",
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import { ulid } from "ulid"
|
||||
|
||||
import { Order } from "./order"
|
||||
import { Swap } from "./swap"
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { ReturnItem } from "./return-item"
|
||||
import { ShippingMethod } from "./shipping-method"
|
||||
|
||||
@@ -52,6 +53,16 @@ export class Return {
|
||||
@JoinColumn({ name: "swap_id" })
|
||||
swap: Swap
|
||||
|
||||
@Column({ nullable: true })
|
||||
claim_order_id: string
|
||||
|
||||
@OneToOne(
|
||||
() => ClaimOrder,
|
||||
co => co.return_order
|
||||
)
|
||||
@JoinColumn({ name: "claim_order_id" })
|
||||
claim_order: ClaimOrder
|
||||
|
||||
@Column({ nullable: true })
|
||||
order_id: string
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* models/money-amount.js
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
region_id: { type: String },
|
||||
currency_code: { type: String, required: true },
|
||||
amount: { type: Number, required: true, min: 0 },
|
||||
sale_amount: { type: Number, min: 0 },
|
||||
})
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
} from "typeorm"
|
||||
import { ulid } from "ulid"
|
||||
|
||||
import { ClaimOrder } from "./claim-order"
|
||||
import { Order } from "./order"
|
||||
import { Cart } from "./cart"
|
||||
import { Swap } from "./swap"
|
||||
@@ -18,7 +19,7 @@ import { Return } from "./return"
|
||||
import { ShippingOption } from "./shipping-option"
|
||||
|
||||
@Check(
|
||||
`"order_id" IS NOT NULL OR "cart_id" IS NOT NULL OR "swap_id" IS NOT NULL OR "return_id" IS NOT NULL`
|
||||
`"claim_order_id" IS NOT NULL OR "order_id" IS NOT NULL OR "cart_id" IS NOT NULL OR "swap_id" IS NOT NULL OR "return_id" IS NOT NULL`
|
||||
)
|
||||
@Check(`"price" >= 0`)
|
||||
@Entity()
|
||||
@@ -38,6 +39,14 @@ export class ShippingMethod {
|
||||
@JoinColumn({ name: "order_id" })
|
||||
order: Order
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: true })
|
||||
claim_order_id: string
|
||||
|
||||
@ManyToOne(() => ClaimOrder)
|
||||
@JoinColumn({ name: "claim_order_id" })
|
||||
claim_order: ClaimOrder
|
||||
|
||||
@Index()
|
||||
@Column({ nullable: true })
|
||||
cart_id: string
|
||||
|
||||
Reference in New Issue
Block a user