breaking: rename package names to be consistent and under @medusajs scope (#9580)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import { StockLocationModuleService } from "@services"
|
||||
import { ModuleExports } from "@medusajs/framework/types"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
service: StockLocationModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
@@ -0,0 +1,11 @@
|
||||
import { defineJoinerConfig, Modules } from "@medusajs/framework/utils"
|
||||
import { StockLocation } from "./models"
|
||||
import { default as schema } from "./schema"
|
||||
|
||||
export const joinerConfig = defineJoinerConfig(Modules.STOCK_LOCATION, {
|
||||
schema,
|
||||
linkableKeys: {
|
||||
stock_location_id: StockLocation.name,
|
||||
location_id: StockLocation.name,
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,256 @@
|
||||
{
|
||||
"namespaces": ["public"],
|
||||
"name": "public",
|
||||
"tables": [
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"address_1": {
|
||||
"name": "address_1",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"address_2": {
|
||||
"name": "address_2",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"company": {
|
||||
"name": "company",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"city": {
|
||||
"name": "city",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"phone": {
|
||||
"name": "phone",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"province": {
|
||||
"name": "province",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"postal_code": {
|
||||
"name": "postal_code",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
}
|
||||
},
|
||||
"name": "stock_location_address",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_stock_location_address_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_stock_location_address_deleted_at\" ON \"stock_location_address\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "stock_location_address_pkey",
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"created_at": {
|
||||
"name": "created_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"length": 6,
|
||||
"default": "now()",
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"deleted_at": {
|
||||
"name": "deleted_at",
|
||||
"type": "timestamptz",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"length": 6,
|
||||
"mappedType": "datetime"
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": false,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"address_id": {
|
||||
"name": "address_id",
|
||||
"type": "text",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "text"
|
||||
},
|
||||
"metadata": {
|
||||
"name": "metadata",
|
||||
"type": "jsonb",
|
||||
"unsigned": false,
|
||||
"autoincrement": false,
|
||||
"primary": false,
|
||||
"nullable": true,
|
||||
"mappedType": "json"
|
||||
}
|
||||
},
|
||||
"name": "stock_location",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"keyName": "IDX_stock_location_deleted_at",
|
||||
"columnNames": ["deleted_at"],
|
||||
"composite": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_stock_location_deleted_at\" ON \"stock_location\" (deleted_at) WHERE deleted_at IS NOT NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "stock_location_pkey",
|
||||
"columnNames": ["id"],
|
||||
"composite": false,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"stock_location_address_id_foreign": {
|
||||
"constraintName": "stock_location_address_id_foreign",
|
||||
"columnNames": ["address_id"],
|
||||
"localTableName": "public.stock_location",
|
||||
"referencedColumnNames": ["id"],
|
||||
"referencedTableName": "public.stock_location_address",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240307161216 extends Migration {
|
||||
async up(): Promise<void> {
|
||||
this.addSql(
|
||||
'create table if not exists "stock_location_address" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "address_1" text not null, "address_2" text null, "company" text null, "city" text null, "country_code" text not null, "phone" text null, "province" text null, "postal_code" text null, "metadata" jsonb null, constraint "stock_location_address_pkey" primary key ("id"));'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_stock_location_address_deleted_at" ON "stock_location_address" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'create table if not exists "stock_location" ("id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "name" text not null, "address_id" text null, "metadata" jsonb null, constraint "stock_location_pkey" primary key ("id"));'
|
||||
)
|
||||
this.addSql(
|
||||
'CREATE INDEX IF NOT EXISTS "IDX_stock_location_deleted_at" ON "stock_location" (deleted_at) WHERE deleted_at IS NOT NULL;'
|
||||
)
|
||||
|
||||
this.addSql(
|
||||
'alter table if exists "stock_location" add constraint "stock_location_address_id_foreign" foreign key ("address_id") references "stock_location_address" ("id") on update cascade on delete set null;'
|
||||
)
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql(
|
||||
'alter table if exists "stock_location" drop constraint if exists "stock_location_address_id_foreign";'
|
||||
)
|
||||
|
||||
this.addSql('drop table if exists "stock_location_address" cascade;')
|
||||
|
||||
this.addSql('drop table if exists "stock_location" cascade;')
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./stock-location"
|
||||
export * from "./stock-location-address"
|
||||
@@ -0,0 +1,79 @@
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
import {
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
|
||||
const StockLocationAddressDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "stock_location_address",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
export class StockLocationAddress {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@StockLocationAddressDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
address_1: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
address_2: string | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
company: string | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
city: string | null
|
||||
|
||||
@Property({ columnType: "text" })
|
||||
country_code: string
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
phone: string | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
province: string | null
|
||||
|
||||
@Property({ columnType: "text", nullable: true })
|
||||
postal_code: string | null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate(): void {
|
||||
this.id = generateEntityId(this.id, "laddr")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit(): void {
|
||||
this.id = generateEntityId(this.id, "laddr")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
DALUtils,
|
||||
Searchable,
|
||||
createPsqlIndexStatementHelper,
|
||||
generateEntityId,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Entity,
|
||||
Filter,
|
||||
ManyToOne,
|
||||
OnInit,
|
||||
PrimaryKey,
|
||||
Property,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
import { StockLocationAddress } from "./stock-location-address"
|
||||
|
||||
const StockLocationDeletedAtIndex = createPsqlIndexStatementHelper({
|
||||
tableName: "stock_location",
|
||||
columns: "deleted_at",
|
||||
where: "deleted_at IS NOT NULL",
|
||||
})
|
||||
|
||||
@Entity()
|
||||
@Filter(DALUtils.mikroOrmSoftDeletableFilterOptions)
|
||||
export class StockLocation {
|
||||
@PrimaryKey({ columnType: "text" })
|
||||
id: string
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
created_at: Date
|
||||
|
||||
@Property({
|
||||
onCreate: () => new Date(),
|
||||
onUpdate: () => new Date(),
|
||||
columnType: "timestamptz",
|
||||
defaultRaw: "now()",
|
||||
})
|
||||
updated_at: Date
|
||||
|
||||
@StockLocationDeletedAtIndex.MikroORMIndex()
|
||||
@Property({ columnType: "timestamptz", nullable: true })
|
||||
deleted_at: Date | null = null
|
||||
|
||||
@Searchable()
|
||||
@Property({ columnType: "text" })
|
||||
name: string
|
||||
|
||||
@ManyToOne(() => StockLocationAddress, {
|
||||
fieldName: "address_id",
|
||||
type: "text",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
onDelete: "cascade",
|
||||
})
|
||||
address_id: string | null
|
||||
|
||||
@ManyToOne(() => StockLocationAddress, {
|
||||
nullable: true,
|
||||
})
|
||||
address: StockLocationAddress | null
|
||||
|
||||
@Property({ columnType: "jsonb", nullable: true })
|
||||
metadata: Record<string, unknown> | null
|
||||
|
||||
@BeforeCreate()
|
||||
beforeCreate(): void {
|
||||
this.id = generateEntityId(this.id, "sloc")
|
||||
}
|
||||
|
||||
@OnInit()
|
||||
onInit(): void {
|
||||
this.id = generateEntityId(this.id, "sloc")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
export default `
|
||||
type StockLocationAddress {
|
||||
id: ID
|
||||
address_1: String!
|
||||
address_2: String
|
||||
company: String
|
||||
country_code: String!
|
||||
city: String
|
||||
phone: String
|
||||
postal_code: String
|
||||
province: String
|
||||
metadata: JSON
|
||||
created_at: DateTime!
|
||||
updated_at: DateTime!
|
||||
deleted_at: DateTime
|
||||
}
|
||||
|
||||
type StockLocation {
|
||||
id: ID!
|
||||
name: String!
|
||||
metadata: JSON
|
||||
address_id: ID!
|
||||
address: StockLocationAddress
|
||||
created_at: DateTime!
|
||||
updated_at: DateTime!
|
||||
deleted_at: DateTime
|
||||
}
|
||||
|
||||
`
|
||||
@@ -0,0 +1,5 @@
|
||||
describe("noop", function () {
|
||||
it("should run", function () {
|
||||
expect(true).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1 @@
|
||||
export { default as StockLocationModuleService } from "./stock-location-module"
|
||||
@@ -0,0 +1,250 @@
|
||||
import {
|
||||
Context,
|
||||
CreateStockLocationInput,
|
||||
DAL,
|
||||
FilterableStockLocationProps,
|
||||
IEventBusService,
|
||||
InternalModuleDeclaration,
|
||||
IStockLocationService,
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
StockLocationAddressInput,
|
||||
StockLocationTypes,
|
||||
UpdateStockLocationInput,
|
||||
UpsertStockLocationInput,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isString,
|
||||
MedusaContext,
|
||||
MedusaService,
|
||||
Modules,
|
||||
promiseAll,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { StockLocation, StockLocationAddress } from "../models"
|
||||
|
||||
type InjectedDependencies = {
|
||||
[Modules.EVENT_BUS]: IEventBusService
|
||||
baseRepository: DAL.RepositoryService
|
||||
stockLocationService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
stockLocationAddressService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
/**
|
||||
* Service for managing stock locations.
|
||||
*/
|
||||
export default class StockLocationModuleService
|
||||
extends MedusaService<{
|
||||
StockLocation: { dto: StockLocationTypes.StockLocationDTO }
|
||||
StockLocationAddress: { dto: StockLocationTypes.StockLocationAddressDTO }
|
||||
}>({ StockLocation, StockLocationAddress })
|
||||
implements IStockLocationService
|
||||
{
|
||||
protected readonly eventBusModuleService_: IEventBusService
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected readonly stockLocationService_: ModulesSdkTypes.IMedusaInternalService<StockLocation>
|
||||
protected readonly stockLocationAddressService_: ModulesSdkTypes.IMedusaInternalService<StockLocationAddress>
|
||||
|
||||
constructor(
|
||||
{
|
||||
[Modules.EVENT_BUS]: eventBusModuleService,
|
||||
baseRepository,
|
||||
stockLocationService,
|
||||
stockLocationAddressService,
|
||||
}: InjectedDependencies,
|
||||
protected readonly moduleDeclaration?: InternalModuleDeclaration
|
||||
) {
|
||||
// @ts-ignore
|
||||
super(...arguments)
|
||||
|
||||
this.baseRepository_ = baseRepository
|
||||
this.stockLocationService_ = stockLocationService
|
||||
this.stockLocationAddressService_ = stockLocationAddressService
|
||||
this.eventBusModuleService_ = eventBusModuleService
|
||||
}
|
||||
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
createStockLocations(
|
||||
data: CreateStockLocationInput,
|
||||
context: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO>
|
||||
createStockLocations(
|
||||
data: CreateStockLocationInput[],
|
||||
context: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO[]>
|
||||
|
||||
@InjectManager()
|
||||
async createStockLocations(
|
||||
data: CreateStockLocationInput | CreateStockLocationInput[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<
|
||||
StockLocationTypes.StockLocationDTO | StockLocationTypes.StockLocationDTO[]
|
||||
> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const created = await this.createStockLocations_(input, context)
|
||||
|
||||
const serialized = await this.baseRepository_.serialize<
|
||||
| StockLocationTypes.StockLocationDTO
|
||||
| StockLocationTypes.StockLocationDTO[]
|
||||
>(created, { populate: true })
|
||||
|
||||
return Array.isArray(data) ? serialized : serialized[0]
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
async createStockLocations_(
|
||||
data: CreateStockLocationInput[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<StockLocation[]> {
|
||||
return await this.stockLocationService_.create(data, context)
|
||||
}
|
||||
|
||||
async upsertStockLocations(
|
||||
data: UpsertStockLocationInput,
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO>
|
||||
async upsertStockLocations(
|
||||
data: UpsertStockLocationInput[],
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO[]>
|
||||
|
||||
@InjectManager()
|
||||
async upsertStockLocations(
|
||||
data: UpsertStockLocationInput | UpsertStockLocationInput[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<
|
||||
StockLocationTypes.StockLocationDTO | StockLocationTypes.StockLocationDTO[]
|
||||
> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const result = await this.upsertStockLocations_(input, context)
|
||||
|
||||
return await this.baseRepository_.serialize<
|
||||
| StockLocationTypes.StockLocationDTO[]
|
||||
| StockLocationTypes.StockLocationDTO
|
||||
>(Array.isArray(data) ? result : result[0])
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
async upsertStockLocations_(
|
||||
input: UpsertStockLocationInput[],
|
||||
@MedusaContext() context: Context = {}
|
||||
) {
|
||||
const toUpdate = input.filter(
|
||||
(location): location is UpdateStockLocationInput => !!location.id
|
||||
) as UpdateStockLocationInput[]
|
||||
const toCreate = input.filter(
|
||||
(location) => !location.id
|
||||
) as CreateStockLocationInput[]
|
||||
|
||||
const operations: Promise<StockLocation[] | StockLocation>[] = []
|
||||
|
||||
if (toCreate.length) {
|
||||
operations.push(this.createStockLocations_(toCreate, context))
|
||||
}
|
||||
if (toUpdate.length) {
|
||||
operations.push(this.updateStockLocations_(toUpdate, context))
|
||||
}
|
||||
|
||||
return (await promiseAll(operations)).flat()
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
updateStockLocations(
|
||||
id: string,
|
||||
input: UpdateStockLocationInput,
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO>
|
||||
updateStockLocations(
|
||||
selector: FilterableStockLocationProps,
|
||||
input: UpdateStockLocationInput,
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationDTO[]>
|
||||
/**
|
||||
* Updates an existing stock location.
|
||||
* @param stockLocationId - The ID of the stock location to update.
|
||||
* @param updateData - The update data for the stock location.
|
||||
* @param context
|
||||
* @returns The updated stock location.
|
||||
*/
|
||||
@InjectManager()
|
||||
async updateStockLocations(
|
||||
idOrSelector: string | FilterableStockLocationProps,
|
||||
data: UpdateStockLocationInput | UpdateStockLocationInput[],
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<
|
||||
StockLocationTypes.StockLocationDTO | StockLocationTypes.StockLocationDTO[]
|
||||
> {
|
||||
let normalizedInput:
|
||||
| (UpdateStockLocationInput & { id: string })[]
|
||||
| { data: any; selector: FilterableStockLocationProps } = []
|
||||
if (isString(idOrSelector)) {
|
||||
normalizedInput = [{ id: idOrSelector, ...data }]
|
||||
} else {
|
||||
normalizedInput = { data, selector: idOrSelector }
|
||||
}
|
||||
const updated = await this.updateStockLocations_(normalizedInput, context)
|
||||
|
||||
const serialized = await this.baseRepository_.serialize<
|
||||
| StockLocationTypes.StockLocationDTO
|
||||
| StockLocationTypes.StockLocationDTO[]
|
||||
>(updated, { populate: true })
|
||||
|
||||
return Array.isArray(data) ? serialized : serialized[0]
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
async updateStockLocations_(
|
||||
data:
|
||||
| UpdateStockLocationInput[]
|
||||
| UpdateStockLocationInput
|
||||
| { data: any; selector: FilterableStockLocationProps },
|
||||
@MedusaContext() context: Context = {}
|
||||
): Promise<StockLocation[] | StockLocation> {
|
||||
return await this.stockLocationService_.update(data, context)
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
updateStockLocationAddresses(
|
||||
data: StockLocationAddressInput & { id: string },
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationAddressDTO>
|
||||
updateStockLocationAddresses(
|
||||
data: (StockLocationAddressInput & { id: string })[],
|
||||
context?: Context
|
||||
): Promise<StockLocationTypes.StockLocationAddressDTO[]>
|
||||
|
||||
@InjectManager()
|
||||
async updateStockLocationAddresses(
|
||||
data:
|
||||
| (StockLocationAddressInput & { id: string })
|
||||
| (StockLocationAddressInput & { id: string })[],
|
||||
@MedusaContext() context: Context = {}
|
||||
) {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const updated = await this.updateStockLocationAddresses_(input, context)
|
||||
|
||||
const serialized = await this.baseRepository_.serialize<
|
||||
| StockLocationTypes.StockLocationAddressDTO
|
||||
| StockLocationTypes.StockLocationAddressDTO[]
|
||||
>(updated, { populate: true })
|
||||
|
||||
return Array.isArray(data) ? serialized : serialized[0]
|
||||
}
|
||||
|
||||
@InjectTransactionManager()
|
||||
private async updateStockLocationAddresses_(
|
||||
input: (StockLocationAddressInput & { id: string })[],
|
||||
@MedusaContext() context: Context
|
||||
) {
|
||||
return await this.stockLocationAddressService_.update(input, context)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user