feat(medusa): Allow custom created_by on order edits (#3007)
This commit is contained in:
@@ -30,7 +30,7 @@ describe("POST /admin/order-edits/:id/cancel", () => {
|
||||
it("calls orderService cancel", () => {
|
||||
expect(orderEditServiceMock.cancel).toHaveBeenCalledTimes(1)
|
||||
expect(orderEditServiceMock.cancel).toHaveBeenCalledWith(orderEditId, {
|
||||
loggedInUserId: IdMap.getId("admin_user"),
|
||||
canceledBy: IdMap.getId("admin_user"),
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ describe("POST /admin/order-edits/:id/confirm", () => {
|
||||
it("calls orderService confirm", () => {
|
||||
expect(orderEditServiceMock.confirm).toHaveBeenCalledTimes(1)
|
||||
expect(orderEditServiceMock.confirm).toHaveBeenCalledWith(orderEditId, {
|
||||
loggedInUserId: "admin_user",
|
||||
confirmedBy: "admin_user",
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { orderEditServiceMock } from "../../../../../services/__mocks__/order-edit"
|
||||
import OrderEditingFeatureFlag from "../../../../../loaders/feature-flags/order-editing"
|
||||
import { orderEditServiceMock } from "../../../../../services/__mocks__/order-edit"
|
||||
|
||||
describe("POST /admin/order-edits", () => {
|
||||
describe("successfully create an order edit", () => {
|
||||
@@ -41,7 +41,7 @@ describe("POST /admin/order-edits", () => {
|
||||
internal_note: internalNote,
|
||||
},
|
||||
{
|
||||
loggedInUserId: IdMap.getId("admin_user"),
|
||||
createdBy: IdMap.getId("admin_user"),
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
@@ -35,7 +35,7 @@ describe("GET /admin/order-edits/:id", () => {
|
||||
expect(orderEditServiceMock.requestConfirmation).toHaveBeenCalledTimes(1)
|
||||
expect(orderEditServiceMock.requestConfirmation).toHaveBeenCalledWith(
|
||||
orderEditId,
|
||||
{ loggedInUserId: IdMap.getId("admin_user") }
|
||||
{ requestedBy: IdMap.getId("admin_user") }
|
||||
)
|
||||
|
||||
expect(orderEditServiceMock.update).toHaveBeenCalledTimes(1)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Request, Response } from "express"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import {
|
||||
defaultOrderEditFields,
|
||||
defaultOrderEditRelations,
|
||||
defaultOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ export default async (req: Request, res: Response) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
await orderEditService
|
||||
.withTransaction(transactionManager)
|
||||
.cancel(id, { loggedInUserId: userId })
|
||||
.cancel(id, { canceledBy: userId })
|
||||
})
|
||||
|
||||
const orderEdit = await orderEditService.retrieve(id, {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Request, Response } from "express"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import {
|
||||
defaultOrderEditFields,
|
||||
defaultOrderEditRelations,
|
||||
defaultOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ export default async (req: Request, res: Response) => {
|
||||
await manager.transaction(async (transactionManager) => {
|
||||
await orderEditService
|
||||
.withTransaction(transactionManager)
|
||||
.confirm(id, { loggedInUserId: userId })
|
||||
.confirm(id, { confirmedBy: userId })
|
||||
})
|
||||
|
||||
let orderEdit = await orderEditService.retrieve(id, {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Request, Response } from "express"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
import { Request, Response } from "express"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import {
|
||||
defaultOrderEditFields,
|
||||
defaultOrderEditRelations,
|
||||
defaultOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
|
||||
/**
|
||||
@@ -71,13 +71,13 @@ export default async (req: Request, res: Response) => {
|
||||
const manager = req.scope.resolve("manager") as EntityManager
|
||||
|
||||
const data = req.validatedBody as AdminPostOrderEditsReq
|
||||
const loggedInUserId = (req.user?.id ?? req.user?.userId) as string
|
||||
const createdBy = (req.user?.id ?? req.user?.userId) as string
|
||||
|
||||
const createdOrderEdit = await manager.transaction(
|
||||
async (transactionManager) => {
|
||||
return await orderEditService
|
||||
.withTransaction(transactionManager)
|
||||
.create(data, { loggedInUserId })
|
||||
.create(data, { createdBy })
|
||||
}
|
||||
)
|
||||
|
||||
@@ -110,4 +110,8 @@ export class AdminPostOrderEditsReq {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
internal_note?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
created_by?: string
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { EntityManager } from "typeorm"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { PaymentCollectionType } from "../../../../models"
|
||||
import {
|
||||
OrderEditService,
|
||||
OrderService,
|
||||
PaymentCollectionService,
|
||||
PaymentCollectionService
|
||||
} from "../../../../services"
|
||||
import {
|
||||
defaultOrderEditFields,
|
||||
defaultOrderEditRelations,
|
||||
defaultOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
import { PaymentCollectionType } from "../../../../models"
|
||||
|
||||
/**
|
||||
* @oas [post] /order-edits/{id}/request
|
||||
@@ -82,7 +82,7 @@ export default async (req, res) => {
|
||||
orderEditService.withTransaction(transactionManager)
|
||||
|
||||
const orderEdit = await orderEditServiceTx.requestConfirmation(id, {
|
||||
loggedInUserId: loggedInUser,
|
||||
requestedBy: loggedInUser,
|
||||
})
|
||||
|
||||
const total = await orderEditServiceTx.getTotals(orderEdit.id)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Request, Response } from "express"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { OrderEditStatus, PaymentCollectionStatus } from "../../../../models"
|
||||
import { OrderEditService, PaymentProviderService } from "../../../../services"
|
||||
import {
|
||||
defaultStoreOrderEditFields,
|
||||
defaultStoreOrderEditRelations,
|
||||
defaultStoreOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
import { OrderEditStatus, PaymentCollectionStatus } from "../../../../models"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
|
||||
/**
|
||||
* @oas [post] /order-edits/{id}/complete
|
||||
@@ -111,7 +111,7 @@ export default async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
const returned = await orderEditServiceTx.confirm(id, {
|
||||
loggedInUserId: userId,
|
||||
confirmedBy: userId,
|
||||
})
|
||||
|
||||
return returned
|
||||
|
||||
@@ -4,7 +4,7 @@ import { EntityManager } from "typeorm"
|
||||
import { OrderEditService } from "../../../../services"
|
||||
import {
|
||||
defaultStoreOrderEditFields,
|
||||
defaultStoreOrderEditRelations,
|
||||
defaultStoreOrderEditRelations
|
||||
} from "../../../../types/order-edit"
|
||||
|
||||
/**
|
||||
@@ -70,7 +70,7 @@ export default async (req: Request, res: Response) => {
|
||||
await manager.transaction(async (manager) => {
|
||||
await orderEditService.withTransaction(manager).decline(id, {
|
||||
declinedReason: validatedBody.declined_reason,
|
||||
loggedInUserId: userId,
|
||||
declinedBy: userId,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user