Skip to content
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

feat: add search by surname to proposal table #728

Merged
merged 26 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f8e0d1b
Add filtering for postgres db
ellen-wright Aug 14, 2024
60c42f2
Merge branch 'develop' of https://github.com/UserOfficeProject/user-o…
ellen-wright Aug 14, 2024
e51b196
Merge branch 'develop' of https://github.com/UserOfficeProject/user-o…
ellen-wright Aug 20, 2024
5fde216
Merge branch 'develop' of https://github.com/UserOfficeProject/user-o…
ellen-wright Aug 29, 2024
8eeca06
Add surname search for STFC
ellen-wright Aug 29, 2024
157badd
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 3, 2024
771b98d
Add instrument scientist search for non-STFC proposal data source
ellen-wright Sep 9, 2024
cb20999
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 9, 2024
1fd120e
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 12, 2024
59e11ab
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 12, 2024
6963e84
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 16, 2024
b916854
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Sep 30, 2024
a73b238
Remove stfc references from postgres datasource
ellen-wright Oct 2, 2024
9482935
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 2, 2024
d2ecbc8
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 3, 2024
2c6b9f6
Merge branch 'develop' into 913-add-search-by-name-and-email
mutambaraf Oct 3, 2024
02b06f6
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 10, 2024
7ec151e
remove unecessary function
ellen-wright Oct 10, 2024
2e4738f
Merge branch '913-add-search-by-name-and-email' of https://github.com…
ellen-wright Oct 10, 2024
60fb7ef
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 10, 2024
aab29d1
Remove logging
ellen-wright Oct 10, 2024
f0d750f
Merge branch '913-add-search-by-name-and-email' of https://github.com…
ellen-wright Oct 10, 2024
8bda794
resolve test error
ellen-wright Oct 10, 2024
4c95457
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 11, 2024
e8944bb
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 11, 2024
7b1e284
Merge branch 'develop' into 913-add-search-by-name-and-email
ellen-wright Oct 15, 2024
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
26 changes: 25 additions & 1 deletion apps/backend/src/datasources/postgres/ProposalDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,22 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
offset?: number,
sortField?: string,
sortDirection?: string,
searchText?: string
searchText?: string,
principleInvestigator?: number[]
): Promise<{ totalCount: number; proposalViews: ProposalView[] }> {
const principalInvestigator = principleInvestigator
? principleInvestigator
: [];

return database
.select(['*', database.raw('count(*) OVER() AS full_count')])
.from('proposal_table_view')
.join(
'users',
'users.user_id',
'=',
'proposal_table_view.principal_investigator'
)
.modify((query) => {
if (filter?.callId) {
query.where('call_id', filter?.callId);
Expand Down Expand Up @@ -427,6 +438,10 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
.orWhereRaw('proposal_id ILIKE ?', `%${searchText}%`)
.orWhereRaw('title ILIKE ?', `%${searchText}%`)
.orWhereRaw('proposal_status_name ILIKE ?', `%${searchText}%`)
.orWhere('users.email', 'ilike', `%${searchText}%`)
.orWhere('users.firstname', 'ilike', `%${searchText}%`)
.orWhere('users.lastname', 'ilike', `%${searchText}%`)
.orWhere('principal_investigator', 'in', principalInvestigator)
// NOTE: Using jsonpath we check the jsonb (instruments) field if it contains object with name equal to searchText case insensitive
.orWhereRaw(
'jsonb_path_exists(instruments, \'$[*].name \\? (@.type() == "string" && @ like_regex :searchText: flag "i")\')',
Expand Down Expand Up @@ -569,6 +584,12 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
return database
.select(['*', database.raw('count(*) OVER() AS full_count')])
.from('proposal_table_view')
.join(
'users',
'users.user_id',
'=',
'proposal_table_view.principal_investigator'
)
.where(function () {
if (user.currentRole?.shortCode === Roles.INTERNAL_REVIEWER) {
// NOTE: Using jsonpath we check the jsonb (technical_reviews) field if it contains internalReviewers array of objects with id equal to user.id
Expand All @@ -595,6 +616,9 @@ export default class PostgresProposalDataSource implements ProposalDataSource {
.orWhereRaw('title ILIKE ?', `%${filter.text}%`)
.orWhereRaw('proposal_id ILIKE ?', `%${filter.text}%`)
.orWhereRaw('proposal_status_name ILIKE ?', `%${filter.text}%`)
.orWhereRaw('users.email ILIKE', `%${filter.text}%`)
.orWhereRaw('users.firstname ILIKE', `%${filter.text}%`)
.orWhereRaw('users.lastname ILIKE', `%${filter.text}%`)
// NOTE: Using jsonpath we check the jsonb (instruments) field if it contains object with name equal to searchText case insensitive
.orWhereRaw(
'jsonb_path_exists(instruments, \'$[*].name \\? (@.type() == "string" && @ like_regex :searchText: flag "i")\')',
Expand Down
29 changes: 27 additions & 2 deletions apps/backend/src/datasources/stfc/StfcProposalDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export default class StfcProposalDataSource extends PostgresProposalDataSource {
first?: number,
offset?: number
): Promise<{ totalCount: number; proposals: ProposalView[] }> {
const stfcUserIds: number[] = filter?.text
? [
...(
await stfcUserDataSource.getUsers({ filter: filter.text })
).users.map((user) => user.id),
]
: [];

const proposals = database
.select('proposal_pk')
.from('proposal_table_view')
Expand Down Expand Up @@ -59,10 +67,15 @@ export default class StfcProposalDataSource extends PostgresProposalDataSource {
);
}
});

const result = database
.select(['*', database.raw('count(*) OVER() AS full_count')])
.from('proposal_table_view')
.join(
'users',
'users.user_id',
'=',
'proposal_table_view.principal_investigator'
)
.whereIn('proposal_pk', proposals)
.orderBy('proposal_pk', 'desc')
.modify((query) => {
Expand All @@ -71,6 +84,10 @@ export default class StfcProposalDataSource extends PostgresProposalDataSource {
this.where('title', 'ilike', `%${filter.text}%`)
.orWhere('proposal_id', 'ilike', `%${filter.text}%`)
.orWhere('proposal_status_name', 'ilike', `%${filter.text}%`)
.orWhere('users.email', 'ilike', `%${filter.text}%`)
.orWhere('users.firstname', 'ilike', `%${filter.text}%`)
.orWhere('users.lastname', 'ilike', `%${filter.text}%`)
.orWhere('principal_investigator', 'in', stfcUserIds)
// NOTE: Using jsonpath we check the jsonb (instruments) field if it contains object with name equal to searchText case insensitive
.orWhereRaw(
'jsonb_path_exists(instruments, \'$[*].name \\? (@.type() == "string" && @ like_regex :searchText: flag "i")\')',
Expand Down Expand Up @@ -156,13 +173,21 @@ export default class StfcProposalDataSource extends PostgresProposalDataSource {
sortDirection?: string,
searchText?: string
): Promise<{ totalCount: number; proposalViews: ProposalView[] }> {
const stfcUserIds: number[] = searchText
? [
...(
await stfcUserDataSource.getUsers({ filter: searchText })
).users.map((ids) => ids.id),
]
: [];
const proposals = await super.getProposalsFromView(
filter,
first,
offset,
sortField,
sortDirection,
searchText
searchText,
stfcUserIds
);

const technicalReviewers = removeDuplicates(
Expand Down
Loading