Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 42 additions & 0 deletions backend/app/graphql/resolvers/companyApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Season,
CompanyApplicationFeedback,
ApplicationCocktail,
ApplicationInternship,
} from "@generated/type-graphql";
import {
groupBy,
Expand Down Expand Up @@ -109,6 +110,10 @@ import {
CocktailChooseInput,
transformSelect as transformSelectCocktail,
} from "./companyApplicationCocktail";
import {
InternshipCreateInput,
transformSelect as transformSelectInternship
} from "./companyApplicationInternship"
import {
PresenterCreateInput,
transformSelect as transformSelectPresenter,
Expand Down Expand Up @@ -190,6 +195,13 @@ export class CompanyApplicationFieldResolver {
): ApplicationCocktail | null {
return application.cocktail || null;
}

@FieldResolver(() => ApplicationInternship, { nullable: true })
internship(
@Root() application: CompanyApplication,
): ApplicationInternship | null {
return application.internship || null;
}

@FieldResolver(() => [ ApplicationPresenter ])
panelParticipants(
Expand Down Expand Up @@ -310,6 +322,14 @@ export const transformSelect = transformSelectFor<CompanyApplicationFieldResolve
return select;
},

internship(select) {
select.internship = {
select: transformSelectInternship(select.internship as Dict),
};

return select;
},

panelParticipants(select) {
select.panelParticipants = {
select: transformSelectPresenter(select.panelParticipants as Dict),
Expand Down Expand Up @@ -375,6 +395,9 @@ class CompanyApplicationApprovedEditInput {

@Field(() => [ PresenterCreateInput ])
panel: PresenterCreateInput[] = [];

@Field(() => InternshipCreateInput, { nullable: true })
internship: InternshipCreateInput | null = null;
}

@ObjectType()
Expand Down Expand Up @@ -2230,6 +2253,24 @@ export class CompanyApplicationCreateResolver {
}
}

// internship if any approved, likely to change later
if(Object.entries(approval).some(x => x[0] != "id" && x[1])) {
const id = "internship" as const;
const entry = info[id];
if(entry) {
data[id] = {
upsert: {
create: {
...entry
},
update: {
...entry
}
}
}
}
}

const entity = await ctx.prisma.companyApplication.update({
data,
where: {
Expand Down Expand Up @@ -2265,6 +2306,7 @@ export class CompanyApplicationCreateResolver {
type: true
}
},
internship: true,
},
});

Expand Down
122 changes: 122 additions & 0 deletions backend/app/graphql/resolvers/companyApplicationInternship.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { ApplicationInternship, Company, CompanyApplication, FindManyApplicationInternshipArgs } from "@generated/type-graphql";
import {
Args,
Ctx,
Field,
FieldResolver,
Info,
InputType,
Query,
Resolver,
Root,
} from "type-graphql";
import { toSelect, transformSelectFor } from "../helpers/resolver";
import { GraphQLResolveInfo } from "graphql";
import { Context } from "../../types/apollo-context";
import {
transformSelect as transformSelectImage,
} from "./image";
import { Dict } from "../../types/helpers";


@Resolver(() => ApplicationInternship)
export class CompanyApplicationInternshipFieldResolver {
@Field(() => CompanyApplication)
@FieldResolver(() => Company, { nullable: true })
company(
@Root() internship: ApplicationInternship,
): Company | null {
return internship.forApplication?.forCompany ?? null;
}
}
export const transformSelect = transformSelectFor<CompanyApplicationInternshipFieldResolver>({
company(select) {

const rasterLogoSelection = (
(select as Dict)?.company as Dict
)?.rasterLogo as Dict;

select.forApplication = {
select: {
forCompany: {
select: {
uid: true,
brandName: true,
rasterLogo: {
select: transformSelectImage(rasterLogoSelection),
},
},
},
},
};

delete select.company;
return select;
}
});



@Resolver(() => ApplicationInternship)
export class CompanyApplicationInternshipResolver {
@Query(() => [ ApplicationInternship ])
internships(
@Ctx() ctx: Context,
@Info() info: GraphQLResolveInfo,
@Args() args: FindManyApplicationInternshipArgs,
) {
const now = new Date();

return ctx.prisma.applicationInternship.findMany({
...args,
cursor: undefined,
where: {
...(
args.where
? args.where
: {
forApplication: {
forSeason: {
startsAt: {
lte: now,
},
endsAt: {
gte: now,
},
}
}
}
)
},
select: toSelect(info, transformSelect),
})
}
}


@InputType()
export class InternshipCreateInput {
@Field()
position: string = "";

@Field()
competencies: string = "";

@Field()
description: string = "";

@Field(() => Date)
workingPeriodStart: Date = new Date("2022-05-03T17:26:50.810Z");

@Field(() => Date)
workingPeriodEnd: Date = new Date("2022-05-03T17:26:50.810Z");

@Field()
duration: string = "";

@Field()
url: string = "";
}



24 changes: 24 additions & 0 deletions backend/app/graphql/resolvers/companyProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
CompanyApplicationApproval,
CompanyPanel,
ApplicationCocktail,
ApplicationInternship,
} from "@generated/type-graphql";
import {
Dict,
Expand All @@ -35,6 +36,9 @@ import {
import {
transformSelect as transformSelectPanel,
} from "./companyPanel";
import {
transformSelect as transformSelectInternship,
} from "./companyApplicationInternship";

@ObjectType()
export class CompanyProgram {
Expand All @@ -56,6 +60,9 @@ export class CompanyProgram {
@Field(() => CompanyPanel, { nullable: true })
panel: CompanyPanel | null = null;

@Field(() => ApplicationInternship, { nullable: true })
internship: ApplicationInternship | null = null;

approval: CompanyApplicationApproval | null = null;
}

Expand Down Expand Up @@ -115,6 +122,14 @@ export class CompanyProgramFieldResolver {
): GQLField<CompanyPanel, "nullable"> {
return approved(program?.panel, "panel", program);
}

@FieldResolver(() => ApplicationInternship, { nullable: true })
internship(
@Root() program: CompanyProgram,
): GQLField<ApplicationInternship, "nullable"> {
return program?.internship ?? null;
}

}

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

delete select.panel;
}),

internship: withApplications((select) => {
select.applications.select.internship = {
select: transformSelectInternship(select.internship as Dict),
};

delete select.internship;
}),

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- CreateTable
CREATE TABLE "ApplicationInternship" (
"id" SERIAL NOT NULL,
"uid" TEXT NOT NULL,
"position" TEXT NOT NULL,
"competencies" TEXT NOT NULL,
"description" TEXT NOT NULL,
"workingPeriod" TEXT NOT NULL,
"duration" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"forApplicationId" INTEGER NOT NULL,

CONSTRAINT "ApplicationInternship_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "ApplicationInternship_uid_key" ON "ApplicationInternship"("uid");

-- CreateIndex
CREATE UNIQUE INDEX "ApplicationInternship_forApplicationId_key" ON "ApplicationInternship"("forApplicationId");

-- AddForeignKey
ALTER TABLE "ApplicationInternship" ADD CONSTRAINT "ApplicationInternship_forApplicationId_fkey" FOREIGN KEY ("forApplicationId") REFERENCES "CompanyApplication"("id") ON DELETE CASCADE ON UPDATE CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:

- You are about to drop the column `description` on the `ApplicationInternship` table. All the data in the column will be lost.
- You are about to drop the column `workingPeriod` on the `ApplicationInternship` table. All the data in the column will be lost.
- Added the required column `url` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
- Added the required column `workingPeriodEnd` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
- Added the required column `workingPeriodStart` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "ApplicationInternship" DROP COLUMN "description",
DROP COLUMN "workingPeriod",
ADD COLUMN "url" TEXT NOT NULL,
ADD COLUMN "workingPeriodEnd" TIMESTAMP(3) NOT NULL,
ADD COLUMN "workingPeriodStart" TIMESTAMP(3) NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Warnings:

- Added the required column `description` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.
- Added the required column `workingPeriod` to the `ApplicationInternship` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "ApplicationInternship" ADD COLUMN "description" TEXT NOT NULL,
ADD COLUMN "workingPeriod" TEXT NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `workingPeriod` on the `ApplicationInternship` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "ApplicationInternship" DROP COLUMN "workingPeriod";
Loading
Loading