fixed merge conflicts
This commit is contained in:
@@ -11,7 +11,7 @@ class TestNotiService extends NotificationService {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
async reSendNotification() {
|
async resendNotification() {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
"pg-god": "^1.0.11",
|
"pg-god": "^1.0.11",
|
||||||
"prettier": "^2.1.1",
|
"prettier": "^2.1.1",
|
||||||
"resolve-cwd": "^3.0.0",
|
"resolve-cwd": "^3.0.0",
|
||||||
"typeorm": "^0.2.30"
|
"typeorm": "^0.2.31"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"publish:next": "lerna publish --canary --preid next --dist-tag next",
|
"publish:next": "lerna publish --canary --preid next --dist-tag next",
|
||||||
|
|||||||
+211
@@ -0,0 +1,211 @@
|
|||||||
|
import WebshipperFulfillmentService from "../webshipper-fulfillment"
|
||||||
|
|
||||||
|
describe("WebshipperFulfillmentService", () => {
|
||||||
|
const orderService = {
|
||||||
|
createShipment: jest.fn(),
|
||||||
|
}
|
||||||
|
const swapService = {
|
||||||
|
createShipment: jest.fn(),
|
||||||
|
}
|
||||||
|
const claimService = {
|
||||||
|
createShipment: jest.fn(),
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("handleWebhook", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates an order shipment", async () => {
|
||||||
|
const webshipper = new WebshipperFulfillmentService(
|
||||||
|
{
|
||||||
|
orderService,
|
||||||
|
claimService,
|
||||||
|
swapService,
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
webshipper.retrieveRelationship = () => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
ext_ref: "order_test.ful_test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
tracking_links: [
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
relationships: {
|
||||||
|
order: {
|
||||||
|
id: "order",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await webshipper.handleWebhook("", body)
|
||||||
|
|
||||||
|
expect(claimService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
expect(swapService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
|
expect(orderService.createShipment).toHaveBeenCalledTimes(1)
|
||||||
|
expect(orderService.createShipment).toHaveBeenCalledWith(
|
||||||
|
"order_test",
|
||||||
|
"ful_test",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates a claim shipment", async () => {
|
||||||
|
const webshipper = new WebshipperFulfillmentService(
|
||||||
|
{
|
||||||
|
orderService,
|
||||||
|
claimService,
|
||||||
|
swapService,
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
webshipper.retrieveRelationship = () => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
ext_ref: "claim_test.ful_test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
tracking_links: [
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
relationships: {
|
||||||
|
order: {
|
||||||
|
id: "order",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await webshipper.handleWebhook("", body)
|
||||||
|
|
||||||
|
expect(orderService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
expect(swapService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
|
expect(claimService.createShipment).toHaveBeenCalledTimes(1)
|
||||||
|
expect(claimService.createShipment).toHaveBeenCalledWith(
|
||||||
|
"claim_test",
|
||||||
|
"ful_test",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("creates a swap shipment", async () => {
|
||||||
|
const webshipper = new WebshipperFulfillmentService(
|
||||||
|
{
|
||||||
|
orderService,
|
||||||
|
claimService,
|
||||||
|
swapService,
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
webshipper.retrieveRelationship = () => {
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
ext_ref: "swap_test.ful_test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
data: {
|
||||||
|
attributes: {
|
||||||
|
tracking_links: [
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
number: "12324245345",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
relationships: {
|
||||||
|
order: {
|
||||||
|
id: "order",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
await webshipper.handleWebhook("", body)
|
||||||
|
|
||||||
|
expect(orderService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
expect(claimService.createShipment).toHaveBeenCalledTimes(0)
|
||||||
|
|
||||||
|
expect(swapService.createShipment).toHaveBeenCalledTimes(1)
|
||||||
|
expect(swapService.createShipment).toHaveBeenCalledWith(
|
||||||
|
"swap_test",
|
||||||
|
"ful_test",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
url: "https://test/1134",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://test/1234",
|
||||||
|
tracking_number: "12324245345",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -363,9 +363,10 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
body.data.relationships.order
|
body.data.relationships.order
|
||||||
)
|
)
|
||||||
if (wsOrder.data && wsOrder.data.attributes.ext_ref) {
|
if (wsOrder.data && wsOrder.data.attributes.ext_ref) {
|
||||||
const trackingNumbers = body.data.attributes.tracking_links.map(
|
const trackingLinks = body.data.attributes.tracking_links.map((l) => ({
|
||||||
(l) => l.number
|
url: l.url,
|
||||||
)
|
tracking_number: l.number,
|
||||||
|
}))
|
||||||
const [orderId, fulfillmentIndex] = wsOrder.data.attributes.ext_ref.split(
|
const [orderId, fulfillmentIndex] = wsOrder.data.attributes.ext_ref.split(
|
||||||
"."
|
"."
|
||||||
)
|
)
|
||||||
@@ -375,7 +376,7 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
return this.swapService_.createShipment(
|
return this.swapService_.createShipment(
|
||||||
orderId,
|
orderId,
|
||||||
fulfillmentIndex,
|
fulfillmentIndex,
|
||||||
trackingNumbers
|
trackingLinks
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
const swap = await this.swapService_.retrieve(orderId.substring(1), {
|
const swap = await this.swapService_.retrieve(orderId.substring(1), {
|
||||||
@@ -385,21 +386,21 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
return this.swapService_.createShipment(
|
return this.swapService_.createShipment(
|
||||||
swap.id,
|
swap.id,
|
||||||
fulfillment.id,
|
fulfillment.id,
|
||||||
trackingNumbers
|
trackingLinks
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else if (orderId.charAt(0).toLowerCase() === "c") {
|
} else if (orderId.charAt(0).toLowerCase() === "c") {
|
||||||
return this.claimService_.createShipment(
|
return this.claimService_.createShipment(
|
||||||
orderId,
|
orderId,
|
||||||
fulfillmentIndex,
|
fulfillmentIndex,
|
||||||
trackingNumbers
|
trackingLinks
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (fulfillmentIndex.startsWith("ful")) {
|
if (fulfillmentIndex.startsWith("ful")) {
|
||||||
return this.orderService_.createShipment(
|
return this.orderService_.createShipment(
|
||||||
orderId,
|
orderId,
|
||||||
fulfillmentIndex,
|
fulfillmentIndex,
|
||||||
trackingNumbers
|
trackingLinks
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
const order = await this.orderService_.retrieve(orderId, {
|
const order = await this.orderService_.retrieve(orderId, {
|
||||||
@@ -411,7 +412,7 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
return this.orderService_.createShipment(
|
return this.orderService_.createShipment(
|
||||||
order.id,
|
order.id,
|
||||||
fulfillment.id,
|
fulfillment.id,
|
||||||
trackingNumbers
|
trackingLinks
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -523,6 +524,11 @@ class WebshipperFulfillmentService extends FulfillmentService {
|
|||||||
.retrieve(data.id)
|
.retrieve(data.id)
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
|
|
||||||
|
// if order does not exist, we resolve gracefully
|
||||||
|
if (!order) {
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
if (order.data.attributes.status !== "pending") {
|
if (order.data.attributes.status !== "pending") {
|
||||||
if (order.data.attributes.status === "cancelled") {
|
if (order.data.attributes.status === "cancelled") {
|
||||||
|
|||||||
@@ -66,6 +66,8 @@ class SegmentService extends BaseService {
|
|||||||
coupon = order.discounts[0] && order.discounts[0].code
|
coupon = order.discounts[0] && order.discounts[0].code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const taxRate = order.tax_rate / 100
|
||||||
|
|
||||||
const orderData = {
|
const orderData = {
|
||||||
checkout_id: order.cart_id,
|
checkout_id: order.cart_id,
|
||||||
order_id: order.id,
|
order_id: order.id,
|
||||||
@@ -104,12 +106,16 @@ class SegmentService extends BaseService {
|
|||||||
products: await Promise.all(
|
products: await Promise.all(
|
||||||
order.items.map(async (item) => {
|
order.items.map(async (item) => {
|
||||||
let name = item.title
|
let name = item.title
|
||||||
|
const lineTotalTax = this.totalsService_.getLineItemRefund(
|
||||||
|
order,
|
||||||
|
item
|
||||||
|
)
|
||||||
|
|
||||||
|
const lineTotal = lineTotalTax / (1 + taxRate)
|
||||||
|
|
||||||
const unit_price = item.unit_price
|
|
||||||
const line_total = this.totalsService_.getLineItemRefund(order, item)
|
|
||||||
const revenue = await this.getReportingValue(
|
const revenue = await this.getReportingValue(
|
||||||
order.currency_code,
|
order.currency_code,
|
||||||
line_total / 100
|
lineTotal / 100
|
||||||
)
|
)
|
||||||
|
|
||||||
let sku = ""
|
let sku = ""
|
||||||
@@ -126,7 +132,7 @@ class SegmentService extends BaseService {
|
|||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
variant,
|
variant,
|
||||||
price: line_total / 100 / item.quantity,
|
price: lineTotal / 100 / item.quantity,
|
||||||
reporting_revenue: revenue,
|
reporting_revenue: revenue,
|
||||||
product_id: item.variant.product_id,
|
product_id: item.variant.product_id,
|
||||||
sku,
|
sku,
|
||||||
|
|||||||
@@ -3,6 +3,17 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.1.9](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.8...@medusajs/medusa@1.1.9) (2021-02-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* performant relations ([5659d10](https://github.com/medusajs/medusa/commit/5659d106e3be139fcf2b32b48ce4c7fa5f678a8b))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [1.1.8](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.7...@medusajs/medusa@1.1.8) (2021-02-17)
|
## [1.1.8](https://github.com/medusajs/medusa/compare/@medusajs/medusa@1.1.7...@medusajs/medusa@1.1.8) (2021-02-17)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@medusajs/medusa",
|
"name": "@medusajs/medusa",
|
||||||
"version": "1.1.8",
|
"version": "1.1.9",
|
||||||
"description": "E-commerce for JAMstack",
|
"description": "E-commerce for JAMstack",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ const defaultRelations = [
|
|||||||
"shipping_methods",
|
"shipping_methods",
|
||||||
"payments",
|
"payments",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
|
"fulfillments.tracking_links",
|
||||||
|
"fulfillments.items",
|
||||||
"returns",
|
"returns",
|
||||||
"gift_cards",
|
"gift_cards",
|
||||||
"gift_card_transactions",
|
"gift_card_transactions",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default async (req, res) => {
|
|||||||
await claimService.createShipment(
|
await claimService.createShipment(
|
||||||
claim_id,
|
claim_id,
|
||||||
value.fulfillment_id,
|
value.fulfillment_id,
|
||||||
value.tracking_numbers
|
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||||
)
|
)
|
||||||
|
|
||||||
const order = await orderService.retrieve(id, {
|
const order = await orderService.retrieve(id, {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default async (req, res) => {
|
|||||||
await orderService.createShipment(
|
await orderService.createShipment(
|
||||||
id,
|
id,
|
||||||
value.fulfillment_id,
|
value.fulfillment_id,
|
||||||
value.tracking_numbers
|
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||||
)
|
)
|
||||||
|
|
||||||
const order = await orderService.retrieve(id, {
|
const order = await orderService.retrieve(id, {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default async (req, res) => {
|
|||||||
await swapService.createShipment(
|
await swapService.createShipment(
|
||||||
swap_id,
|
swap_id,
|
||||||
value.fulfillment_id,
|
value.fulfillment_id,
|
||||||
value.tracking_numbers
|
value.tracking_numbers.map(n => ({ tracking_number: n }))
|
||||||
)
|
)
|
||||||
|
|
||||||
const order = await orderService.retrieve(id, {
|
const order = await orderService.retrieve(id, {
|
||||||
|
|||||||
@@ -188,6 +188,8 @@ export const defaultRelations = [
|
|||||||
"shipping_methods",
|
"shipping_methods",
|
||||||
"payments",
|
"payments",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
|
"fulfillments.tracking_links",
|
||||||
|
"fulfillments.items",
|
||||||
"returns",
|
"returns",
|
||||||
"gift_cards",
|
"gift_cards",
|
||||||
"gift_card_transactions",
|
"gift_card_transactions",
|
||||||
@@ -273,6 +275,7 @@ export const allowedRelations = [
|
|||||||
"shipping_methods",
|
"shipping_methods",
|
||||||
"payments",
|
"payments",
|
||||||
"fulfillments",
|
"fulfillments",
|
||||||
|
"fulfillments.tracking_links",
|
||||||
"returns",
|
"returns",
|
||||||
"claims",
|
"claims",
|
||||||
"swaps",
|
"swaps",
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import {MigrationInterface, QueryRunner} from "typeorm";
|
||||||
|
|
||||||
|
export class trackingLinks1613656135167 implements MigrationInterface {
|
||||||
|
name = 'trackingLinks1613656135167'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`CREATE TABLE "tracking_link" ("id" character varying NOT NULL, "url" character varying, "tracking_number" character varying NOT NULL, "fulfillment_id" character varying NOT NULL, "created_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updated_at" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "deleted_at" TIMESTAMP WITH TIME ZONE, "metadata" jsonb, "idempotency_key" character varying, CONSTRAINT "PK_fcfd77feb9012ec2126d7c0bfb6" PRIMARY KEY ("id"))`);
|
||||||
|
await queryRunner.query(`ALTER TABLE "tracking_link" ADD CONSTRAINT "FK_471e9e4c96e02ba209a307db32b" FOREIGN KEY ("fulfillment_id") REFERENCES "fulfillment"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "tracking_link" DROP CONSTRAINT "FK_471e9e4c96e02ba209a307db32b"`);
|
||||||
|
await queryRunner.query(`DROP TABLE "tracking_link"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import { FulfillmentProvider } from "./fulfillment-provider"
|
|||||||
import { FulfillmentItem } from "./fulfillment-item"
|
import { FulfillmentItem } from "./fulfillment-item"
|
||||||
import { Swap } from "./swap"
|
import { Swap } from "./swap"
|
||||||
import { ClaimOrder } from "./claim-order"
|
import { ClaimOrder } from "./claim-order"
|
||||||
|
import { TrackingLink } from "./tracking-link"
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export class Fulfillment {
|
export class Fulfillment {
|
||||||
@@ -76,6 +77,13 @@ export class Fulfillment {
|
|||||||
)
|
)
|
||||||
items: FulfillmentItem[]
|
items: FulfillmentItem[]
|
||||||
|
|
||||||
|
@OneToMany(
|
||||||
|
() => TrackingLink,
|
||||||
|
tl => tl.fulfillment,
|
||||||
|
{ cascade: ["insert"] }
|
||||||
|
)
|
||||||
|
tracking_links: TrackingLink[]
|
||||||
|
|
||||||
@Column({ type: "jsonb", default: [] })
|
@Column({ type: "jsonb", default: [] })
|
||||||
tracking_numbers: string[]
|
tracking_numbers: string[]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
Index,
|
||||||
|
BeforeInsert,
|
||||||
|
Column,
|
||||||
|
DeleteDateColumn,
|
||||||
|
CreateDateColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
PrimaryColumn,
|
||||||
|
OneToOne,
|
||||||
|
OneToMany,
|
||||||
|
ManyToOne,
|
||||||
|
ManyToMany,
|
||||||
|
JoinColumn,
|
||||||
|
JoinTable,
|
||||||
|
} from "typeorm"
|
||||||
|
import { ulid } from "ulid"
|
||||||
|
|
||||||
|
import { Fulfillment } from "./fulfillment"
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class TrackingLink {
|
||||||
|
@PrimaryColumn()
|
||||||
|
id: string
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
url: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
tracking_number: string
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
fulfillment_id: string
|
||||||
|
|
||||||
|
@ManyToOne(
|
||||||
|
() => Fulfillment,
|
||||||
|
ful => ful.tracking_links
|
||||||
|
)
|
||||||
|
@JoinColumn({ name: "fulfillment_id" })
|
||||||
|
fulfillment: Fulfillment
|
||||||
|
|
||||||
|
@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 = `tlink_${id}`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,28 +10,22 @@ export class OrderRepository extends Repository<Order> {
|
|||||||
): Promise<Order[]> {
|
): Promise<Order[]> {
|
||||||
const entities = await this.find(optionsWithoutRelations)
|
const entities = await this.find(optionsWithoutRelations)
|
||||||
const entitiesIds = entities.map(({ id }) => id)
|
const entitiesIds = entities.map(({ id }) => id)
|
||||||
|
|
||||||
|
const groupedRelations = {}
|
||||||
|
for (const rel of relations) {
|
||||||
|
const [topLevel] = rel.split(".")
|
||||||
|
if (groupedRelations[topLevel]) {
|
||||||
|
groupedRelations[topLevel].push(rel)
|
||||||
|
} else {
|
||||||
|
groupedRelations[topLevel] = [rel]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const entitiesIdsWithRelations = await Promise.all(
|
const entitiesIdsWithRelations = await Promise.all(
|
||||||
relations.map(relation => {
|
Object.entries(groupedRelations).map(([_, rels]) => {
|
||||||
const relationParts = relation.split(".") as string[]
|
|
||||||
|
|
||||||
const partialRelations = relationParts.reduce(
|
|
||||||
(acc: string[], _: string, index: number) => {
|
|
||||||
const toPush = []
|
|
||||||
|
|
||||||
for (let i = 0; i <= index; i++) {
|
|
||||||
toPush.push(relationParts[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
acc.push(toPush.join("."))
|
|
||||||
|
|
||||||
return acc
|
|
||||||
},
|
|
||||||
[] as string[]
|
|
||||||
)
|
|
||||||
|
|
||||||
return this.findByIds(entitiesIds, {
|
return this.findByIds(entitiesIds, {
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
relations: partialRelations,
|
relations: rels as string[],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
).then(flatten)
|
).then(flatten)
|
||||||
@@ -47,6 +41,9 @@ export class OrderRepository extends Repository<Order> {
|
|||||||
relations: Array<keyof Order> = [],
|
relations: Array<keyof Order> = [],
|
||||||
optionsWithoutRelations: Omit<FindManyOptions<Order>, "relations"> = {}
|
optionsWithoutRelations: Omit<FindManyOptions<Order>, "relations"> = {}
|
||||||
): Promise<Order> {
|
): Promise<Order> {
|
||||||
|
// Limit 1
|
||||||
|
optionsWithoutRelations.take = 1
|
||||||
|
|
||||||
const result = await this.findWithRelations(
|
const result = await this.findWithRelations(
|
||||||
relations,
|
relations,
|
||||||
optionsWithoutRelations
|
optionsWithoutRelations
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { EntityRepository, Repository } from "typeorm"
|
||||||
|
import { TrackingLink } from "../models/tracking-link"
|
||||||
|
|
||||||
|
@EntityRepository(TrackingLink)
|
||||||
|
export class TrackingLinkRepository extends Repository<TrackingLink> {}
|
||||||
@@ -95,6 +95,7 @@ describe("FulfillmentService", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("createShipment", () => {
|
describe("createShipment", () => {
|
||||||
|
const trackingLinkRepository = MockRepository({ create: c => c })
|
||||||
const fulfillmentRepository = MockRepository({
|
const fulfillmentRepository = MockRepository({
|
||||||
findOne: () => Promise.resolve({ id: IdMap.getId("fulfillment") }),
|
findOne: () => Promise.resolve({ id: IdMap.getId("fulfillment") }),
|
||||||
})
|
})
|
||||||
@@ -102,6 +103,7 @@ describe("FulfillmentService", () => {
|
|||||||
const fulfillmentService = new FulfillmentService({
|
const fulfillmentService = new FulfillmentService({
|
||||||
manager: MockManager,
|
manager: MockManager,
|
||||||
fulfillmentRepository,
|
fulfillmentRepository,
|
||||||
|
trackingLinkRepository,
|
||||||
})
|
})
|
||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
@@ -113,14 +115,17 @@ describe("FulfillmentService", () => {
|
|||||||
it("calls order model functions", async () => {
|
it("calls order model functions", async () => {
|
||||||
await fulfillmentService.createShipment(
|
await fulfillmentService.createShipment(
|
||||||
IdMap.getId("fulfillment"),
|
IdMap.getId("fulfillment"),
|
||||||
["1234", "2345"],
|
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(fulfillmentRepository.save).toHaveBeenCalledTimes(1)
|
expect(fulfillmentRepository.save).toHaveBeenCalledTimes(1)
|
||||||
expect(fulfillmentRepository.save).toHaveBeenCalledWith({
|
expect(fulfillmentRepository.save).toHaveBeenCalledWith({
|
||||||
id: IdMap.getId("fulfillment"),
|
id: IdMap.getId("fulfillment"),
|
||||||
tracking_numbers: ["1234", "2345"],
|
tracking_links: [
|
||||||
|
{ tracking_number: "1234" },
|
||||||
|
{ tracking_number: "2345" },
|
||||||
|
],
|
||||||
metadata: {},
|
metadata: {},
|
||||||
shipped_at: now,
|
shipped_at: now,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1182,14 +1182,14 @@ describe("OrderService", () => {
|
|||||||
await orderService.createShipment(
|
await orderService.createShipment(
|
||||||
IdMap.getId("test"),
|
IdMap.getId("test"),
|
||||||
IdMap.getId("fulfillment"),
|
IdMap.getId("fulfillment"),
|
||||||
["1234", "2345"],
|
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(fulfillmentService.createShipment).toHaveBeenCalledTimes(1)
|
expect(fulfillmentService.createShipment).toHaveBeenCalledTimes(1)
|
||||||
expect(fulfillmentService.createShipment).toHaveBeenCalledWith(
|
expect(fulfillmentService.createShipment).toHaveBeenCalledWith(
|
||||||
IdMap.getId("fulfillment"),
|
IdMap.getId("fulfillment"),
|
||||||
["1234", "2345"],
|
[{ tracking_number: "1234" }, { tracking_number: "2345" }],
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ class ClaimService extends BaseService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async createShipment(id, fulfillmentId, trackingNumbers, metadata = []) {
|
async createShipment(id, fulfillmentId, trackingLinks, metadata = []) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const claim = await this.retrieve(id, {
|
const claim = await this.retrieve(id, {
|
||||||
relations: ["additional_items"],
|
relations: ["additional_items"],
|
||||||
@@ -426,7 +426,7 @@ class ClaimService extends BaseService {
|
|||||||
|
|
||||||
const shipment = await this.fulfillmentService_
|
const shipment = await this.fulfillmentService_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.createShipment(fulfillmentId, trackingNumbers, metadata)
|
.createShipment(fulfillmentId, trackingLinks, metadata)
|
||||||
|
|
||||||
claim.fulfillment_status = "shipped"
|
claim.fulfillment_status = "shipped"
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class FulfillmentService extends BaseService {
|
|||||||
manager,
|
manager,
|
||||||
totalsService,
|
totalsService,
|
||||||
fulfillmentRepository,
|
fulfillmentRepository,
|
||||||
|
trackingLinkRepository,
|
||||||
shippingProfileService,
|
shippingProfileService,
|
||||||
lineItemService,
|
lineItemService,
|
||||||
fulfillmentProviderService,
|
fulfillmentProviderService,
|
||||||
@@ -26,6 +27,9 @@ class FulfillmentService extends BaseService {
|
|||||||
/** @private @const {FulfillmentRepository} */
|
/** @private @const {FulfillmentRepository} */
|
||||||
this.fulfillmentRepository_ = fulfillmentRepository
|
this.fulfillmentRepository_ = fulfillmentRepository
|
||||||
|
|
||||||
|
/** @private @const {TrackingLinkRepository} */
|
||||||
|
this.trackingLinkRepository_ = trackingLinkRepository
|
||||||
|
|
||||||
/** @private @const {ShippingProfileService} */
|
/** @private @const {ShippingProfileService} */
|
||||||
this.shippingProfileService_ = shippingProfileService
|
this.shippingProfileService_ = shippingProfileService
|
||||||
|
|
||||||
@@ -44,6 +48,7 @@ class FulfillmentService extends BaseService {
|
|||||||
const cloned = new FulfillmentService({
|
const cloned = new FulfillmentService({
|
||||||
manager: transactionManager,
|
manager: transactionManager,
|
||||||
totalsService: this.totalsService_,
|
totalsService: this.totalsService_,
|
||||||
|
trackingLinkRepository: this.trackingLinkRepository_,
|
||||||
fulfillmentRepository: this.fulfillmentRepository_,
|
fulfillmentRepository: this.fulfillmentRepository_,
|
||||||
shippingProfileService: this.shippingProfileService_,
|
shippingProfileService: this.shippingProfileService_,
|
||||||
lineItemService: this.lineItemService_,
|
lineItemService: this.lineItemService_,
|
||||||
@@ -235,15 +240,18 @@ class FulfillmentService extends BaseService {
|
|||||||
* Creates a shipment by marking a fulfillment as shipped. Adds
|
* Creates a shipment by marking a fulfillment as shipped. Adds
|
||||||
* tracking numbers and potentially more metadata.
|
* tracking numbers and potentially more metadata.
|
||||||
* @param {Order} fulfillmentId - the fulfillment to ship
|
* @param {Order} fulfillmentId - the fulfillment to ship
|
||||||
* @param {string[]} trackingNumbers - tracking numbers for the shipment
|
* @param {TrackingLink[]} trackingNumbers - tracking numbers for the shipment
|
||||||
* @param {object} metadata - potential metadata to add
|
* @param {object} metadata - potential metadata to add
|
||||||
* @return {Fulfillment} the shipped fulfillment
|
* @return {Fulfillment} the shipped fulfillment
|
||||||
*/
|
*/
|
||||||
async createShipment(fulfillmentId, trackingNumbers, metadata) {
|
async createShipment(fulfillmentId, trackingLinks, metadata) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const fulfillmentRepository = manager.getCustomRepository(
|
const fulfillmentRepository = manager.getCustomRepository(
|
||||||
this.fulfillmentRepository_
|
this.fulfillmentRepository_
|
||||||
)
|
)
|
||||||
|
const trackingLinkRepo = manager.getCustomRepository(
|
||||||
|
this.trackingLinkRepository_
|
||||||
|
)
|
||||||
|
|
||||||
const fulfillment = await this.retrieve(fulfillmentId, {
|
const fulfillment = await this.retrieve(fulfillmentId, {
|
||||||
relations: ["items"],
|
relations: ["items"],
|
||||||
@@ -251,7 +259,11 @@ class FulfillmentService extends BaseService {
|
|||||||
|
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
fulfillment.shipped_at = now
|
fulfillment.shipped_at = now
|
||||||
fulfillment.tracking_numbers = trackingNumbers
|
|
||||||
|
fulfillment.tracking_links = trackingLinks.map(tl =>
|
||||||
|
trackingLinkRepo.create(tl)
|
||||||
|
)
|
||||||
|
|
||||||
fulfillment.metadata = {
|
fulfillment.metadata = {
|
||||||
...fulfillment.metadata,
|
...fulfillment.metadata,
|
||||||
...metadata,
|
...metadata,
|
||||||
|
|||||||
@@ -328,7 +328,9 @@ class OrderService extends BaseService {
|
|||||||
query.select = select
|
query.select = select
|
||||||
}
|
}
|
||||||
|
|
||||||
const raw = await orderRepo.findOneWithRelations(query.relations, query)
|
const rels = query.relations
|
||||||
|
delete query.relations
|
||||||
|
const raw = await orderRepo.findOneWithRelations(rels, query)
|
||||||
|
|
||||||
if (!raw) {
|
if (!raw) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
@@ -550,13 +552,13 @@ class OrderService extends BaseService {
|
|||||||
* have been created in regards to the shipment.
|
* have been created in regards to the shipment.
|
||||||
* @param {string} orderId - the id of the order that has been shipped
|
* @param {string} orderId - the id of the order that has been shipped
|
||||||
* @param {string} fulfillmentId - the fulfillment that has now been shipped
|
* @param {string} fulfillmentId - the fulfillment that has now been shipped
|
||||||
* @param {Array<String>} trackingNumbers - array of tracking numebers
|
* @param {TrackingLink[]} trackingLinks - array of tracking numebers
|
||||||
* associated with the shipment
|
* associated with the shipment
|
||||||
* @param {Dictionary<String, String>} metadata - optional metadata to add to
|
* @param {Dictionary<String, String>} metadata - optional metadata to add to
|
||||||
* the fulfillment
|
* the fulfillment
|
||||||
* @return {order} the resulting order following the update.
|
* @return {order} the resulting order following the update.
|
||||||
*/
|
*/
|
||||||
async createShipment(orderId, fulfillmentId, trackingNumbers, metadata = {}) {
|
async createShipment(orderId, fulfillmentId, trackingLinks, metadata = {}) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const order = await this.retrieve(orderId, { relations: ["items"] })
|
const order = await this.retrieve(orderId, { relations: ["items"] })
|
||||||
const shipment = await this.fulfillmentService_.retrieve(fulfillmentId)
|
const shipment = await this.fulfillmentService_.retrieve(fulfillmentId)
|
||||||
@@ -570,7 +572,7 @@ class OrderService extends BaseService {
|
|||||||
|
|
||||||
const shipmentRes = await this.fulfillmentService_
|
const shipmentRes = await this.fulfillmentService_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.createShipment(fulfillmentId, trackingNumbers, metadata)
|
.createShipment(fulfillmentId, trackingLinks, metadata)
|
||||||
|
|
||||||
order.fulfillment_status = "shipped"
|
order.fulfillment_status = "shipped"
|
||||||
for (const item of order.items) {
|
for (const item of order.items) {
|
||||||
|
|||||||
@@ -671,12 +671,12 @@ class SwapService extends BaseService {
|
|||||||
* @param {string} swapId - the id of the swap that has been shipped.
|
* @param {string} swapId - the id of the swap that has been shipped.
|
||||||
* @param {string} fulfillmentId - the id of the specific fulfillment that
|
* @param {string} fulfillmentId - the id of the specific fulfillment that
|
||||||
* has been shipped
|
* has been shipped
|
||||||
* @param {Array<string>} trackingNumbers - the tracking numbers associated
|
* @param {TrackingLink[]} trackingLinks - the tracking numbers associated
|
||||||
* with the shipment
|
* with the shipment
|
||||||
* @param {object} metadata - optional metadata to attach to the shipment.
|
* @param {object} metadata - optional metadata to attach to the shipment.
|
||||||
* @returns {Promise<Swap>} the updated swap with new fulfillments and status.
|
* @returns {Promise<Swap>} the updated swap with new fulfillments and status.
|
||||||
*/
|
*/
|
||||||
async createShipment(swapId, fulfillmentId, trackingNumbers, metadata = {}) {
|
async createShipment(swapId, fulfillmentId, trackingLinks, metadata = {}) {
|
||||||
return this.atomicPhase_(async manager => {
|
return this.atomicPhase_(async manager => {
|
||||||
const swap = await this.retrieve(swapId, {
|
const swap = await this.retrieve(swapId, {
|
||||||
relations: ["additional_items"],
|
relations: ["additional_items"],
|
||||||
@@ -685,7 +685,7 @@ class SwapService extends BaseService {
|
|||||||
// Update the fulfillment to register
|
// Update the fulfillment to register
|
||||||
const shipment = await this.fulfillmentService_
|
const shipment = await this.fulfillmentService_
|
||||||
.withTransaction(manager)
|
.withTransaction(manager)
|
||||||
.createShipment(fulfillmentId, trackingNumbers, metadata)
|
.createShipment(fulfillmentId, trackingLinks, metadata)
|
||||||
|
|
||||||
swap.fulfillment_status = "shipped"
|
swap.fulfillment_status = "shipped"
|
||||||
|
|
||||||
|
|||||||
+890
-6
File diff suppressed because it is too large
Load Diff
@@ -9222,10 +9222,10 @@ typedarray@^0.0.6:
|
|||||||
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
|
||||||
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
|
||||||
|
|
||||||
typeorm@^0.2.30:
|
typeorm@^0.2.31:
|
||||||
version "0.2.30"
|
version "0.2.31"
|
||||||
resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.30.tgz#a0df2256402cbcdde8049a244437560495ce9b38"
|
resolved "https://registry.yarnpkg.com/typeorm/-/typeorm-0.2.31.tgz#82b8a1b233224f81c738f53b0380386ccf360917"
|
||||||
integrity sha512-qpr8AO3Phi6ZF7qMHOrRdNisVt8jE1KfmW0ooLFcXscA87aJ12aBPyB9cJfxGNjNwd7B3WIK9ZlBveWiqd74QA==
|
integrity sha512-dVvCEVHH48DG0QPXAKfo0l6ecQrl3A8ucGP4Yw4myz4YEDMProebTQo8as83uyES+nrwCbu3qdkL4ncC2+qcMA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@sqltools/formatter" "1.2.2"
|
"@sqltools/formatter" "1.2.2"
|
||||||
app-root-path "^3.0.0"
|
app-root-path "^3.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user