Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/backend/src/domains/commerce.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { WishlistModule } from "../modules/wishlist/wishlist.module";
import { InventoryModule } from "./commerce/inventory/inventory.module";
import { PostModule } from "./commerce/post/post.module";
import { ProductModule } from "./commerce/product/product.module";
import { SearchModule } from "./commerce/search/search.module";
import { SourcedProductModule } from "./commerce/sourced-product/sourced-product.module";

@Module({
imports: [
CategoryModule,
ProductModule,
PostModule,
SearchModule,
InventoryModule,
SourcedProductModule,
CartModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Transform, Type } from "class-transformer";
import {
IsBooleanString,
IsIn,
IsInt,
IsOptional,
IsString,
Matches,
Max,
MaxLength,
Min,
} from "class-validator";

const toOptionalString = (value: unknown): unknown =>
value == null ? value : String(value);

export type SearchResultType = "products" | "stores" | "posts" | "all";

export class SearchQueryDto {
@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsString()
@MaxLength(120)
q?: string;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsIn(["products", "stores", "posts", "all"])
type?: SearchResultType;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsString()
@MaxLength(80)
category?: string;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@Matches(/^\d+$/)
minPrice?: string;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@Matches(/^\d+$/)
maxPrice?: string;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsString()
@MaxLength(60)
color?: string;

@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsString()
@MaxLength(80)
location?: string;

@IsOptional()
@IsBooleanString()
inStock?: string;
Comment on lines +59 to +61
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Rename boolean query flag to follow the API naming convention.

inStock should be renamed to isInStock (and propagated through service contracts) to match the backend boolean-field rule.

As per coding guidelines: "All boolean field names must be prefixed with 'is', 'has', 'can', or 'should'."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/backend/src/domains/commerce/search/dto/search-query.dto.ts` around
lines 59 - 61, Rename the boolean query flag property in SearchQueryDto from
inStock to isInStock: update the property name (`@IsOptional`() `@IsBooleanString`()
inStock?: string) to isInStock and update all usages and service contracts that
accept or map this DTO (search services, controllers, and any
mappers/validators) so the DTO, method signatures, parameter names, and
downstream mappings consistently use isInStock; also update any tests and API
docs to reflect the new field name.


@Transform(({ value }) => toOptionalString(value))
@IsOptional()
@IsString()
cursor?: string;

@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(50)
limit?: number;
}
14 changes: 14 additions & 0 deletions apps/backend/src/domains/commerce/search/search.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Controller, Get, Query } from "@nestjs/common";

import { SearchQueryDto } from "./dto/search-query.dto";
import { SearchService } from "./search.service";

@Controller("search")
export class SearchController {
constructor(private readonly searchService: SearchService) {}

@Get()
search(@Query() query: SearchQueryDto) {
return this.searchService.search(query);
}
}
11 changes: 11 additions & 0 deletions apps/backend/src/domains/commerce/search/search.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from "@nestjs/common";

import { SearchController } from "./search.controller";
import { SearchService } from "./search.service";

@Module({
controllers: [SearchController],
providers: [SearchService],
exports: [SearchService],
})
export class SearchModule {}
Loading
Loading