diff --git a/.changeset/clean-rockets-grow.md b/.changeset/clean-rockets-grow.md new file mode 100644 index 0000000000..b95ac73870 --- /dev/null +++ b/.changeset/clean-rockets-grow.md @@ -0,0 +1,6 @@ +--- +"@medusajs/medusa": patch +"@medusajs/stock-location": patch +--- + +Fix (stock-location): stock location address required diff --git a/packages/medusa/src/api/routes/admin/stock-locations/create-stock-location.ts b/packages/medusa/src/api/routes/admin/stock-locations/create-stock-location.ts index 511f3a7ee3..6e8f665054 100644 --- a/packages/medusa/src/api/routes/admin/stock-locations/create-stock-location.ts +++ b/packages/medusa/src/api/routes/admin/stock-locations/create-stock-location.ts @@ -92,6 +92,10 @@ class StockLocationAddress { @IsString() address_2?: string + @IsOptional() + @IsString() + company?: string + @IsOptional() @IsString() city?: string diff --git a/packages/medusa/src/api/routes/admin/stock-locations/update-stock-location.ts b/packages/medusa/src/api/routes/admin/stock-locations/update-stock-location.ts index bba4cbc784..f0f1975397 100644 --- a/packages/medusa/src/api/routes/admin/stock-locations/update-stock-location.ts +++ b/packages/medusa/src/api/routes/admin/stock-locations/update-stock-location.ts @@ -92,6 +92,10 @@ class StockLocationAddress { @IsString() address_2?: string + @IsOptional() + @IsString() + company?: string + @IsOptional() @IsString() city?: string diff --git a/packages/medusa/src/types/stock-location.ts b/packages/medusa/src/types/stock-location.ts index e5f401ac00..5d81692f45 100644 --- a/packages/medusa/src/types/stock-location.ts +++ b/packages/medusa/src/types/stock-location.ts @@ -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 diff --git a/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts b/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts index 3a941c5227..2712bae839 100644 --- a/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts +++ b/packages/stock-location/src/migrations/schema-migrations/1665749860179-setup.ts @@ -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; `) } diff --git a/packages/stock-location/src/models/stock-location-address.ts b/packages/stock-location/src/models/stock-location-address.ts index 1db150c2ad..1e8563d6c5 100644 --- a/packages/stock-location/src/models/stock-location-address.ts +++ b/packages/stock-location/src/models/stock-location-address.ts @@ -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 diff --git a/packages/stock-location/src/models/stock-location.ts b/packages/stock-location/src/models/stock-location.ts index 204e1ff302..74a1d716f9 100644 --- a/packages/stock-location/src/models/stock-location.ts +++ b/packages/stock-location/src/models/stock-location.ts @@ -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" }) diff --git a/packages/stock-location/src/services/stock-location.ts b/packages/stock-location/src/services/stock-location.ts index b33eda506f..75118b7841 100644 --- a/packages/stock-location/src/services/stock-location.ts +++ b/packages/stock-location/src/services/stock-location.ts @@ -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} 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} 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} - The created stock location. + * @param data - The input data for creating a Stock Location. + * @returns The created stock location. */ async create(data: CreateStockLocationInput): Promise { 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} - 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} - 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} - 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 { return await this.atomicPhase_(async (manager) => {