Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit 9f02a09

Browse files
author
Tischa
committed
Create filter on application
1 parent 34c6c14 commit 9f02a09

File tree

9 files changed

+106
-103
lines changed

9 files changed

+106
-103
lines changed

server/prisma/migrations/20210725080216_name_to_displayname/migration.sql

Lines changed: 0 additions & 10 deletions
This file was deleted.

server/prisma/migrations/20210725125303_/migration.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

server/prisma/migrations/20210725201313_add_provider_column/migration.sql

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/prisma/migrations/20210727074858_init/migration.sql renamed to server/prisma/migrations/20210727092840_init/migration.sql

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ CREATE TYPE "Role" AS ENUM ('USER', 'COACH', 'ADMIN');
44
-- CreateEnum
55
CREATE TYPE "Status" AS ENUM ('YES', 'MAYBE', 'NO');
66

7+
-- CreateEnum
8+
CREATE TYPE "OAuthProvider" AS ENUM ('GITHUB');
9+
710
-- CreateTable
811
CREATE TABLE "User" (
912
"id" SERIAL NOT NULL,
1013
"uuid" TEXT NOT NULL,
14+
"externalId" TEXT,
15+
"provider" "OAuthProvider",
1116
"email" TEXT NOT NULL,
12-
"firstname" TEXT NOT NULL,
13-
"lastname" TEXT NOT NULL,
17+
"displayName" TEXT NOT NULL,
18+
"firstname" TEXT,
19+
"lastname" TEXT,
1420
"imageUrl" TEXT,
1521
"role" "Role" NOT NULL DEFAULT E'USER',
1622
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -175,6 +181,9 @@ CREATE TABLE "Question" (
175181
-- CreateIndex
176182
CREATE UNIQUE INDEX "User.uuid_unique" ON "User"("uuid");
177183

184+
-- CreateIndex
185+
CREATE UNIQUE INDEX "User.externalId_unique" ON "User"("externalId");
186+
178187
-- CreateIndex
179188
CREATE UNIQUE INDEX "User.email_unique" ON "User"("email");
180189

server/prisma/seed.ts

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ const prisma = new PrismaClient();
66
async function main() {
77
console.log('seeding...');
88

9-
for (let i = 0; i < 10; i++) {
10-
await prisma.user.upsert({
11-
where: { email: faker.internet.email() },
12-
update: {},
13-
create: {
14-
uuid: faker.datatype.uuid(),
15-
email: faker.internet.email(),
16-
firstname: faker.name.firstName(),
17-
lastname: faker.name.lastName(),
18-
role: Math.random() < 0.5 ? Role.COACH : Role.USER
19-
}
20-
});
9+
// for (let i = 0; i < 10; i++) {
10+
// await prisma.user.upsert({
11+
// where: { email: faker.internet.email() },
12+
// update: {},
13+
// create: {
14+
// uuid: faker.datatype.uuid(),
15+
// email: faker.internet.email(),
16+
// firstname: faker.name.firstName(),
17+
// lastname: faker.name.lastName(),
18+
// role: Math.random() < 0.5 ? Role.COACH : Role.USER
19+
// }
20+
// });
2121

22-
const genders = ['male', 'female', 'nonbinary'];
22+
// const genders = ['male', 'female', 'nonbinary'];
2323

24-
await prisma.applicant.upsert({
25-
where: { email: faker.internet.email() },
26-
update: {},
27-
create: {
28-
uuid: faker.datatype.uuid(),
29-
email: faker.internet.email(),
30-
firstname: faker.name.firstName(),
31-
lastname: faker.name.lastName(),
32-
gender: genders[Math.floor(Math.random() * genders.length)],
33-
nationality: 'Belgian',
34-
phone: faker.phone.phoneNumber(),
35-
address: {
36-
create: {
37-
addressLine: faker.address.streetAddress(),
38-
city: faker.address.cityName(),
39-
postalCode: faker.address.zipCode(),
40-
state: faker.address.state(),
41-
country: faker.address.country()
42-
}
43-
},
44-
isAlumni: Math.random() < 0.5
45-
}
46-
});
47-
}
24+
// await prisma.applicant.upsert({
25+
// where: { email: faker.internet.email() },
26+
// update: {},
27+
// create: {
28+
// uuid: faker.datatype.uuid(),
29+
// email: faker.internet.email(),
30+
// firstname: faker.name.firstName(),
31+
// lastname: faker.name.lastName(),
32+
// gender: genders[Math.floor(Math.random() * genders.length)],
33+
// nationality: 'Belgian',
34+
// phone: faker.phone.phoneNumber(),
35+
// address: {
36+
// create: {
37+
// addressLine: faker.address.streetAddress(),
38+
// city: faker.address.cityName(),
39+
// postalCode: faker.address.zipCode(),
40+
// state: faker.address.state(),
41+
// country: faker.address.country()
42+
// }
43+
// },
44+
// isAlumni: Math.random() < 0.5
45+
// }
46+
// });
47+
// }
4848
}
4949

5050
main()

server/src/applicants/applicants.service.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,34 @@ export class ApplicantsService {
3333
const { profiles_every, projects_every, suggestions_every, skills_every, ...whereArgs } =
3434
where || {};
3535

36+
//todo: filter parents with more than one condition
37+
38+
const filter = {
39+
...whereArgs,
40+
profiles: {
41+
some: { profile: profiles_every }
42+
},
43+
projects: {
44+
some: { project: projects_every }
45+
},
46+
suggestions: {
47+
every: suggestions_every
48+
},
49+
skillset: {
50+
every: { skill: skills_every }
51+
}
52+
};
53+
3654
let applicants = await this.prisma.applicant.findMany({
3755
include: this.applicantIncludes,
38-
where: {
39-
...whereArgs,
40-
profiles: {
41-
every: { profile: profiles_every }
42-
},
43-
projects: {
44-
every: { project: projects_every }
45-
},
46-
suggestions: {
47-
every: suggestions_every
48-
},
49-
skillset: {
50-
every: { skill: skills_every }
51-
}
52-
}
56+
where: filter
5357
});
5458

59+
console.log(applicants);
60+
61+
console.log(filter);
62+
63+
// todo refactor
5564
if (projects_every) applicants = applicants.filter((applicant) => applicant.projects.length);
5665
if (profiles_every) applicants = applicants.filter((applicant) => applicant.profiles.length);
5766

server/src/applicants/dto/filterApplicant.input.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import { FilterSkillInput } from '../../skills/dto/filterSkill.input';
88

99
@InputType()
1010
export class FilterApplicantInput {
11-
@Field((type) => FilterApplicantInput, { nullable: true })
12-
AND?: FilterApplicantInput;
11+
@Field((type) => [FilterApplicantInput], { nullable: true })
12+
AND?: FilterApplicantInput[];
1313

14-
@Field((type) => FilterApplicantInput, { nullable: true })
15-
OR?: FilterApplicantInput;
14+
@Field((type) => [FilterApplicantInput], { nullable: true })
15+
OR?: FilterApplicantInput[];
1616

17-
@Field((type) => FilterApplicantInput, { nullable: true })
18-
NOT?: FilterApplicantInput;
17+
@Field((type) => [FilterApplicantInput], { nullable: true })
18+
NOT?: FilterApplicantInput[];
1919

2020
@Field((type) => StringFilter, { nullable: true })
2121
email?: StringFilter;

server/src/profiles/dto/filterProfile.input.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { StringFilter } from '../../helpers/stringFilter.input';
33

44
@InputType()
55
export class FilterProfileInput {
6-
@Field((type) => FilterProfileInput, { nullable: true })
7-
AND?: FilterProfileInput;
6+
@Field((type) => [FilterProfileInput], { nullable: true })
7+
AND?: FilterProfileInput[];
88

9-
@Field((type) => FilterProfileInput, { nullable: true })
10-
OR?: FilterProfileInput;
9+
@Field((type) => [FilterProfileInput], { nullable: true })
10+
OR?: FilterProfileInput[];
1111

12-
@Field((type) => FilterProfileInput, { nullable: true })
13-
NOT?: FilterProfileInput;
12+
@Field((type) => [FilterProfileInput], { nullable: true })
13+
NOT?: FilterProfileInput[];
1414

1515
@Field((type) => StringFilter, { nullable: true })
1616
name: StringFilter;

server/src/schema.gql

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ type Query {
113113
}
114114

115115
input FilterApplicantInput {
116-
AND: FilterApplicantInput
117-
OR: FilterApplicantInput
118-
NOT: FilterApplicantInput
116+
AND: [FilterApplicantInput!]
117+
OR: [FilterApplicantInput!]
118+
NOT: [FilterApplicantInput!]
119119
email: StringFilter
120120
firstname: StringFilter
121121
lastname: StringFilter
@@ -127,6 +127,8 @@ input FilterApplicantInput {
127127
isAlumni: Boolean
128128
profiles_every: FilterProfileInput
129129
projects_every: FilterProjectInput
130+
suggestions_every: FilterSuggestionInput
131+
skills_every: FilterSkillInput
130132
}
131133

132134
input StringFilter {
@@ -154,9 +156,9 @@ input FilterAddressInput {
154156
}
155157

156158
input FilterProfileInput {
157-
AND: FilterProfileInput
158-
OR: FilterProfileInput
159-
NOT: FilterProfileInput
159+
AND: [FilterProfileInput!]
160+
OR: [FilterProfileInput!]
161+
NOT: [FilterProfileInput!]
160162
name: StringFilter
161163
}
162164

@@ -169,14 +171,27 @@ input FilterProjectInput {
169171
leadCoachId: Float
170172
}
171173

174+
input FilterSuggestionInput {
175+
AND: FilterSuggestionInput
176+
OR: FilterSuggestionInput
177+
NOT: FilterSuggestionInput
178+
status: StringFilter
179+
}
180+
181+
input FilterSkillInput {
182+
AND: FilterSkillInput
183+
OR: FilterSkillInput
184+
NOT: FilterSkillInput
185+
name: StringFilter
186+
}
187+
172188
type Mutation {
173189
createApplicant(input: CreateApplicantInput!): Applicant!
174190
updateApplicant(input: UpdateApplicantInput!, uuid: String!): Applicant!
175191
deleteApplicant(uuid: String!): Boolean!
176192
addApplicantToProject(projectId: Int!, applicantId: Int!): Boolean!
177193
removeApplicantFromProject(projectId: Int!, applicantId: Int!): Boolean!
178194
addSkillToApplicant(level: String!, skill: String!, applicantId: Int!): Boolean!
179-
createUser(input: CreateUserInput!): User!
180195
updateUser(input: UpdateUserInput!, uuid: String!): User!
181196
deleteUser(uuid: String!): Boolean!
182197
addUserToProject(projectId: Int!, userId: Int!): Boolean!

0 commit comments

Comments
 (0)