-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#2741 - Ministry Filter Search Programs and Offerings [Location Search] #3819
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { IsEnum, IsIn, IsOptional, Max, MaxLength, Min } from "class-validator"; | ||
import { PAGINATION_SEARCH_MAX_LENGTH } from "../../constants"; | ||
import { FieldSortOrder } from "@sims/utilities"; | ||
import { ProgramStatus } from "@sims/sims-db"; | ||
|
||
/** | ||
* Common parameters used when an API result | ||
|
@@ -77,6 +78,15 @@ export class ProgramsPaginationOptionsAPIInDTO extends PaginationOptionsAPIInDTO | |
@IsOptional() | ||
@IsIn(["submittedDate", "programName", "credentialType"]) | ||
sortField?: string; | ||
@IsOptional() | ||
@MaxLength(PAGINATION_SEARCH_MAX_LENGTH) | ||
programNameSearch?: string; | ||
@IsOptional() | ||
@MaxLength(PAGINATION_SEARCH_MAX_LENGTH) | ||
locationNameSearch?: string; | ||
@IsOptional() | ||
@IsIn([ProgramStatus.Approved, ProgramStatus.Declined, ProgramStatus.Pending]) | ||
status?: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please keep the naming pattern from the others: |
||
} | ||
|
||
export class OfferingsPaginationOptionsAPIInDTO extends PaginationOptionsAPIInDTO { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,9 +33,9 @@ import { | |
} from "./education-program.service.models"; | ||
import { | ||
sortProgramsColumnMap, | ||
PaginationOptions, | ||
PaginatedResults, | ||
SortPriority, | ||
ProgramPaginationOptions, | ||
} from "../../utilities"; | ||
import { | ||
CustomNamedError, | ||
|
@@ -271,14 +271,14 @@ export class EducationProgramService extends RecordDataModelService<EducationPro | |
* Gets all the programs that are associated with an institution | ||
* alongside with the total of offerings on locations. | ||
* @param institutionId id of the institution. | ||
* @param paginationOptions pagination options. | ||
* @param paginationOptions program related pagination options. | ||
* @param locationId optional location id to filter. | ||
* @returns paginated summary for the institution or location. | ||
*/ | ||
async getProgramsSummary( | ||
institutionId: number, | ||
offeringTypes: OfferingTypes[], | ||
paginationOptions: PaginationOptions, | ||
paginationOptions: ProgramPaginationOptions, | ||
locationId?: number, | ||
): Promise<PaginatedResults<EducationProgramsSummary>> { | ||
const paginatedProgramQuery = this.repo | ||
|
@@ -331,6 +331,33 @@ export class EducationProgramService extends RecordDataModelService<EducationPro | |
}); | ||
queryParams.push(`%${paginationOptions.searchCriteria}%`); | ||
} | ||
if (paginationOptions.programNameSearch) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please correct me if i am wrong, the paginationOptions, if searched with only one criteria, paginationOptions.searchCriteria is used else the paginationOptions.programNameSearch and paginationOptions.locationNameSearch is pushed. If that is the case, either paginationOptions.searchCriteria should be pushed or the paginationOptions.programNameSearch and paginationOptions.locationNameSearch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
export interface BasePaginationOptions {
sortField?: string;
sortOrder?: FieldSortOrder;
page: number;
pageLimit: number;
}
/**
* Pagination option.
*/
export interface PaginationOptions extends BasePaginationOptions {
searchCriteria?: string;
}
export interface ProgramPaginationOptions extends BasePaginationOptions {
programNameSearch?: string;
locationNameSearch?: string;
status?: string;
} |
||
paginatedProgramQuery.andWhere( | ||
"programs.name Ilike :programNameSearchCriteria", | ||
{ | ||
programNameSearchCriteria: `%${paginationOptions.programNameSearch}%`, | ||
}, | ||
); | ||
queryParams.push(`%${paginationOptions.programNameSearch}%`); | ||
} | ||
if (paginationOptions.locationNameSearch) { | ||
paginatedProgramQuery.andWhere( | ||
"location.name Ilike :locationNameSearchCriteria", | ||
{ | ||
locationNameSearchCriteria: `%${paginationOptions.locationNameSearch}%`, | ||
}, | ||
); | ||
queryParams.push(`%${paginationOptions.locationNameSearch}%`); | ||
} | ||
if (paginationOptions.status) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
paginatedProgramQuery.andWhere( | ||
"programs.programStatus Ilike :programStatusSearchCriteria", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
programStatusSearchCriteria: `%${paginationOptions.status}%`, | ||
}, | ||
); | ||
queryParams.push(`%${paginationOptions.status}%`); | ||
} | ||
|
||
// For getting total raw count before pagination. | ||
const sqlQuery = paginatedProgramQuery.getSql(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,12 @@ export interface PaginationOptions { | |
pageLimit: number; | ||
} | ||
|
||
export interface ProgramPaginationOptions extends PaginationOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see suggested changes here: https://github.com/bcgov/SIMS/pull/3819/files#r1813295340 |
||
programNameSearch?: string; | ||
locationNameSearch?: string; | ||
status?: string; | ||
} | ||
|
||
export enum SortPriority { | ||
Priority1 = 1, | ||
Priority2 = 2, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,10 +88,22 @@ export const getPaginationQueryString = ( | |
} | ||
|
||
// Search criteria. | ||
if (paginationOptions.searchCriteria) { | ||
if ( | ||
paginationOptions.searchCriteria && | ||
typeof paginationOptions.searchCriteria === "string" | ||
) { | ||
parameters.push( | ||
`${PaginationParams.SearchCriteria}=${paginationOptions.searchCriteria}`, | ||
); | ||
} | ||
if ( | ||
paginationOptions.searchCriteria && | ||
typeof paginationOptions.searchCriteria === "object" | ||
) { | ||
const searchCriteria = paginationOptions.searchCriteria; | ||
for (const searchCriterion in searchCriteria) { | ||
parameters.push(`${searchCriterion}=${searchCriteria[searchCriterion]}`); | ||
} | ||
} | ||
Comment on lines
+99
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: if (!paginationOptions.searchCriteria) {
return parameters.join("&");
}
// Search criteria.
if (typeof paginationOptions.searchCriteria === "string") {
// Single search criteria.
parameters.push(
`${PaginationParams.SearchCriteria}=${paginationOptions.searchCriteria}`,
);
return parameters.join("&");
}
// Multiple search criteria.
const searchCriteria = paginationOptions.searchCriteria;
for (const searchCriterion in paginationOptions.searchCriteria) {
parameters.push(`${searchCriterion}=${searchCriteria[searchCriterion]}`);
}
return parameters.join("&"); |
||
return parameters.join("&"); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ export enum PaginationParams { | |
* todo: remove sortOrder: DataTableSortOrder when all primevue datatables are removed. | ||
*/ | ||
export interface PaginationOptions { | ||
searchCriteria?: string; | ||
searchCriteria?: string | Record<string, string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment to this parameter. |
||
sortField?: string; | ||
sortOrder?: DataTableSortOrder | DataTableSortByOrder; | ||
page: number; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a reason why the dropdown for statuses was not included in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, as discussed in call with you, there was some confusion related to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that it is safe to replace the
@IsIn
by@IsEnum(ProgramStatus)
.