feat(medusa, stock-location, types): Add q and order params to list-stock-locations (#6197)
**What** - add `q` and `order` params to list-stock-location endpoint closes #6189
This commit is contained in:
1 parent
3db2f95e65
commit
d1c18a3090
9 files changed
+263
-33
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { IStockLocationService } from "@medusajs/types"
|
||||
import { IsOptional } from "class-validator"
|
||||
import { IsOptional, IsString } from "class-validator"
|
||||
import { Request, Response } from "express"
|
||||
import {
|
||||
SalesChannelLocationService,
|
||||
@@ -231,6 +231,13 @@ export class AdminGetStockLocationsParams extends extendedFindParamsMixin({
|
||||
limit: 20,
|
||||
offset: 0,
|
||||
}) {
|
||||
/**
|
||||
* Search term to search stock location names.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
q?: string
|
||||
|
||||
/**
|
||||
* IDs to filter stock locations by.
|
||||
*/
|
||||
@@ -258,4 +265,11 @@ export class AdminGetStockLocationsParams extends extendedFindParamsMixin({
|
||||
@IsOptional()
|
||||
@IsType([String, [String]])
|
||||
sales_channel_id?: string | string[]
|
||||
|
||||
/**
|
||||
* The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`.
|
||||
*/
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
order?: string
|
||||
}
|
||||
@@ -12,12 +12,12 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
InjectEntityManager,
|
||||
isDefined,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
isDefined,
|
||||
setMetadata,
|
||||
} from "@medusajs/utils"
|
||||
import { EntityManager } from "typeorm"
|
||||
import { EntityManager, FindOptionsWhere, ILike } from "typeorm"
|
||||
import { joinerConfig } from "../joiner-config"
|
||||
import { StockLocation, StockLocationAddress } from "../models"
|
||||
import { buildQuery } from "../utils/build-query"
|
||||
@@ -66,11 +66,8 @@ export default class StockLocationService {
|
||||
config: FindConfig<StockLocation> = { relations: [], skip: 0, take: 10 },
|
||||
context: SharedContext = {}
|
||||
): Promise<StockLocation[]> {
|
||||
const manager = context.transactionManager ?? this.manager_
|
||||
const locationRepo = manager.getRepository(StockLocation)
|
||||
|
||||
const query = buildQuery(selector, config)
|
||||
return await locationRepo.find(query)
|
||||
const [locations] = await this.listAndCount(selector, config, context)
|
||||
return locations
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,8 +84,27 @@ export default class StockLocationService {
|
||||
): Promise<[StockLocation[], number]> {
|
||||
const manager = context.transactionManager ?? this.manager_
|
||||
const locationRepo = manager.getRepository(StockLocation)
|
||||
let q
|
||||
if (selector.q) {
|
||||
q = selector.q
|
||||
delete selector.q
|
||||
}
|
||||
|
||||
const query = buildQuery(selector, config)
|
||||
|
||||
if (q) {
|
||||
const where = query.where as FindOptionsWhere<StockLocation>
|
||||
|
||||
delete where.name
|
||||
|
||||
query.where = [
|
||||
{
|
||||
...where,
|
||||
name: ILike(`%${q}%`),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
return await locationRepo.findAndCount(query)
|
||||
}
|
||||
|
||||
|
||||
@@ -153,10 +153,14 @@ export type StockLocationExpandedDTO = StockLocationDTO & {
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
*
|
||||
* The filters to apply on the retrieved stock locations.
|
||||
*/
|
||||
export type FilterableStockLocationProps = {
|
||||
/**
|
||||
* Search parameter for stock location names
|
||||
*/
|
||||
q?: string
|
||||
/**
|
||||
* The IDs to filter stock locations by.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user