Skip to content

Commit 89731aa

Browse files
pavleergDinoWw
andauthored
Summer internships (#21)
* add internship field to approved company application backend * add internships Query * add url to ApplicationInternship * added summer internships * deleted old migration file * fixed application data not loading, added info messgae to profile dashboard --------- Co-authored-by: Dino Plecko <[email protected]>
1 parent d9e226f commit 89731aa

File tree

20 files changed

+1218
-46
lines changed

20 files changed

+1218
-46
lines changed

backend/app/graphql/resolvers/companyApplication.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
Season,
2929
CompanyApplicationFeedback,
3030
ApplicationCocktail,
31+
ApplicationInternship,
3132
} from "@generated/type-graphql";
3233
import {
3334
groupBy,
@@ -109,6 +110,10 @@ import {
109110
CocktailChooseInput,
110111
transformSelect as transformSelectCocktail,
111112
} from "./companyApplicationCocktail";
113+
import {
114+
InternshipCreateInput,
115+
transformSelect as transformSelectInternship
116+
} from "./companyApplicationInternship"
112117
import {
113118
PresenterCreateInput,
114119
transformSelect as transformSelectPresenter,
@@ -190,6 +195,13 @@ export class CompanyApplicationFieldResolver {
190195
): ApplicationCocktail | null {
191196
return application.cocktail || null;
192197
}
198+
199+
@FieldResolver(() => ApplicationInternship, { nullable: true })
200+
internship(
201+
@Root() application: CompanyApplication,
202+
): ApplicationInternship | null {
203+
return application.internship || null;
204+
}
193205

194206
@FieldResolver(() => [ ApplicationPresenter ])
195207
panelParticipants(
@@ -310,6 +322,14 @@ export const transformSelect = transformSelectFor<CompanyApplicationFieldResolve
310322
return select;
311323
},
312324

325+
internship(select) {
326+
select.internship = {
327+
select: transformSelectInternship(select.internship as Dict),
328+
};
329+
330+
return select;
331+
},
332+
313333
panelParticipants(select) {
314334
select.panelParticipants = {
315335
select: transformSelectPresenter(select.panelParticipants as Dict),
@@ -375,6 +395,9 @@ class CompanyApplicationApprovedEditInput {
375395

376396
@Field(() => [ PresenterCreateInput ])
377397
panel: PresenterCreateInput[] = [];
398+
399+
@Field(() => InternshipCreateInput, { nullable: true })
400+
internship: InternshipCreateInput | null = null;
378401
}
379402

380403
@ObjectType()
@@ -2230,6 +2253,24 @@ export class CompanyApplicationCreateResolver {
22302253
}
22312254
}
22322255

2256+
// internship if any approved, likely to change later
2257+
if(Object.entries(approval).some(x => x[0] != "id" && x[1])) {
2258+
const id = "internship" as const;
2259+
const entry = info[id];
2260+
if(entry) {
2261+
data[id] = {
2262+
upsert: {
2263+
create: {
2264+
...entry
2265+
},
2266+
update: {
2267+
...entry
2268+
}
2269+
}
2270+
}
2271+
}
2272+
}
2273+
22332274
const entity = await ctx.prisma.companyApplication.update({
22342275
data,
22352276
where: {
@@ -2265,6 +2306,7 @@ export class CompanyApplicationCreateResolver {
22652306
type: true
22662307
}
22672308
},
2309+
internship: true,
22682310
},
22692311
});
22702312

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { ApplicationInternship, Company, CompanyApplication, FindManyApplicationInternshipArgs } from "@generated/type-graphql";
2+
import {
3+
Args,
4+
Ctx,
5+
Field,
6+
FieldResolver,
7+
Info,
8+
InputType,
9+
Query,
10+
Resolver,
11+
Root,
12+
} from "type-graphql";
13+
import { toSelect, transformSelectFor } from "../helpers/resolver";
14+
import { GraphQLResolveInfo } from "graphql";
15+
import { Context } from "../../types/apollo-context";
16+
import {
17+
transformSelect as transformSelectImage,
18+
} from "./image";
19+
import { Dict } from "../../types/helpers";
20+
21+
22+
@Resolver(() => ApplicationInternship)
23+
export class CompanyApplicationInternshipFieldResolver {
24+
@Field(() => CompanyApplication)
25+
@FieldResolver(() => Company, { nullable: true })
26+
company(
27+
@Root() internship: ApplicationInternship,
28+
): Company | null {
29+
return internship.forApplication?.forCompany ?? null;
30+
}
31+
}
32+
export const transformSelect = transformSelectFor<CompanyApplicationInternshipFieldResolver>({
33+
company(select) {
34+
35+
const rasterLogoSelection = (
36+
(select as Dict)?.company as Dict
37+
)?.rasterLogo as Dict;
38+
39+
select.forApplication = {
40+
select: {
41+
forCompany: {
42+
select: {
43+
uid: true,
44+
brandName: true,
45+
rasterLogo: {
46+
select: transformSelectImage(rasterLogoSelection),
47+
},
48+
},
49+
},
50+
},
51+
};
52+
53+
delete select.company;
54+
return select;
55+
}
56+
});
57+
58+
59+
60+
@Resolver(() => ApplicationInternship)
61+
export class CompanyApplicationInternshipResolver {
62+
@Query(() => [ ApplicationInternship ])
63+
internships(
64+
@Ctx() ctx: Context,
65+
@Info() info: GraphQLResolveInfo,
66+
@Args() args: FindManyApplicationInternshipArgs,
67+
) {
68+
const now = new Date();
69+
70+
return ctx.prisma.applicationInternship.findMany({
71+
...args,
72+
cursor: undefined,
73+
where: {
74+
...(
75+
args.where
76+
? args.where
77+
: {
78+
forApplication: {
79+
forSeason: {
80+
startsAt: {
81+
lte: now,
82+
},
83+
endsAt: {
84+
gte: now,
85+
},
86+
}
87+
}
88+
}
89+
)
90+
},
91+
select: toSelect(info, transformSelect),
92+
})
93+
}
94+
}
95+
96+
97+
@InputType()
98+
export class InternshipCreateInput {
99+
@Field()
100+
position: string = "";
101+
102+
@Field()
103+
competencies: string = "";
104+
105+
@Field()
106+
description: string = "";
107+
108+
@Field(() => Date)
109+
workingPeriodStart: Date = new Date("2022-05-03T17:26:50.810Z");
110+
111+
@Field(() => Date)
112+
workingPeriodEnd: Date = new Date("2022-05-03T17:26:50.810Z");
113+
114+
@Field()
115+
duration: string = "";
116+
117+
@Field()
118+
url: string = "";
119+
}
120+
121+
122+

backend/app/graphql/resolvers/companyProgram.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
CompanyApplicationApproval,
1313
CompanyPanel,
1414
ApplicationCocktail,
15+
ApplicationInternship,
1516
} from "@generated/type-graphql";
1617
import {
1718
Dict,
@@ -35,6 +36,9 @@ import {
3536
import {
3637
transformSelect as transformSelectPanel,
3738
} from "./companyPanel";
39+
import {
40+
transformSelect as transformSelectInternship,
41+
} from "./companyApplicationInternship";
3842

3943
@ObjectType()
4044
export class CompanyProgram {
@@ -56,6 +60,9 @@ export class CompanyProgram {
5660
@Field(() => CompanyPanel, { nullable: true })
5761
panel: CompanyPanel | null = null;
5862

63+
@Field(() => ApplicationInternship, { nullable: true })
64+
internship: ApplicationInternship | null = null;
65+
5966
approval: CompanyApplicationApproval | null = null;
6067
}
6168

@@ -115,6 +122,14 @@ export class CompanyProgramFieldResolver {
115122
): GQLField<CompanyPanel, "nullable"> {
116123
return approved(program?.panel, "panel", program);
117124
}
125+
126+
@FieldResolver(() => ApplicationInternship, { nullable: true })
127+
internship(
128+
@Root() program: CompanyProgram,
129+
): GQLField<ApplicationInternship, "nullable"> {
130+
return program?.internship ?? null;
131+
}
132+
118133
}
119134

120135
type WithApplications<T> = T & {
@@ -211,4 +226,13 @@ export const transformSelect = transformSelectFor<CompanyProgramFieldResolver>({
211226

212227
delete select.panel;
213228
}),
229+
230+
internship: withApplications((select) => {
231+
select.applications.select.internship = {
232+
select: transformSelectInternship(select.internship as Dict),
233+
};
234+
235+
delete select.internship;
236+
}),
237+
214238
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- CreateTable
2+
CREATE TABLE "ApplicationInternship" (
3+
"id" SERIAL NOT NULL,
4+
"uid" TEXT NOT NULL,
5+
"position" TEXT NOT NULL,
6+
"competencies" TEXT NOT NULL,
7+
"description" TEXT NOT NULL,
8+
"workingPeriod" TEXT NOT NULL,
9+
"duration" TEXT NOT NULL,
10+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
"updatedAt" TIMESTAMP(3) NOT NULL,
12+
"forApplicationId" INTEGER NOT NULL,
13+
14+
CONSTRAINT "ApplicationInternship_pkey" PRIMARY KEY ("id")
15+
);
16+
17+
-- CreateIndex
18+
CREATE UNIQUE INDEX "ApplicationInternship_uid_key" ON "ApplicationInternship"("uid");
19+
20+
-- CreateIndex
21+
CREATE UNIQUE INDEX "ApplicationInternship_forApplicationId_key" ON "ApplicationInternship"("forApplicationId");
22+
23+
-- AddForeignKey
24+
ALTER TABLE "ApplicationInternship" ADD CONSTRAINT "ApplicationInternship_forApplicationId_fkey" FOREIGN KEY ("forApplicationId") REFERENCES "CompanyApplication"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `description` on the `ApplicationInternship` table. All the data in the column will be lost.
5+
- You are about to drop the column `workingPeriod` on the `ApplicationInternship` table. All the data in the column will be lost.
6+
- Added the required column `url` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
7+
- Added the required column `workingPeriodEnd` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
8+
- Added the required column `workingPeriodStart` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
9+
10+
*/
11+
-- AlterTable
12+
ALTER TABLE "ApplicationInternship" DROP COLUMN "description",
13+
DROP COLUMN "workingPeriod",
14+
ADD COLUMN "url" TEXT NOT NULL,
15+
ADD COLUMN "workingPeriodEnd" TIMESTAMP(3) NOT NULL,
16+
ADD COLUMN "workingPeriodStart" TIMESTAMP(3) NOT NULL;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Warnings:
3+
4+
- Added the required column `description` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
5+
- Added the required column `workingPeriod` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
6+
7+
*/
8+
-- AlterTable
9+
ALTER TABLE "ApplicationInternship" ADD COLUMN "description" TEXT NOT NULL,
10+
ADD COLUMN "workingPeriod" TEXT NOT NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `workingPeriod` on the `ApplicationInternship` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "ApplicationInternship" DROP COLUMN "workingPeriod";

0 commit comments

Comments
 (0)