Skip to content

Commit

Permalink
fix with avaiable inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
bahram1249 committed Jun 27, 2024
1 parent 206fb9e commit be013f8
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,18 @@ export class ProductQueryBuilderService {
queryBuilder = queryBuilder.order(orderItem);
}
if (filter.orderBy.startsWith('randomize')) {
// const offsetRandom = await this.sequelize.query(
// `SELECT RAND(CHECKSUM(NEWID()))*SUM([rows]) as offset FROM sys.partitions
// WHERE index_id IN (0, 1) AND [object_id]=OBJECT_ID('dbo.ECProducts')`,
// { type: QueryTypes.SELECT, raw: true },
// );

const offsetRandom = await this.sequelize.query(
`SELECT RAND(CHECKSUM(NEWID()))*SUM([rows]) as offset FROM sys.partitions
WHERE index_id IN (0, 1) AND [object_id]=OBJECT_ID('dbo.ECProducts')`,
`SELECT RAND(CHECKSUM(NEWID()))* count(*) as offset FROM ECProducts
WHERE inventoryStatusId = ${InventoryStatusEnum.available}`,
{ type: QueryTypes.SELECT, raw: true },
);

const offset = Math.round(offsetRandom[0]['offset']);
queryBuilder = queryBuilder
.offset(offset)
Expand Down

0 comments on commit be013f8

Please sign in to comment.