Skip to content

Commit 5ce93e4

Browse files
authored
Merge pull request #2 from codeday/dev-universal-autocomplete
Expand functionality of `autocomplete` resolver to support universal search
2 parents 6d09dd4 + 2258efa commit 5ce93e4

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/resolvers/Autocomplete.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ export class AutocompleteResolver {
2121
@Arg('types', () => AutocompleteFilterTypeInput) types: AutocompleteFilterTypeInput,
2222
@Arg('status', () => [StudentStatus], { defaultValue: [StudentStatus.ACCEPTED] }) status: StudentStatus[],
2323
@Arg('q', () => String) q: string,
24+
@Arg('universal', () => Boolean, { nullable: true, defaultValue: false}) universal?: boolean,
2425
): Promise<AutocompleteResult[]> {
2526
const lookups: (() => Promise<AutocompleteResult[]>)[] = [];
2627

2728
if (types.students) {
2829
lookups.push(async () =>
2930
(await this.prisma.student.findMany({
3031
where: {
31-
eventId: auth.eventId,
32+
eventId: (universal === true) ? undefined : auth.eventId,
3233
AND: [
3334
{
3435
OR: status.map(s => ({
@@ -48,6 +49,7 @@ export class AutocompleteResolver {
4849
.map(s => ({
4950
name: `${s.givenName} ${s.surname} (${s.email})`,
5051
id: s.id,
52+
eventId: s.eventId,
5153
type: AutocompleteType.STUDENT,
5254
}) as AutocompleteResult)
5355
);
@@ -57,7 +59,7 @@ export class AutocompleteResolver {
5759
lookups.push(async () =>
5860
(await this.prisma.mentor.findMany({
5961
where: {
60-
eventId: auth.eventId,
62+
eventId: (universal === true) ? undefined : auth.eventId,
6163
status: 'ACCEPTED',
6264
OR: [
6365
{ givenName: { contains: q, mode: 'insensitive'} },
@@ -69,6 +71,7 @@ export class AutocompleteResolver {
6971
.map(m => ({
7072
name: `${m.givenName} ${m.surname} (${m.email})`,
7173
id: m.id,
74+
eventId: m.eventId,
7275
type: AutocompleteType.MENTOR,
7376
}) as AutocompleteResult)
7477
);
@@ -78,14 +81,18 @@ export class AutocompleteResolver {
7881
lookups.push(async () =>
7982
(await this.prisma.project.findMany({
8083
where: {
81-
eventId: auth.eventId,
84+
eventId: (universal === true) ? undefined : auth.eventId,
8285
status: { in: ['ACCEPTED', 'MATCHED' ]},
83-
description: { contains: q, mode: 'insensitive'}
86+
OR: [
87+
{ description: { contains: q, mode: 'insensitive'} },
88+
{ issueUrl: { contains: q, mode: 'insensitive' } },
89+
]
8490
},
8591
}))
86-
.map(m => ({
87-
name: `${m.description?.slice(0,40)}...`,
88-
id: m.id,
92+
.map(p => ({
93+
name: `${p.description?.slice(0,40)}...`,
94+
id: p.id,
95+
eventId: p.eventId,
8996
type: AutocompleteType.PROJECT,
9097
}) as AutocompleteResult)
9198
);

src/types/AutocompleteResult.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ export class AutocompleteResult {
1818

1919
@Field(() => String)
2020
id: String;
21+
22+
@Field(() => String)
23+
eventId: String;
2124
}

0 commit comments

Comments
 (0)