fix(medusa, pricing, types): pass dates as Date-objects rather than strings to the pricing module (#5768)
* init * remove date string validator; * add transformOptionalDate transformer to api * move type conversion to the datalayer * fix final module integration test * update arrow-function * make string optional * move work to utils * make check for value exists * move util back to pricng * change utils * refactor get-iso-string * fix build * flip transform condition * add null check for isDate * feat(pricing): Separate Pricing Module internal types from `@medusajs/types` (#5777) * create types for pricing repositories * create RepositoryTypes input * add service types * use models for repository types * fix build * update types to match interface types * add aliases * types instead of moduletypes * move repository to types for pricing module * add changeset * fix merge error * fix conflict * fix build * re-add validation of dates in updatePriceLists_
This commit is contained in:
6
.changeset/small-kangaroos-camp.md
Normal file
6
.changeset/small-kangaroos-camp.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/pricing": patch
|
||||
"@medusajs/types": patch
|
||||
---
|
||||
|
||||
feat(types, pricing): separate internal pricing module types from types module
|
||||
@@ -105,6 +105,7 @@ describe("POST /admin/price-lists", () => {
|
||||
type: "override",
|
||||
customer_groups: [{ id: "customer-group-1" }],
|
||||
status: "active",
|
||||
starts_at: new Date(),
|
||||
prices: [
|
||||
{
|
||||
amount: 400,
|
||||
@@ -132,7 +133,7 @@ describe("POST /admin/price-lists", () => {
|
||||
description: "test",
|
||||
type: "override",
|
||||
status: "active",
|
||||
starts_at: null,
|
||||
starts_at: expect.any(String),
|
||||
ends_at: null,
|
||||
customer_groups: [
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { IdMap } from "medusa-test-utils"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
import { PriceListServiceMock } from "../../../../../services/__mocks__/price-list"
|
||||
import { request } from "../../../../../helpers/test-request"
|
||||
|
||||
jest.setTimeout(10000)
|
||||
describe("POST /price-lists", () => {
|
||||
@@ -58,8 +58,8 @@ describe("POST /price-lists", () => {
|
||||
expect(PriceListServiceMock.create).toHaveBeenCalledWith({
|
||||
name: "My Price List",
|
||||
description: "testing",
|
||||
ends_at: "2022-03-14T08:28:38.551Z",
|
||||
starts_at: "2022-03-14T08:28:38.551Z",
|
||||
ends_at: new Date("2022-03-14T08:28:38.551Z"),
|
||||
starts_at: new Date("2022-03-14T08:28:38.551Z"),
|
||||
customer_groups: [
|
||||
{
|
||||
id: "gc_123",
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
PriceListType,
|
||||
} from "@medusajs/utils"
|
||||
import { createPriceLists } from "@medusajs/core-flows"
|
||||
import { Type } from "class-transformer"
|
||||
import { Transform, Type } from "class-transformer"
|
||||
import {
|
||||
IsArray,
|
||||
IsBoolean,
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
} from "../../../../types/price-list"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { getPriceListPricingModule } from "./modules-queries"
|
||||
import { transformOptionalDate } from "../../../../utils/validators/date-transform"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/price-lists
|
||||
@@ -263,9 +264,11 @@ export class AdminPostPriceListsPriceListReq {
|
||||
description: string
|
||||
|
||||
@IsOptional()
|
||||
@Transform(transformOptionalDate)
|
||||
starts_at?: Date
|
||||
|
||||
@IsOptional()
|
||||
@Transform(transformOptionalDate)
|
||||
ends_at?: Date
|
||||
|
||||
@IsOptional()
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import { defaultAdminPriceListFields, defaultAdminPriceListRelations } from "."
|
||||
|
||||
import { updatePriceLists } from "@medusajs/core-flows"
|
||||
import { Type } from "class-transformer"
|
||||
import { Transform, Type } from "class-transformer"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { PriceList } from "../../../.."
|
||||
import TaxInclusivePricingFeatureFlag from "../../../../loaders/feature-flags/tax-inclusive-pricing"
|
||||
@@ -20,6 +20,7 @@ import { AdminPriceListPricesUpdateReq } from "../../../../types/price-list"
|
||||
import { FeatureFlagDecorators } from "../../../../utils/feature-flag-decorators"
|
||||
import { validator } from "../../../../utils/validator"
|
||||
import { getPriceListPricingModule } from "./modules-queries"
|
||||
import { transformOptionalDate } from "../../../../utils/validators/date-transform"
|
||||
|
||||
/**
|
||||
* @oas [post] /admin/price-lists/{id}
|
||||
@@ -238,9 +239,11 @@ export class AdminPostPriceListsPriceListPriceListReq {
|
||||
description?: string
|
||||
|
||||
@IsOptional()
|
||||
@Transform(transformOptionalDate)
|
||||
starts_at?: Date | null
|
||||
|
||||
@IsOptional()
|
||||
@Transform(transformOptionalDate)
|
||||
ends_at?: Date | null
|
||||
|
||||
@IsOptional()
|
||||
|
||||
@@ -138,8 +138,6 @@ const migratePriceLists = async (container: AwilixContainer) => {
|
||||
({ name: title, prices, customer_groups, ...priceList }) => {
|
||||
const createData: PricingTypes.CreatePriceListDTO = {
|
||||
...priceList,
|
||||
starts_at: priceList.starts_at?.toISOString(),
|
||||
ends_at: priceList.ends_at?.toISOString(),
|
||||
title,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { isDate } from "@medusajs/utils"
|
||||
|
||||
export const transformDate = ({ value }): Date => {
|
||||
return !isNaN(Date.parse(value))
|
||||
? new Date(value)
|
||||
: new Date(Number(value) * 1000)
|
||||
return isDate(value) ? new Date(value) : new Date(Number(value) * 1000)
|
||||
}
|
||||
|
||||
export const transformOptionalDate = ({ value }) => {
|
||||
return !isDate(value) ? value : transformDate({ value })
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
import { PriceListRepository } from "@repositories"
|
||||
import { PriceListService } from "@services"
|
||||
import { MikroOrmWrapper } from "../../../utils"
|
||||
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
|
||||
@@ -183,7 +182,7 @@ describe("PriceList Service", () => {
|
||||
await service.update([
|
||||
{
|
||||
id,
|
||||
starts_at: updateDate.toISOString(),
|
||||
starts_at: updateDate,
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
@@ -1575,8 +1575,8 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
await createPriceLists(
|
||||
service,
|
||||
{
|
||||
starts_at: yesterday.toISOString(),
|
||||
ends_at: tomorrow.toISOString(),
|
||||
starts_at: yesterday,
|
||||
ends_at: tomorrow,
|
||||
},
|
||||
{}
|
||||
)
|
||||
@@ -1651,8 +1651,8 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
await createPriceLists(
|
||||
service,
|
||||
{
|
||||
starts_at: tomorrow.toISOString(),
|
||||
ends_at: tenDaysFromToday.toISOString(),
|
||||
starts_at: tomorrow,
|
||||
ends_at: tenDaysFromToday,
|
||||
},
|
||||
{}
|
||||
)
|
||||
@@ -1726,8 +1726,8 @@ describe("PricingModule Service - Calculate Price", () => {
|
||||
await createPriceLists(
|
||||
service,
|
||||
{
|
||||
starts_at: tenDaysAgo.toISOString(),
|
||||
ends_at: yesterday.toISOString(),
|
||||
starts_at: tenDaysAgo,
|
||||
ends_at: yesterday,
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { initialize } from "../../../../src"
|
||||
|
||||
import { createCurrencies } from "../../../__fixtures__/currency"
|
||||
import { createPriceLists } from "../../../__fixtures__/price-list"
|
||||
import { createPriceSets } from "../../../__fixtures__/price-set"
|
||||
import { DB_URL, MikroOrmWrapper } from "../../../utils"
|
||||
import { initialize } from "../../../../src"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -188,15 +188,16 @@ describe("PriceList Service", () => {
|
||||
})
|
||||
|
||||
describe("update", () => {
|
||||
let createdId
|
||||
const id = "price-list-2"
|
||||
|
||||
it("should update the starts_at date of the priceList successfully", async () => {
|
||||
beforeEach(async () => {
|
||||
const [created] = await service.createPriceLists([
|
||||
{
|
||||
title: "test",
|
||||
description: "test",
|
||||
starts_at: "10/01/2023",
|
||||
ends_at: "10/30/2023",
|
||||
starts_at: new Date("10/01/2023"),
|
||||
ends_at: new Date("10/30/2023"),
|
||||
rules: {
|
||||
customer_group_id: [
|
||||
"vip-customer-group-id",
|
||||
@@ -213,12 +214,67 @@ describe("PriceList Service", () => {
|
||||
],
|
||||
},
|
||||
])
|
||||
createdId = created.id
|
||||
})
|
||||
|
||||
it("should fail to update a priceList with invalid starts_at date", async () => {
|
||||
let error
|
||||
try {
|
||||
await service.updatePriceLists([
|
||||
{
|
||||
id: createdId,
|
||||
starts_at: "invalid-date",
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Cannot set price list starts at with with invalid date string: invalid-date"
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to update a priceList with invalid ends_at date", async () => {
|
||||
let error
|
||||
try {
|
||||
await service.updatePriceLists([
|
||||
{
|
||||
id: createdId,
|
||||
ends_at: "invalid-date",
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Cannot set price list ends at with with invalid date string: invalid-date"
|
||||
)
|
||||
})
|
||||
|
||||
it("should update a priceList with starts_at and ends_at dates given as string", async () => {
|
||||
let [priceList] = await service.updatePriceLists([
|
||||
{
|
||||
id: createdId,
|
||||
starts_at: "10/10/2010",
|
||||
ends_at: "10/20/2030",
|
||||
},
|
||||
])
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
starts_at: new Date("10/10/2010").toISOString(),
|
||||
ends_at: new Date("10/20/2030").toISOString(),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should update the starts_at date of the priceList successfully", async () => {
|
||||
const updateDate = new Date()
|
||||
await service.updatePriceLists([
|
||||
{
|
||||
id: created.id,
|
||||
starts_at: updateDate.toISOString(),
|
||||
id: createdId,
|
||||
starts_at: updateDate,
|
||||
rules: {
|
||||
new_rule: ["new-rule-value"],
|
||||
},
|
||||
@@ -227,7 +283,7 @@ describe("PriceList Service", () => {
|
||||
|
||||
const [priceList] = await service.listPriceLists(
|
||||
{
|
||||
id: [created.id],
|
||||
id: [createdId],
|
||||
},
|
||||
{
|
||||
relations: [
|
||||
@@ -303,13 +359,68 @@ describe("PriceList Service", () => {
|
||||
})
|
||||
|
||||
describe("createPriceLists", () => {
|
||||
it("should fail to create a priceList with invalid starts_at date", async () => {
|
||||
let error
|
||||
try {
|
||||
await service.createPriceLists([
|
||||
{
|
||||
title: "test",
|
||||
description: "test",
|
||||
starts_at: "invalid-date",
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Cannot set price list starts at with with invalid date string: invalid-date"
|
||||
)
|
||||
})
|
||||
|
||||
it("should fail to create a priceList with invalid ends_at date", async () => {
|
||||
let error
|
||||
try {
|
||||
await service.createPriceLists([
|
||||
{
|
||||
title: "test",
|
||||
description: "test",
|
||||
ends_at: "invalid-date",
|
||||
},
|
||||
])
|
||||
} catch (err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Cannot set price list ends at with with invalid date string: invalid-date"
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a priceList with starts_at and ends_at dates given as string", async () => {
|
||||
let [priceList] = await service.createPriceLists([
|
||||
{
|
||||
title: "test",
|
||||
description: "test",
|
||||
starts_at: "10/10/2010",
|
||||
ends_at: "10/20/2030",
|
||||
},
|
||||
])
|
||||
expect(priceList).toEqual(
|
||||
expect.objectContaining({
|
||||
starts_at: new Date("10/10/2010").toISOString(),
|
||||
ends_at: new Date("10/20/2030").toISOString(),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should create a priceList successfully", async () => {
|
||||
const [created] = await service.createPriceLists([
|
||||
{
|
||||
title: "test",
|
||||
description: "test",
|
||||
starts_at: "10/01/2023",
|
||||
ends_at: "10/30/2023",
|
||||
starts_at: new Date("10/01/2023"),
|
||||
ends_at: new Date("10/30/2023"),
|
||||
rules: {
|
||||
customer_group_id: [
|
||||
"vip-customer-group-id",
|
||||
|
||||
@@ -3,6 +3,8 @@ module.exports = {
|
||||
"^@models": "<rootDir>/src/models",
|
||||
"^@services": "<rootDir>/src/services",
|
||||
"^@repositories": "<rootDir>/src/repositories",
|
||||
"^@types": "<rootDir>/src/types",
|
||||
"^@utils": "<rootDir>/src/utils",
|
||||
},
|
||||
transform: {
|
||||
"^.+\\.[jt]s?$": [
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
MedusaModule,
|
||||
MODULE_PACKAGE_NAMES,
|
||||
MedusaModule,
|
||||
Modules,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { IPricingModuleService, ModulesSdkTypes } from "@medusajs/types"
|
||||
|
||||
import { InitializeModuleInjectableDependencies } from "@types"
|
||||
import { moduleDefinition } from "../module-definition"
|
||||
import { InitializeModuleInjectableDependencies } from "../types"
|
||||
|
||||
export const initialize = async (
|
||||
options?:
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreateCurrencyDTO,
|
||||
DAL,
|
||||
UpdateCurrencyDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { Currency } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class CurrencyRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class CurrencyRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreateCurrencyDTO[],
|
||||
data: RepositoryTypes.CreateCurrencyDTO[],
|
||||
context: Context = {}
|
||||
): Promise<Currency[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -84,7 +81,7 @@ export class CurrencyRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdateCurrencyDTO[],
|
||||
data: RepositoryTypes.UpdateCurrencyDTO[],
|
||||
context: Context = {}
|
||||
): Promise<Currency[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreateMoneyAmountDTO,
|
||||
DAL,
|
||||
UpdateMoneyAmountDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { MoneyAmount } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class MoneyAmountRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class MoneyAmountRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreateMoneyAmountDTO[],
|
||||
data: RepositoryTypes.CreateMoneyAmountDTO[],
|
||||
context: Context = {}
|
||||
): Promise<MoneyAmount[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -84,7 +81,7 @@ export class MoneyAmountRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdateMoneyAmountDTO[],
|
||||
data: RepositoryTypes.UpdateMoneyAmountDTO[],
|
||||
context: Context = {}
|
||||
): Promise<MoneyAmount[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -5,12 +5,10 @@ import {
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceListRuleValue } from "@models"
|
||||
import {
|
||||
CreatePriceListRuleValueDTO,
|
||||
UpdatePriceListRuleValueDTO,
|
||||
} from "../types"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceListRuleValueRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +67,7 @@ export class PriceListRuleValueRepository extends DALUtils.MikroOrmBaseRepositor
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceListRuleValueDTO[],
|
||||
data: RepositoryTypes.CreatePriceListRuleValueDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceListRuleValue[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -91,7 +89,7 @@ export class PriceListRuleValueRepository extends DALUtils.MikroOrmBaseRepositor
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceListRuleValueDTO[],
|
||||
data: RepositoryTypes.UpdatePriceListRuleValueDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceListRuleValue[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreatePriceListRuleDTO,
|
||||
DAL,
|
||||
UpdatePriceListRuleDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError, arrayDifference } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceListRule } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceListRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class PriceListRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceListRuleDTO[],
|
||||
data: RepositoryTypes.CreatePriceListRuleDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceListRule[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -98,7 +95,7 @@ export class PriceListRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceListRuleDTO[],
|
||||
data: RepositoryTypes.UpdatePriceListRuleDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceListRule[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { Context, DAL, UpdatePriceListDTO } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, GetIsoStringFromDate, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceList } from "@models"
|
||||
import { CreatePriceListDTO } from "../types"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceListRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -65,12 +66,20 @@ export class PriceListRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceListDTO[],
|
||||
data: RepositoryTypes.CreatePriceListDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceList[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
const priceLists = data.map((priceListData) => {
|
||||
const priceLists = data.map((priceListData: any) => {
|
||||
if (!!priceListData.starts_at) {
|
||||
priceListData.starts_at = GetIsoStringFromDate(priceListData.starts_at)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at) {
|
||||
priceListData.ends_at = GetIsoStringFromDate(priceListData.ends_at)
|
||||
}
|
||||
|
||||
return manager.create(PriceList, priceListData)
|
||||
})
|
||||
|
||||
@@ -80,7 +89,7 @@ export class PriceListRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: Omit<UpdatePriceListDTO, "rules">[],
|
||||
data: RepositoryTypes.UpdatePriceListDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceList[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -103,7 +112,7 @@ export class PriceListRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
])
|
||||
)
|
||||
|
||||
const priceLists = data.map((priceListData) => {
|
||||
const priceLists = data.map((priceListData: any) => {
|
||||
const existingPriceList = existingPriceListMap.get(priceListData.id)
|
||||
|
||||
if (!existingPriceList) {
|
||||
@@ -114,13 +123,11 @@ export class PriceListRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
if (!!priceListData.starts_at) {
|
||||
priceListData.starts_at = new Date(
|
||||
priceListData.starts_at
|
||||
).toISOString()
|
||||
priceListData.starts_at = GetIsoStringFromDate(priceListData.starts_at)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at) {
|
||||
priceListData.ends_at = new Date(priceListData.ends_at).toISOString()
|
||||
priceListData.ends_at = GetIsoStringFromDate(priceListData.ends_at)
|
||||
}
|
||||
|
||||
return manager.assign(existingPriceList, priceListData)
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
import {
|
||||
Context,
|
||||
CreatePriceRuleDTO,
|
||||
DAL,
|
||||
UpdatePriceRuleDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { PriceRule } from "@models"
|
||||
|
||||
import { PriceRule } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
@@ -70,7 +66,7 @@ export class PriceRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceRuleDTO[],
|
||||
data: RepositoryTypes.CreatePriceRuleDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceRule[]> {
|
||||
const manager: SqlEntityManager =
|
||||
@@ -97,7 +93,7 @@ export class PriceRuleRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceRuleDTO[],
|
||||
data: RepositoryTypes.UpdatePriceRuleDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceRule[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreatePriceSetMoneyAmountRulesDTO,
|
||||
DAL,
|
||||
UpdatePriceSetMoneyAmountRulesDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceSetMoneyAmountRules } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceSetMoneyAmountRulesRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class PriceSetMoneyAmountRulesRepository extends DALUtils.MikroOrmBaseRep
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceSetMoneyAmountRulesDTO[],
|
||||
data: RepositoryTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetMoneyAmountRules[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -84,7 +81,7 @@ export class PriceSetMoneyAmountRulesRepository extends DALUtils.MikroOrmBaseRep
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
data: RepositoryTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetMoneyAmountRules[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreatePriceSetMoneyAmountDTO,
|
||||
DAL,
|
||||
UpdatePriceSetMoneyAmountDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceSetMoneyAmount } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceSetMoneyAmountRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class PriceSetMoneyAmountRepository extends DALUtils.MikroOrmBaseReposito
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceSetMoneyAmountDTO[],
|
||||
data: RepositoryTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetMoneyAmount[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -87,7 +84,7 @@ export class PriceSetMoneyAmountRepository extends DALUtils.MikroOrmBaseReposito
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceSetMoneyAmountDTO[],
|
||||
data: RepositoryTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetMoneyAmount[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
UpdatePriceSetDTO,
|
||||
CreatePriceSetRuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { PriceSetRuleType } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceSet, PriceSetRuleType, RuleType } from "@models"
|
||||
|
||||
export class PriceSetRuleTypeRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class PriceSetRuleTypeRepository extends DALUtils.MikroOrmBaseRepository
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreatePriceSetRuleTypeDTO[],
|
||||
data: RepositoryTypes.CreatePriceSetRuleTypeDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetRuleType[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -84,7 +81,7 @@ export class PriceSetRuleTypeRepository extends DALUtils.MikroOrmBaseRepository
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdatePriceSetDTO[],
|
||||
data: RepositoryTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSetRuleType[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
import { UpdatePriceListDTO } from "@medusajs/types"
|
||||
import {
|
||||
Context,
|
||||
DAL,
|
||||
UpdatePriceSetDTO,
|
||||
CreatePriceSetDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { PriceSet } from "@models"
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class PriceSetRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -70,7 +66,7 @@ export class PriceSetRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: Omit<CreatePriceSetDTO, "rules">[],
|
||||
data: RepositoryTypes.CreatePriceSetDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSet[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
@@ -85,7 +81,7 @@ export class PriceSetRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: Omit<UpdatePriceListDTO, "rules">[],
|
||||
data: RepositoryTypes.UpdatePriceSetDTO[],
|
||||
context: Context = {}
|
||||
): Promise<PriceSet[]> {
|
||||
const manager = this.getActiveManager<SqlEntityManager>(context)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { MedusaError, MikroOrmBase } from "@medusajs/utils"
|
||||
|
||||
import {
|
||||
CalculatedPriceSetDTO,
|
||||
Context,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
PricingRepositoryService,
|
||||
} from "@medusajs/types"
|
||||
import { MedusaError, MikroOrmBase } from "@medusajs/utils"
|
||||
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PricingRepositoryService } from "../types"
|
||||
|
||||
export class PricingRepository
|
||||
extends MikroOrmBase
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import {
|
||||
Context,
|
||||
CreateRuleTypeDTO,
|
||||
DAL,
|
||||
UpdateRuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
import { Context, DAL } from "@medusajs/types"
|
||||
import { DALUtils, MedusaError, validateRuleAttributes } from "@medusajs/utils"
|
||||
import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { RepositoryTypes } from "@types"
|
||||
import { RuleType } from "@models"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export class RuleTypeRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
protected readonly manager_: SqlEntityManager
|
||||
@@ -69,7 +66,7 @@ export class RuleTypeRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async create(
|
||||
data: CreateRuleTypeDTO[],
|
||||
data: RepositoryTypes.CreateRuleTypeDTO[],
|
||||
context: Context = {}
|
||||
): Promise<RuleType[]> {
|
||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||
@@ -86,7 +83,7 @@ export class RuleTypeRepository extends DALUtils.MikroOrmBaseRepository {
|
||||
}
|
||||
|
||||
async update(
|
||||
data: UpdateRuleTypeDTO[],
|
||||
data: RepositoryTypes.UpdateRuleTypeDTO[],
|
||||
context: Context = {}
|
||||
): Promise<RuleType[]> {
|
||||
validateRuleAttributes(data.map((d) => d.rule_attribute))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { Currency } from "@models"
|
||||
import { CurrencyRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
currencyRepository: DAL.RepositoryService
|
||||
@@ -23,10 +24,10 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
@InjectManager("currencyRepository_")
|
||||
async retrieve(
|
||||
currencyCode: string,
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<Currency, PricingTypes.CurrencyDTO>({
|
||||
return (await retrieveEntity<Currency, ServiceTypes.CurrencyDTO>({
|
||||
id: currencyCode,
|
||||
identifierColumn: "code",
|
||||
entityName: Currency.name,
|
||||
@@ -38,8 +39,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.currencyRepository_.find(
|
||||
@@ -50,8 +51,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectManager("currencyRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {},
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.currencyRepository_.findAndCount(
|
||||
@@ -61,8 +62,8 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<PricingTypes.CurrencyDTO> = {}
|
||||
filters: ServiceTypes.FilterableCurrencyProps = {},
|
||||
config: FindConfig<ServiceTypes.CurrencyDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<Currency>(filters, config)
|
||||
|
||||
@@ -75,7 +76,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateCurrencyDTO[],
|
||||
data: ServiceTypes.CreateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).create(
|
||||
@@ -86,7 +87,7 @@ export default class CurrencyService<TEntity extends Currency = Currency> {
|
||||
|
||||
@InjectTransactionManager("currencyRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateCurrencyDTO[],
|
||||
data: ServiceTypes.UpdateCurrencyDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.currencyRepository_ as CurrencyRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { MoneyAmount } from "@models"
|
||||
import { MoneyAmountRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
moneyAmountRepository: DAL.RepositoryService
|
||||
@@ -25,10 +26,10 @@ export default class MoneyAmountService<
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async retrieve(
|
||||
moneyAmountId: string,
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<MoneyAmount, PricingTypes.MoneyAmountDTO>({
|
||||
return (await retrieveEntity<MoneyAmount, ServiceTypes.MoneyAmountDTO>({
|
||||
id: moneyAmountId,
|
||||
entityName: MoneyAmount.name,
|
||||
repository: this.moneyAmountRepository_,
|
||||
@@ -39,8 +40,8 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
@@ -56,8 +57,8 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectManager("moneyAmountRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<PricingTypes.MoneyAmountDTO> = {},
|
||||
filters: ServiceTypes.FilterableMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.MoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<MoneyAmount>(
|
||||
@@ -73,7 +74,7 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateMoneyAmountDTO[],
|
||||
data: ServiceTypes.CreateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).create(
|
||||
@@ -84,7 +85,7 @@ export default class MoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("moneyAmountRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateMoneyAmountDTO[],
|
||||
data: ServiceTypes.UpdateMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.moneyAmountRepository_ as MoneyAmountRepository).update(
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceListRuleValue } from "@models"
|
||||
import { PriceListRuleValueRepository } from "@repositories"
|
||||
|
||||
import { CreatePriceListRuleValueDTO } from "../types"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRuleValueRepository: DAL.RepositoryService
|
||||
@@ -29,12 +28,12 @@ export default class PriceListRuleValueService<
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceListRuleValue,
|
||||
PricingTypes.PriceListRuleValueDTO
|
||||
ServiceTypes.PriceListRuleValueDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRuleValue.name,
|
||||
@@ -46,8 +45,8 @@ export default class PriceListRuleValueService<
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
@@ -63,8 +62,8 @@ export default class PriceListRuleValueService<
|
||||
|
||||
@InjectManager("priceListRuleValueRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleValueDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleValueProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleValueDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRuleValue>(
|
||||
@@ -83,7 +82,7 @@ export default class PriceListRuleValueService<
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async create(
|
||||
data: CreatePriceListRuleValueDTO[],
|
||||
data: ServiceTypes.CreatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -96,7 +95,7 @@ export default class PriceListRuleValueService<
|
||||
"priceListRuleValueRepository_"
|
||||
)
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceListRuleValueDTO[],
|
||||
data: ServiceTypes.UpdatePriceListRuleValueDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceListRule } from "@models"
|
||||
import { PriceListRuleRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRuleRepository: DAL.RepositoryService
|
||||
@@ -27,10 +28,10 @@ export default class PriceListRuleService<
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceListRule, PricingTypes.PriceListRuleDTO>({
|
||||
return (await retrieveEntity<PriceListRule, ServiceTypes.PriceListRuleDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceListRule.name,
|
||||
repository: this.priceListRuleRepository_,
|
||||
@@ -41,8 +42,8 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
@@ -58,8 +59,8 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectManager("priceListRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceListRule>(
|
||||
@@ -75,7 +76,7 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceListRuleDTO[],
|
||||
data: ServiceTypes.CreatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -85,7 +86,7 @@ export default class PriceListRuleService<
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRuleRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceListRuleDTO[],
|
||||
data: ServiceTypes.UpdatePriceListRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
doNotForceTransaction,
|
||||
retrieveEntity,
|
||||
shouldForceTransaction,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceList } from "@models"
|
||||
import { PriceListRepository } from "@repositories"
|
||||
import { CreatePriceListDTO } from "../types"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceListRepository: DAL.RepositoryService
|
||||
@@ -26,10 +26,10 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
@InjectManager("priceListRepository_")
|
||||
async retrieve(
|
||||
priceListId: string,
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceList, PricingTypes.PriceListDTO>({
|
||||
return (await retrieveEntity<PriceList, ServiceTypes.PriceListDTO>({
|
||||
id: priceListId,
|
||||
entityName: PriceList.name,
|
||||
repository: this.priceListRepository_,
|
||||
@@ -40,8 +40,8 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
@@ -54,8 +54,8 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectManager("priceListRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<PricingTypes.PriceListDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceListProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceListDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceList>(filters, config)
|
||||
@@ -68,7 +68,7 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async create(
|
||||
data: CreatePriceListDTO[],
|
||||
data: ServiceTypes.CreatePriceListDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).create(
|
||||
@@ -79,7 +79,7 @@ export default class PriceListService<TEntity extends PriceList = PriceList> {
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "priceListRepository_")
|
||||
async update(
|
||||
data: Omit<PricingTypes.UpdatePriceListDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.UpdatePriceListDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceListRepository_ as PriceListRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
import { PriceRule } from "@models"
|
||||
import { PriceRuleRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceRuleRepository: DAL.RepositoryService
|
||||
}
|
||||
@@ -23,10 +25,10 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async retrieve(
|
||||
priceRuleId: string,
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceRule, PricingTypes.PriceRuleDTO>({
|
||||
return (await retrieveEntity<PriceRule, ServiceTypes.PriceRuleDTO>({
|
||||
id: priceRuleId,
|
||||
entityName: PriceRule.name,
|
||||
repository: this.priceRuleRepository_,
|
||||
@@ -37,8 +39,8 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
@@ -51,8 +53,8 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectManager("priceRuleRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<PricingTypes.PriceRuleDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceRuleProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceRuleDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryConfig = ModulesSdkUtils.buildQuery<PriceRule>(filters, config)
|
||||
@@ -65,7 +67,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceRuleDTO[],
|
||||
data: ServiceTypes.CreatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).create(
|
||||
@@ -76,7 +78,7 @@ export default class PriceRuleService<TEntity extends PriceRule = PriceRule> {
|
||||
|
||||
@InjectTransactionManager("priceRuleRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceRuleDTO[],
|
||||
data: ServiceTypes.UpdatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceRuleRepository_ as PriceRuleRepository).update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSetMoneyAmountRules } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetMoneyAmountRulesRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async retrieve(
|
||||
priceSetMoneyAmountRulesId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmountRules,
|
||||
PricingTypes.PriceSetMoneyAmountRulesDTO
|
||||
ServiceTypes.PriceSetMoneyAmountRulesDTO
|
||||
>({
|
||||
id: priceSetMoneyAmountRulesId,
|
||||
identifierColumn: "id",
|
||||
@@ -43,8 +44,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.find(
|
||||
@@ -55,8 +56,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRulesRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.findAndCount(
|
||||
@@ -66,8 +67,8 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetMoneyAmountRulesDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountRulesProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountRulesDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSetMoneyAmountRules>(
|
||||
filters,
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.create(
|
||||
@@ -90,7 +91,7 @@ export default class PriceSetMoneyAmountRulesService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRulesRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountRulesDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRulesRepository_.update(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetMoneyAmount } from "@models"
|
||||
import { PriceSetMoneyAmountRepository } from "@repositories"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetMoneyAmountRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetMoneyAmountService<
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetRuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetMoneyAmountDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetMoneyAmount,
|
||||
PricingTypes.PriceSetRuleTypeDTO
|
||||
ServiceTypes.PriceSetMoneyAmountDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
@@ -42,8 +43,8 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.find(
|
||||
@@ -54,8 +55,8 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectManager("priceSetMoneyAmountRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetMoneyAmountRepository_.findAndCount(
|
||||
@@ -65,8 +66,8 @@ export default class PriceSetMoneyAmountService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetMoneyAmountProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
data: ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -90,7 +91,7 @@ export default class PriceSetMoneyAmountService<
|
||||
|
||||
@InjectTransactionManager("priceSetMoneyAmountRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetMoneyAmountDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from "@medusajs/utils"
|
||||
import { PriceSet, PriceSetRuleType } from "@models"
|
||||
import { PriceSetRuleTypeRepository } from "src/repositories/price-set-rule-type"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetRuleTypeRepository: DAL.RepositoryService
|
||||
@@ -25,12 +26,12 @@ export default class PriceSetRuleTypeService<
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetRuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetRuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<
|
||||
PriceSetRuleType,
|
||||
PricingTypes.PriceSetRuleTypeDTO
|
||||
ServiceTypes.PriceSetRuleTypeDTO
|
||||
>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
@@ -42,8 +43,8 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.priceSetRuleTypeRepository_.find(
|
||||
@@ -54,8 +55,8 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectManager("priceSetRuleTypeRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
return (await this.priceSetRuleTypeRepository_.findAndCount(
|
||||
@@ -65,8 +66,8 @@ export default class PriceSetRuleTypeService<
|
||||
}
|
||||
|
||||
private buildQueryForList(
|
||||
filters: PricingTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {}
|
||||
filters: ServiceTypes.FilterablePriceSetRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {}
|
||||
) {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
|
||||
@@ -79,7 +80,7 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreatePriceSetRuleTypeDTO[],
|
||||
data: ServiceTypes.CreatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
@@ -89,7 +90,7 @@ export default class PriceSetRuleTypeService<
|
||||
|
||||
@InjectTransactionManager("priceSetRuleTypeRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
data: ServiceTypes.UpdatePriceSetRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
import { PriceSet } from "@models"
|
||||
import { PriceSetRepository } from "@repositories"
|
||||
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
priceSetRepository: DAL.RepositoryService
|
||||
}
|
||||
@@ -23,10 +25,10 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
@InjectManager("priceSetRepository_")
|
||||
async retrieve(
|
||||
priceSetId: string,
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<PriceSet, PricingTypes.PriceSetDTO>({
|
||||
return (await retrieveEntity<PriceSet, ServiceTypes.PriceSetDTO>({
|
||||
id: priceSetId,
|
||||
entityName: PriceSet.name,
|
||||
repository: this.priceSetRepository_,
|
||||
@@ -37,8 +39,8 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
@@ -51,8 +53,8 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectManager("priceSetRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<PricingTypes.PriceSetDTO> = {},
|
||||
filters: ServiceTypes.FilterablePriceSetProps = {},
|
||||
config: FindConfig<ServiceTypes.PriceSetDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<PriceSet>(filters, config)
|
||||
@@ -65,7 +67,7 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async create(
|
||||
data: Omit<PricingTypes.CreatePriceSetDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.CreatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).create(
|
||||
@@ -76,7 +78,7 @@ export default class PriceSetService<TEntity extends PriceSet = PriceSet> {
|
||||
|
||||
@InjectTransactionManager("priceSetRepository_")
|
||||
async update(
|
||||
data: Omit<PricingTypes.UpdatePriceSetDTO, "rules">[],
|
||||
data: Omit<ServiceTypes.UpdatePriceSetDTO, "rules">[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await (this.priceSetRepository_ as PriceSetRepository).update(
|
||||
|
||||
@@ -7,9 +7,11 @@ import {
|
||||
FindConfig,
|
||||
InternalModuleDeclaration,
|
||||
ModuleJoinerConfig,
|
||||
MoneyAmountDTO,
|
||||
PriceSetDTO,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
PricingRepositoryService,
|
||||
PricingTypes,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
@@ -53,8 +55,9 @@ import {
|
||||
RuleTypeService,
|
||||
} from "@services"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { CreatePriceListRuleValueDTO, PricingRepositoryService } from "../types"
|
||||
|
||||
import { validatePriceListDates } from "@utils"
|
||||
import { ServiceTypes } from "@types"
|
||||
import { CreatePriceListRuleValueDTO } from "src/types/services"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
pricingRepository: PricingRepositoryService
|
||||
@@ -426,7 +429,7 @@ export default class PricingModuleService<
|
||||
// Price rules
|
||||
if (priceRulesData.length > 0) {
|
||||
await this.priceRuleService_.create(
|
||||
priceRulesData as PricingTypes.CreatePriceRuleDTO[],
|
||||
priceRulesData as ServiceTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
}
|
||||
@@ -630,8 +633,8 @@ export default class PricingModuleService<
|
||||
|
||||
// Price set money amounts
|
||||
let maCursor = 0
|
||||
const priceSetMoneyAmountsBulkData = input.flatMap(
|
||||
({ priceSetId, prices }) =>
|
||||
const priceSetMoneyAmountsBulkData: unknown[] =
|
||||
input.flatMap(({ priceSetId, prices }) =>
|
||||
prices.map(() => {
|
||||
const ma = createdMoneyAmounts[maCursor]
|
||||
const numberOfRules = Object.entries(
|
||||
@@ -645,10 +648,10 @@ export default class PricingModuleService<
|
||||
rules_count: numberOfRules,
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
const createdPriceSetMoneyAmounts =
|
||||
await this.priceSetMoneyAmountService_.create(
|
||||
priceSetMoneyAmountsBulkData as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
priceSetMoneyAmountsBulkData as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -661,19 +664,15 @@ export default class PricingModuleService<
|
||||
rulesCursor++
|
||||
return Object.entries(rules).map(([k, v]) => ({
|
||||
price_set_money_amount: priceSetMoneyAmount,
|
||||
rule_type: ruleTypeMap.get(priceSetId)!.get(k),
|
||||
rule_type_id: ruleTypeMap.get(priceSetId)!.get(k)!.id,
|
||||
price_set: priceSetId,
|
||||
value: v,
|
||||
price_list_id: "test", // TODO: accept title
|
||||
}))
|
||||
})
|
||||
)
|
||||
|
||||
if (priceRulesBulkData.length > 0) {
|
||||
await this.priceRuleService_.create(
|
||||
priceRulesBulkData as unknown as PricingTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
await this.priceRuleService_.create(priceRulesBulkData, sharedContext)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1272,7 +1271,10 @@ export default class PricingModuleService<
|
||||
data: PricingTypes.CreatePriceRuleDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<PricingTypes.PriceRuleDTO[]> {
|
||||
const priceRules = await this.priceRuleService_.create(data, sharedContext)
|
||||
const priceRules = await this.priceRuleService_.create(
|
||||
data as ServiceTypes.CreatePriceRuleDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.PriceRuleDTO[]>(
|
||||
priceRules,
|
||||
@@ -1428,7 +1430,9 @@ export default class PricingModuleService<
|
||||
const priceListsToCreate: PricingTypes.CreatePriceListDTO[] = []
|
||||
|
||||
for (const priceListData of data) {
|
||||
const { rules = {}, ...priceListOnlyData } = priceListData
|
||||
const { rules = {}, prices = [], ...priceListOnlyData } = priceListData
|
||||
|
||||
validatePriceListDates(priceListData)
|
||||
|
||||
priceListsToCreate.push({
|
||||
...priceListOnlyData,
|
||||
@@ -1494,7 +1498,7 @@ export default class PricingModuleService<
|
||||
title: "test",
|
||||
rules_count: Object.keys(priceRules).length,
|
||||
},
|
||||
] as unknown as PricingTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
] as unknown as ServiceTypes.CreatePriceSetMoneyAmountDTO[],
|
||||
sharedContext
|
||||
)
|
||||
|
||||
@@ -1587,10 +1591,13 @@ export default class PricingModuleService<
|
||||
|
||||
for (const priceListData of data) {
|
||||
const { rules, ...priceListOnlyData } = priceListData
|
||||
const updatePriceListData = {
|
||||
const updatePriceListData: any = {
|
||||
...priceListOnlyData,
|
||||
}
|
||||
|
||||
validatePriceListDates(updatePriceListData)
|
||||
|
||||
|
||||
if (typeof rules === "object") {
|
||||
updatePriceListData.rules_count = Object.keys(rules).length
|
||||
}
|
||||
@@ -2012,7 +2019,7 @@ export default class PricingModuleService<
|
||||
),
|
||||
])
|
||||
|
||||
const priceListRuleValuesToCreate: CreatePriceListRuleValueDTO[] = []
|
||||
const priceListRuleValuesToCreate: unknown[] = []
|
||||
|
||||
for (const { id, price_list, rule_type } of createdRules) {
|
||||
const ruleValues = priceRuleValues.get(
|
||||
@@ -2041,7 +2048,9 @@ export default class PricingModuleService<
|
||||
this.priceListRuleValueService_.delete(
|
||||
priceListValuesToDelete.map((p) => p.id)
|
||||
),
|
||||
this.priceListRuleValueService_.create(priceListRuleValuesToCreate),
|
||||
this.priceListRuleValueService_.create(
|
||||
priceListRuleValuesToCreate as CreatePriceListRuleValueDTO[]
|
||||
),
|
||||
])
|
||||
|
||||
return this.baseRepository_.serialize<PricingTypes.PriceListDTO[]>(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types"
|
||||
import { Context, DAL, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
retrieveEntity,
|
||||
} from "@medusajs/utils"
|
||||
import { RuleType } from "@models"
|
||||
import { ServiceTypes } from "@types"
|
||||
|
||||
type InjectedDependencies = {
|
||||
ruleTypeRepository: DAL.RepositoryService
|
||||
@@ -22,10 +23,10 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async retrieve(
|
||||
ruleTypeId: string,
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity> {
|
||||
return (await retrieveEntity<RuleType, PricingTypes.RuleTypeDTO>({
|
||||
return (await retrieveEntity<RuleType, ServiceTypes.RuleTypeDTO>({
|
||||
id: ruleTypeId,
|
||||
identifierColumn: "id",
|
||||
entityName: RuleType.name,
|
||||
@@ -37,8 +38,8 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async list(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
@@ -51,8 +52,8 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectManager("ruleTypeRepository_")
|
||||
async listAndCount(
|
||||
filters: PricingTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<PricingTypes.RuleTypeDTO> = {},
|
||||
filters: ServiceTypes.FilterableRuleTypeProps = {},
|
||||
config: FindConfig<ServiceTypes.RuleTypeDTO> = {},
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<[TEntity[], number]> {
|
||||
const queryOptions = ModulesSdkUtils.buildQuery<RuleType>(filters, config)
|
||||
@@ -65,7 +66,7 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async create(
|
||||
data: PricingTypes.CreateRuleTypeDTO[],
|
||||
data: ServiceTypes.CreateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.ruleTypeRepository_.create(
|
||||
@@ -76,7 +77,7 @@ export default class RuleTypeService<TEntity extends RuleType = RuleType> {
|
||||
|
||||
@InjectTransactionManager("ruleTypeRepository_")
|
||||
async update(
|
||||
data: PricingTypes.UpdateRuleTypeDTO[],
|
||||
data: ServiceTypes.UpdateRuleTypeDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<TEntity[]> {
|
||||
return (await this.ruleTypeRepository_.update(
|
||||
|
||||
@@ -4,4 +4,5 @@ export type InitializeModuleInjectableDependencies = {
|
||||
logger?: Logger
|
||||
}
|
||||
|
||||
export * from "./repositories"
|
||||
export * as RepositoryTypes from "./repositories"
|
||||
export * as ServiceTypes from "./services"
|
||||
|
||||
13
packages/pricing/src/types/repositories/currency.ts
Normal file
13
packages/pricing/src/types/repositories/currency.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface CreateCurrencyDTO {
|
||||
code: string
|
||||
symbol: string
|
||||
symbol_native: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface UpdateCurrencyDTO {
|
||||
code: string
|
||||
symbol?: string
|
||||
symbol_native?: string
|
||||
name?: string
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
export * from "./price-list"
|
||||
export * from "./currency"
|
||||
export * from "./money-amount"
|
||||
export * from "./price-list-rule-value"
|
||||
export * from "./pricing"
|
||||
export * from "./price-list-rule"
|
||||
export * from "./price-list"
|
||||
export * from "./price-rule"
|
||||
export * from "./price-set-money-amount-rules"
|
||||
export * from "./price-set-money-amount"
|
||||
export * from "./price-set-rule-type"
|
||||
export * from "./price-set"
|
||||
export * from "./rule-type"
|
||||
|
||||
18
packages/pricing/src/types/repositories/money-amount.ts
Normal file
18
packages/pricing/src/types/repositories/money-amount.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Currency } from "@models"
|
||||
|
||||
export interface CreateMoneyAmountDTO {
|
||||
id?: string
|
||||
currency_code: string
|
||||
currency?: Currency
|
||||
amount: number
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
}
|
||||
|
||||
export interface UpdateMoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
}
|
||||
16
packages/pricing/src/types/repositories/price-list-rule.ts
Normal file
16
packages/pricing/src/types/repositories/price-list-rule.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { PriceListDTO, RuleTypeDTO } from "../services"
|
||||
|
||||
export interface CreatePriceListRuleDTO {
|
||||
rule_type_id?: string
|
||||
rule_type?: string | RuleTypeDTO
|
||||
price_list_id?: string
|
||||
price_list?: string | PriceListDTO
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleDTO {
|
||||
id: string
|
||||
price_list_id?: string
|
||||
rule_type_id?: string
|
||||
price_list?: string
|
||||
rule_type?: string
|
||||
}
|
||||
@@ -3,9 +3,18 @@ import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
24
packages/pricing/src/types/repositories/price-rule.ts
Normal file
24
packages/pricing/src/types/repositories/price-rule.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models"
|
||||
import { PriceSetDTO, PriceSetMoneyAmountDTO, RuleTypeDTO } from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceRuleDTO {
|
||||
id?: string
|
||||
price_set_id?: string
|
||||
price_set?: PriceSet | string
|
||||
rule_type_id?: string
|
||||
rule_type?: RuleType | string
|
||||
value: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_set_money_amount?: PriceSetMoneyAmount | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceRuleDTO {
|
||||
id: string
|
||||
price_set_id?: string
|
||||
rule_type_id?: string
|
||||
value?: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_list_id?: string
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export interface CreatePriceSetMoneyAmountRulesDTO {
|
||||
price_set_money_amount: string
|
||||
rule_type: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountRulesDTO {
|
||||
id: string
|
||||
price_set_money_amount?: string
|
||||
rule_type?: string
|
||||
value?: string
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { MoneyAmountDTO, PriceListDTO, PriceSetDTO } from "../services"
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
money_amount?: MoneyAmountDTO
|
||||
}
|
||||
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO | string
|
||||
price_list?: PriceListDTO | string
|
||||
money_amount?: MoneyAmountDTO | string
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PriceSetDTO, RuleTypeDTO } from "../services"
|
||||
|
||||
export interface CreatePriceSetRuleTypeDTO {
|
||||
price_set: PriceSetDTO | string
|
||||
rule_type: RuleTypeDTO | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set?: string
|
||||
rule_type?: string
|
||||
}
|
||||
5
packages/pricing/src/types/repositories/price-set.ts
Normal file
5
packages/pricing/src/types/repositories/price-set.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface CreatePriceSetDTO {}
|
||||
|
||||
export interface UpdatePriceSetDTO {
|
||||
id: string
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import {
|
||||
CalculatedPriceSetDTO,
|
||||
Context,
|
||||
PricingContext,
|
||||
PricingFilters,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface PricingRepositoryService {
|
||||
calculatePrices(
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext,
|
||||
context: Context
|
||||
): Promise<CalculatedPriceSetDTO[]>
|
||||
}
|
||||
13
packages/pricing/src/types/repositories/rule-type.ts
Normal file
13
packages/pricing/src/types/repositories/rule-type.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export interface CreateRuleTypeDTO {
|
||||
id?: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface UpdateRuleTypeDTO {
|
||||
id: string
|
||||
name?: string
|
||||
rule_attribute?: string
|
||||
default_priority?: number
|
||||
}
|
||||
27
packages/pricing/src/types/services/currency.ts
Normal file
27
packages/pricing/src/types/services/currency.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { BaseFilterable } from "@medusajs/types"
|
||||
|
||||
export interface CreateCurrencyDTO {
|
||||
code: string
|
||||
symbol: string
|
||||
symbol_native: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface UpdateCurrencyDTO {
|
||||
code: string
|
||||
symbol?: string
|
||||
symbol_native?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
export interface FilterableCurrencyProps
|
||||
extends BaseFilterable<FilterableCurrencyProps> {
|
||||
code?: string[]
|
||||
}
|
||||
|
||||
export interface CurrencyDTO {
|
||||
code: string
|
||||
symbol?: string
|
||||
symbol_native?: string
|
||||
name?: string
|
||||
}
|
||||
12
packages/pricing/src/types/services/index.ts
Normal file
12
packages/pricing/src/types/services/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export * from "./currency"
|
||||
export * from "./money-amount"
|
||||
export * from "./price-list-rule-value"
|
||||
export * from "./price-list-rule"
|
||||
export * from "./price-list"
|
||||
export * from "./price-rule"
|
||||
export * from "./price-set-money-amount-rules"
|
||||
export * from "./price-set-money-amount"
|
||||
export * from "./price-set-rule-type"
|
||||
export * from "./price-set"
|
||||
export * from "./pricing"
|
||||
export * from "./rule-type"
|
||||
39
packages/pricing/src/types/services/money-amount.ts
Normal file
39
packages/pricing/src/types/services/money-amount.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
CreateCurrencyDTO,
|
||||
CurrencyDTO,
|
||||
PriceSetMoneyAmountDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreateMoneyAmountDTO {
|
||||
id?: string
|
||||
currency_code: string
|
||||
currency?: CreateCurrencyDTO
|
||||
amount: number
|
||||
min_quantity?: number | null
|
||||
max_quantity?: number | null
|
||||
}
|
||||
|
||||
export interface UpdateMoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
}
|
||||
|
||||
export interface MoneyAmountDTO {
|
||||
id: string
|
||||
currency_code?: string
|
||||
currency?: CurrencyDTO
|
||||
amount?: number
|
||||
min_quantity?: number
|
||||
max_quantity?: number
|
||||
price_set_money_amount?: PriceSetMoneyAmountDTO
|
||||
}
|
||||
|
||||
export interface FilterableMoneyAmountProps
|
||||
extends BaseFilterable<FilterableMoneyAmountProps> {
|
||||
id?: string[]
|
||||
currency_code?: string | string[]
|
||||
}
|
||||
26
packages/pricing/src/types/services/price-list-rule-value.ts
Normal file
26
packages/pricing/src/types/services/price-list-rule-value.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { BaseFilterable } from "@medusajs/types"
|
||||
import { PriceListRule } from "@models"
|
||||
|
||||
export interface CreatePriceListRuleValueDTO {
|
||||
price_list_rule_id?: string
|
||||
price_list_rule: PriceListRule | string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface PriceListRuleValueDTO {
|
||||
id: string
|
||||
value: string
|
||||
price_list_rule: PriceListRule
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleValueProps
|
||||
extends BaseFilterable<FilterablePriceListRuleValueProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
price_list_rule_id?: string[]
|
||||
}
|
||||
37
packages/pricing/src/types/services/price-list-rule.ts
Normal file
37
packages/pricing/src/types/services/price-list-rule.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
PriceListDTO,
|
||||
PriceListRuleValueDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceListRuleDTO {
|
||||
rule_type_id?: string
|
||||
rule_type?: string | RuleTypeDTO
|
||||
price_list_id?: string
|
||||
price_list?: string | PriceListDTO
|
||||
}
|
||||
|
||||
export interface UpdatePriceListRuleDTO {
|
||||
id: string
|
||||
price_list_id?: string
|
||||
rule_type_id?: string
|
||||
price_list?: string
|
||||
rule_type?: string
|
||||
}
|
||||
|
||||
export interface PriceListRuleDTO {
|
||||
id: string
|
||||
value: string
|
||||
rule_type: RuleTypeDTO
|
||||
price_list: PriceListDTO
|
||||
price_list_rule_values?: PriceListRuleValueDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListRuleProps
|
||||
extends BaseFilterable<FilterablePriceListRuleProps> {
|
||||
id?: string[]
|
||||
value?: string[]
|
||||
rule_type?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
50
packages/pricing/src/types/services/price-list.ts
Normal file
50
packages/pricing/src/types/services/price-list.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { PriceListStatus, PriceListType } from "@medusajs/utils"
|
||||
import {
|
||||
BaseFilterable,
|
||||
MoneyAmountDTO,
|
||||
PriceListRuleDTO,
|
||||
PriceSetMoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceListDTO {
|
||||
title: string
|
||||
description: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
status?: PriceListStatus
|
||||
type?: PriceListType
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
export interface UpdatePriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
status?: PriceListStatus
|
||||
number_rules?: number
|
||||
}
|
||||
|
||||
export interface PriceListDTO {
|
||||
id: string
|
||||
title?: string
|
||||
starts_at?: string | null
|
||||
status?: PriceListStatus
|
||||
ends_at?: string | null
|
||||
number_rules?: number
|
||||
price_set_money_amounts?: PriceSetMoneyAmountDTO[]
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
rule_types?: RuleTypeDTO[]
|
||||
rules?: PriceListRuleDTO[]
|
||||
price_list_rules?: PriceListRuleDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceListProps
|
||||
extends BaseFilterable<FilterablePriceListProps> {
|
||||
id?: string[]
|
||||
starts_at?: string[]
|
||||
ends_at?: string[]
|
||||
status?: PriceListStatus[]
|
||||
number_rules?: number[]
|
||||
}
|
||||
44
packages/pricing/src/types/services/price-rule.ts
Normal file
44
packages/pricing/src/types/services/price-rule.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { BaseFilterable, PriceSetDTO, PriceSetMoneyAmountDTO, RuleTypeDTO } from "@medusajs/types"
|
||||
import { PriceSet, PriceSetMoneyAmount, RuleType } from "@models"
|
||||
|
||||
export interface CreatePriceRuleDTO {
|
||||
id?: string
|
||||
price_set_id?: string
|
||||
price_set?: PriceSet | string
|
||||
rule_type_id?: string
|
||||
rule_type?: RuleType | string
|
||||
value: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_set_money_amount?: PriceSetMoneyAmount | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceRuleDTO {
|
||||
id: string
|
||||
price_set_id?: string
|
||||
rule_type_id?: string
|
||||
value?: string
|
||||
priority?: number
|
||||
price_set_money_amount_id?: string
|
||||
price_list_id?: string
|
||||
}
|
||||
|
||||
export interface PriceRuleDTO {
|
||||
id: string
|
||||
price_set_id: string
|
||||
price_set: PriceSetDTO
|
||||
rule_type_id: string
|
||||
rule_type: RuleTypeDTO
|
||||
value: string
|
||||
priority: number
|
||||
price_set_money_amount_id: string
|
||||
price_list_id: string
|
||||
}
|
||||
|
||||
export interface FilterablePriceRuleProps
|
||||
extends BaseFilterable<FilterablePriceRuleProps> {
|
||||
id?: string[]
|
||||
name?: string[]
|
||||
price_set_id?: string[]
|
||||
rule_type_id?: string[]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
PriceSetMoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceSetMoneyAmountRulesDTO {
|
||||
price_set_money_amount: string
|
||||
rule_type: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountRulesDTO {
|
||||
id: string
|
||||
price_set_money_amount?: string
|
||||
rule_type?: string
|
||||
value?: string
|
||||
}
|
||||
|
||||
export interface PriceSetMoneyAmountRulesDTO {
|
||||
id: string
|
||||
price_set_money_amount: PriceSetMoneyAmountDTO
|
||||
rule_type: RuleTypeDTO
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetMoneyAmountRulesProps
|
||||
extends BaseFilterable<FilterablePriceSetMoneyAmountRulesProps> {
|
||||
id?: string[]
|
||||
rule_type_id?: string[]
|
||||
price_set_money_amount_id?: string[]
|
||||
value?: string[]
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
MoneyAmountDTO,
|
||||
PriceListDTO,
|
||||
PriceRuleDTO,
|
||||
PriceSetDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface UpdatePriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
money_amount?: MoneyAmountDTO
|
||||
}
|
||||
|
||||
export interface CreatePriceSetMoneyAmountDTO {
|
||||
title?: string
|
||||
price_set?: PriceSetDTO | string
|
||||
price_list?: PriceListDTO | string
|
||||
money_amount?: MoneyAmountDTO | string
|
||||
rules_count?: number
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetMoneyAmountProps
|
||||
extends BaseFilterable<FilterablePriceSetMoneyAmountProps> {
|
||||
id?: string[]
|
||||
price_set_id?: string[]
|
||||
price_list_id?: string[]
|
||||
}
|
||||
|
||||
export interface PriceSetMoneyAmountDTO {
|
||||
id: string
|
||||
title?: string
|
||||
price_set?: PriceSetDTO
|
||||
price_list?: PriceListDTO
|
||||
price_set_id?: string
|
||||
price_rules?: PriceRuleDTO[]
|
||||
money_amount?: MoneyAmountDTO
|
||||
}
|
||||
26
packages/pricing/src/types/services/price-set-rule-type.ts
Normal file
26
packages/pricing/src/types/services/price-set-rule-type.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { BaseFilterable, PriceSetDTO, RuleTypeDTO } from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceSetRuleTypeDTO {
|
||||
price_set: PriceSetDTO | string
|
||||
rule_type: RuleTypeDTO | string
|
||||
}
|
||||
|
||||
export interface UpdatePriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set?: string
|
||||
rule_type?: string
|
||||
}
|
||||
|
||||
export interface PriceSetRuleTypeDTO {
|
||||
id: string
|
||||
price_set: PriceSetDTO
|
||||
rule_type: RuleTypeDTO
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetRuleTypeProps
|
||||
extends BaseFilterable<FilterablePriceSetRuleTypeProps> {
|
||||
id?: string[]
|
||||
rule_type_id?: string[]
|
||||
price_set_id?: string[]
|
||||
}
|
||||
24
packages/pricing/src/types/services/price-set.ts
Normal file
24
packages/pricing/src/types/services/price-set.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
BaseFilterable,
|
||||
FilterableMoneyAmountProps,
|
||||
MoneyAmountDTO,
|
||||
RuleTypeDTO,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export interface CreatePriceSetDTO {}
|
||||
|
||||
export interface UpdatePriceSetDTO {
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface PriceSetDTO {
|
||||
id: string
|
||||
money_amounts?: MoneyAmountDTO[]
|
||||
rule_types?: RuleTypeDTO[]
|
||||
}
|
||||
|
||||
export interface FilterablePriceSetProps
|
||||
extends BaseFilterable<FilterablePriceSetProps> {
|
||||
id?: string[]
|
||||
money_amounts?: FilterableMoneyAmountProps
|
||||
}
|
||||
28
packages/pricing/src/types/services/pricing.ts
Normal file
28
packages/pricing/src/types/services/pricing.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Context } from "@medusajs/types"
|
||||
|
||||
export interface PricingRepositoryService {
|
||||
calculatePrices(
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext,
|
||||
context: Context
|
||||
): Promise<CalculatedPriceSetDTO[]>
|
||||
}
|
||||
|
||||
export interface PricingFilters {
|
||||
id: string[]
|
||||
}
|
||||
|
||||
export interface PricingContext {
|
||||
context?: Record<string, string | number>
|
||||
}
|
||||
|
||||
export interface CalculatedPriceSetDTO {
|
||||
id: string
|
||||
price_set_id: string
|
||||
amount: string | null
|
||||
currency_code: string | null
|
||||
min_quantity: string | null
|
||||
max_quantity: string | null
|
||||
price_list_type: string | null
|
||||
price_list_id: string | null
|
||||
}
|
||||
29
packages/pricing/src/types/services/rule-type.ts
Normal file
29
packages/pricing/src/types/services/rule-type.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { BaseFilterable } from "@medusajs/types"
|
||||
|
||||
export interface CreateRuleTypeDTO {
|
||||
id?: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface UpdateRuleTypeDTO {
|
||||
id: string
|
||||
name?: string
|
||||
rule_attribute?: string
|
||||
default_priority?: number
|
||||
}
|
||||
|
||||
export interface RuleTypeDTO {
|
||||
id: string
|
||||
name: string
|
||||
rule_attribute: string
|
||||
default_priority: number
|
||||
}
|
||||
|
||||
export interface FilterableRuleTypeProps
|
||||
extends BaseFilterable<FilterableRuleTypeProps> {
|
||||
id?: string[]
|
||||
name?: string[]
|
||||
rule_attribute?: string[]
|
||||
}
|
||||
1
packages/pricing/src/utils/index.ts
Normal file
1
packages/pricing/src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./validate-price-list-dates"
|
||||
20
packages/pricing/src/utils/validate-price-list-dates.ts
Normal file
20
packages/pricing/src/utils/validate-price-list-dates.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { isDate, MedusaError } from "@medusajs/utils"
|
||||
|
||||
export const validatePriceListDates = (priceListData: {
|
||||
starts_at?: Date | string | null
|
||||
ends_at?: Date | string | null
|
||||
}) => {
|
||||
if (!!priceListData.starts_at && !isDate(priceListData.starts_at)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Cannot set price list starts at with with invalid date string: ${priceListData.starts_at}`
|
||||
)
|
||||
}
|
||||
|
||||
if (!!priceListData.ends_at && !isDate(priceListData.ends_at)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Cannot set price list ends at with with invalid date string: ${priceListData.ends_at}`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["es2020"],
|
||||
"lib": [
|
||||
"es2020"
|
||||
],
|
||||
"target": "es2020",
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
@@ -16,16 +18,31 @@
|
||||
"noImplicitThis": true,
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"downlevelIteration": true, // to use ES5 specific tooling
|
||||
"downlevelIteration": true,
|
||||
// to use ES5 specific tooling
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
"@models": ["./src/models"],
|
||||
"@services": ["./src/services"],
|
||||
"@repositories": ["./src/repositories"]
|
||||
"@models": [
|
||||
"./src/models"
|
||||
],
|
||||
"@services": [
|
||||
"./src/services"
|
||||
],
|
||||
"@repositories": [
|
||||
"./src/repositories"
|
||||
],
|
||||
"@types": [
|
||||
"./src/types"
|
||||
],
|
||||
"@utils": [
|
||||
"./src/utils"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": ["src"],
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"dist",
|
||||
"./src/**/__tests__",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { CreateMoneyAmountDTO, MoneyAmountDTO } from "./money-amount"
|
||||
import { CreateMoneyAmountDTO, MoneyAmountDTO } from "./money-amount";
|
||||
|
||||
import { BaseFilterable } from "../../dal"
|
||||
import { PriceSetMoneyAmountDTO } from "./price-set-money-amount"
|
||||
import { RuleTypeDTO } from "./rule-type"
|
||||
import { BaseFilterable } from "../../dal";
|
||||
import { PriceSetMoneyAmountDTO } from "./price-set-money-amount";
|
||||
import { RuleTypeDTO } from "./rule-type";
|
||||
|
||||
/**
|
||||
* @enum
|
||||
@@ -152,11 +152,11 @@ export interface CreatePriceListDTO {
|
||||
/**
|
||||
* The price list is enabled starting from this date.
|
||||
*/
|
||||
starts_at?: string
|
||||
starts_at?: Date | string | null
|
||||
/**
|
||||
* The price list expires after this date.
|
||||
*/
|
||||
ends_at?: string
|
||||
ends_at?: Date | string | null
|
||||
/**
|
||||
* The price list's status.
|
||||
*/
|
||||
@@ -193,14 +193,18 @@ export interface UpdatePriceListDTO {
|
||||
* The price list's title.
|
||||
*/
|
||||
title?: string
|
||||
/**
|
||||
* The price list's description.
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* The price list is enabled starting from this date.
|
||||
*/
|
||||
starts_at?: string | null
|
||||
starts_at?: Date | string | null
|
||||
/**
|
||||
* The price list expires after this date.
|
||||
*/
|
||||
ends_at?: string | null
|
||||
ends_at?: Date | string | null
|
||||
/**
|
||||
* The price list's status.
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
import { BaseFilterable } from "../../dal";
|
||||
import { CreateMoneyAmountDTO, FilterableMoneyAmountProps, MoneyAmountDTO } from "./money-amount";
|
||||
import { RuleTypeDTO } from "./rule-type";
|
||||
import { CreatePriceSetPriceRules } from "./price-list";
|
||||
import {
|
||||
CreateMoneyAmountDTO,
|
||||
FilterableMoneyAmountProps,
|
||||
MoneyAmountDTO,
|
||||
} from "./money-amount"
|
||||
import { RuleTypeDTO } from "./rule-type"
|
||||
import { Context } from "../../shared-context"
|
||||
|
||||
export interface PricingRepositoryService {
|
||||
calculatePrices(
|
||||
pricingFilters: PricingFilters,
|
||||
pricingContext: PricingContext,
|
||||
context: Context
|
||||
): Promise<CalculatedPriceSetDTO[]>
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
|
||||
@@ -60,8 +60,8 @@ export interface CreatePriceListWorkflowDTO {
|
||||
name: string
|
||||
description: string
|
||||
type?: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
starts_at?: Date
|
||||
ends_at?: Date
|
||||
status?: PriceListStatus
|
||||
rules_count?: number
|
||||
prices: InputPrice[]
|
||||
|
||||
@@ -10,8 +10,8 @@ export type PriceListVariantPriceDTO = UpdateProductVariantPricesInputDTO & {
|
||||
export interface UpdatePriceListWorkflowDTO {
|
||||
id: string
|
||||
name?: string
|
||||
starts_at?: string
|
||||
ends_at?: string
|
||||
starts_at?: Date
|
||||
ends_at?: Date
|
||||
status?: PriceListStatus
|
||||
rules?: CreatePriceListRules
|
||||
prices?: PriceListVariantPriceDTO[]
|
||||
|
||||
15
packages/utils/src/common/get-iso-string-from-date.ts
Normal file
15
packages/utils/src/common/get-iso-string-from-date.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { isDate } from "./is-date"
|
||||
import { MedusaError } from "./errors"
|
||||
|
||||
export const GetIsoStringFromDate = (date: Date | string) => {
|
||||
if (!isDate(date)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Cannot format date to ISO string: ${date}`
|
||||
)
|
||||
}
|
||||
|
||||
date = new Date(date)
|
||||
|
||||
return date.toISOString()
|
||||
}
|
||||
@@ -15,6 +15,7 @@ export * from "./is-defined"
|
||||
export * from "./is-email"
|
||||
export * from "./is-object"
|
||||
export * from "./is-string"
|
||||
export * from "./get-iso-string-from-date"
|
||||
export * from "./lower-case-first"
|
||||
export * from "./map-object-to"
|
||||
export * from "./medusa-container"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
export function isDate(value: any): value is Date {
|
||||
const date = new Date(value)
|
||||
return !isNaN(date.valueOf())
|
||||
return value !== null && !isNaN(new Date(value).valueOf())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user