fix(stock-location): Stock location address required (#3065)
What: - Removes the requirement to have an address id while creating a new stock location. - Add field company to Location Address FIXES: CORE-1018 Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f65f590a27
commit
2d525237b6
6
.changeset/clean-rockets-grow.md
Normal file
6
.changeset/clean-rockets-grow.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
"@medusajs/stock-location": patch
|
||||
---
|
||||
|
||||
Fix (stock-location): stock location address required
|
||||
@@ -92,6 +92,10 @@ class StockLocationAddress {
|
||||
@IsString()
|
||||
address_2?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
company?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
city?: string
|
||||
|
||||
@@ -92,6 +92,10 @@ class StockLocationAddress {
|
||||
@IsString()
|
||||
address_2?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
company?: string
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
city?: string
|
||||
|
||||
@@ -23,6 +23,10 @@ import { StringComparisonOperator } from "./common"
|
||||
* type: string
|
||||
* description: Stock location address' complement
|
||||
* example: apartment 4432
|
||||
* company:
|
||||
* type: string
|
||||
* description: Stock location company' name
|
||||
* example: Medusa
|
||||
* city:
|
||||
* type: string
|
||||
* description: Stock location address' city
|
||||
@@ -64,6 +68,7 @@ export type StockLocationAddressDTO = {
|
||||
id?: string
|
||||
address_1: string
|
||||
address_2?: string | null
|
||||
company?: string | null
|
||||
country_code: string
|
||||
city?: string | null
|
||||
phone?: string | null
|
||||
|
||||
@@ -55,6 +55,7 @@ export class setup1665749860179 implements MigrationInterface {
|
||||
"deleted_at" TIMESTAMP WITH TIME zone,
|
||||
"address_1" TEXT NOT NULL,
|
||||
"address_2" TEXT,
|
||||
"company" TEXT,
|
||||
"city" TEXT,
|
||||
"country_code" TEXT NOT NULL,
|
||||
"phone" TEXT,
|
||||
@@ -73,12 +74,12 @@ export class setup1665749860179 implements MigrationInterface {
|
||||
"updated_at" TIMESTAMP WITH time zone NOT NULL DEFAULT Now(),
|
||||
"deleted_at" TIMESTAMP WITH time zone,
|
||||
"name" TEXT NOT NULL,
|
||||
"address_id" TEXT NOT NULL,
|
||||
"address_id" TEXT,
|
||||
"metadata" JSONB,
|
||||
CONSTRAINT "PK_adf770067d0df1421f525fa25cc" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
CREATE INDEX "IDX_stock_location_address_id" ON "stock_location" ("address_id");
|
||||
CREATE INDEX "IDX_stock_location_address_id" ON "stock_location" ("address_id") WHERE deleted_at IS NOT NULL;
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ export class StockLocationAddress extends SoftDeletableEntity {
|
||||
@Column({ type: "text", nullable: true })
|
||||
address_2: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
company: string | null
|
||||
|
||||
@Column({ type: "text", nullable: true })
|
||||
city: string | null
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ export class StockLocation extends SoftDeletableEntity {
|
||||
name: string
|
||||
|
||||
@Index()
|
||||
@Column({ type: "text" })
|
||||
address_id: string
|
||||
@Column({ type: "text", nullable: true })
|
||||
address_id: string | null
|
||||
|
||||
@ManyToOne(() => StockLocationAddress)
|
||||
@JoinColumn({ name: "address_id" })
|
||||
|
||||
@@ -62,9 +62,9 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
|
||||
/**
|
||||
* Lists all stock locations that match the given selector.
|
||||
* @param {FilterableStockLocationProps} [selector={}] - Properties to filter by.
|
||||
* @param {FindConfig} [config={ relations: [], skip: 0, take: 10 }] - Additional configuration for the query.
|
||||
* @return {Promise<StockLocation[]>} A list of stock locations.
|
||||
* @param selector - Properties to filter by.
|
||||
* @param config - Additional configuration for the query.
|
||||
* @return A list of stock locations.
|
||||
*/
|
||||
async list(
|
||||
selector: FilterableStockLocationProps = {},
|
||||
@@ -79,9 +79,9 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
|
||||
/**
|
||||
* Lists all stock locations that match the given selector and returns the count of matching stock locations.
|
||||
* @param {FilterableStockLocationProps} [selector={}] - Properties to filter by.
|
||||
* @param {FindConfig} [config={ relations: [], skip: 0, take: 10 }] - Additional configuration for the query.
|
||||
* @return {Promise<[StockLocation[], number]>} A list of stock locations and the count of matching stock locations.
|
||||
* @param selector - Properties to filter by.
|
||||
* @param config - Additional configuration for the query.
|
||||
* @return A list of stock locations and the count of matching stock locations.
|
||||
*/
|
||||
async listAndCount(
|
||||
selector: FilterableStockLocationProps = {},
|
||||
@@ -95,12 +95,11 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a stock location by its ID.
|
||||
* @param {string} stockLocationId - The ID of the stock location.
|
||||
* @param {FindConfig} [config={}] - Additional configuration for the query.
|
||||
* @return {Promise<StockLocation>} The stock location.
|
||||
* @throws {MedusaError} If the stock location ID is not defined.
|
||||
* @throws {MedusaError} If the stock location with the given ID was not found.
|
||||
* Retrieves a Stock Location by its ID.
|
||||
* @param stockLocationId - The ID of the stock location.
|
||||
* @param config - Additional configuration for the query.
|
||||
* @return The stock location.
|
||||
* @throws If the stock location ID is not definedor the stock location with the given ID was not found.
|
||||
*/
|
||||
async retrieve(
|
||||
stockLocationId: string,
|
||||
@@ -131,8 +130,8 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
|
||||
/**
|
||||
* Creates a new stock location.
|
||||
* @param {CreateStockLocationInput} data - The input data for creating a stock location.
|
||||
* @returns {Promise<StockLocation>} - The created stock location.
|
||||
* @param data - The input data for creating a Stock Location.
|
||||
* @returns The created stock location.
|
||||
*/
|
||||
async create(data: CreateStockLocationInput): Promise<StockLocation> {
|
||||
return await this.atomicPhase_(async (manager) => {
|
||||
@@ -145,10 +144,7 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
if (isDefined(data.address) || isDefined(data.address_id)) {
|
||||
if (typeof data.address === "string" || data.address_id) {
|
||||
const addrId = (data.address ?? data.address_id) as string
|
||||
const address = await this.retrieve(addrId, {
|
||||
select: ["id"],
|
||||
})
|
||||
loc.address_id = address.id
|
||||
loc.address_id = addrId
|
||||
} else {
|
||||
const locAddressRepo = manager.getRepository(StockLocationAddress)
|
||||
const locAddress = locAddressRepo.create(data.address!)
|
||||
@@ -176,9 +172,9 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
|
||||
/**
|
||||
* Updates an existing stock location.
|
||||
* @param {string} stockLocationId - The ID of the stock location to update.
|
||||
* @param {UpdateStockLocationInput} updateData - The update data for the stock location.
|
||||
* @returns {Promise<StockLocation>} - The updated stock location.
|
||||
* @param stockLocationId - The ID of the stock location to update.
|
||||
* @param updateData - The update data for the stock location.
|
||||
* @returns The updated stock location.
|
||||
*/
|
||||
|
||||
async update(
|
||||
@@ -223,10 +219,10 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an address for a stock location.
|
||||
* @param {string} addressId - The ID of the address to update.
|
||||
* @param {StockLocationAddressInput} address - The update data for the address.
|
||||
* @returns {Promise<StockLocationAddress>} - The updated stock location address.
|
||||
* Updates an address for a Stock Location.
|
||||
* @param addressId - The ID of the address to update.
|
||||
* @param address - The update data for the address.
|
||||
* @returns The updated stock location address.
|
||||
*/
|
||||
|
||||
protected async updateAddress(
|
||||
@@ -265,9 +261,9 @@ export default class StockLocationService extends TransactionBaseService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a stock location.
|
||||
* @param {string} id - The ID of the stock location to delete.
|
||||
* @returns {Promise<void>} - An empty promise.
|
||||
* Deletes a Stock Location.
|
||||
* @param id - The ID of the stock location to delete.
|
||||
* @returns An empty promise.
|
||||
*/
|
||||
async delete(id: string): Promise<void> {
|
||||
return await this.atomicPhase_(async (manager) => {
|
||||
|
||||
Reference in New Issue
Block a user