Skip to content

Commit

Permalink
Merge pull request #57 from iliubinskii/feature/company-search
Browse files Browse the repository at this point in the history
Feature/company search
  • Loading branch information
iliubinskii authored Aug 5, 2024
2 parents 3e1c052 + 220df73 commit 930a7a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/routes/companies/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,14 @@ export interface GetUserModel {
* @param options.sortBy - The field to sort companies by.
* @param options.sortOrder - The order to sort companies by.
* @param options.status - The status of the companies.
* @param options.q - The query to search companies by.
* @returns The filter to get companies.
*/
function buildFilter({
cursor,
includePrivateCompanies = false,
onlyRecommended = false,
q,
sortBy = "name",
sortOrder = "asc",
status
Expand All @@ -276,6 +278,8 @@ function buildFilter({
];
}

if (q) filter["$text"] = { $search: q };

if (includePrivateCompanies) {
// Include both public and private companies
} else filter["privateCompany"] = { $ne: true };
Expand Down
2 changes: 2 additions & 0 deletions src/schema-mongodb/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const CompanySchema = new mongoose.Schema(
{ versionKey: false }
);

CompanySchema.index({ description: "text", name: "text" });

/**
* Creates a company model.
* @param connection - The mongoose connection.
Expand Down
1 change: 1 addition & 0 deletions src/schema/get-all-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface GetCompaniesOptions {
readonly limit?: number | undefined;
readonly offset?: number | undefined;
readonly onlyRecommended?: boolean | undefined;
readonly q?: string | null | undefined;
readonly sortBy?: "createdAt" | "foundedAt" | "name" | undefined;
readonly sortOrder?: "asc" | "desc" | undefined;
readonly status?: CompanyStatus | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/schema/get-all-options.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const GetCompaniesOptionsValidationSchema = zod.object({
limit: LimitValidationSchema,
offset: OffsetValidationSchema,
onlyRecommended: preprocessBoolean(zod.boolean()).optional(),
q: zod.string().optional(),
sortBy: zod
.union([
zod.literal("createdAt"),
Expand Down

0 comments on commit 930a7a7

Please sign in to comment.