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

Company router #23

Merged
merged 8 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
128 changes: 123 additions & 5 deletions prisma/schema.prisma
banushi-a marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ datasource db {
url = env("DATABASE_URL")
}

// Necessary for Next auth
// Necessary for NextAuth
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? // @db.Text
access_token String? // @db.Text
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String? // @db.Text
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

Expand All @@ -42,13 +42,15 @@ model Session {
}

model User {
id String @id @default(cuid())
id String @id @unique @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]

profile Profile?
}

model VerificationToken {
Expand All @@ -58,3 +60,119 @@ model VerificationToken {

@@unique([identifier, token])
}

// End of NextAuth specific schemas

model Profile {
id String @id @default(cuid())
firstName String
lastName String
major String
minor String?
graduationYear Int
graduationMonth Int
createdAt DateTime @default(now())

reviews Review[]

user User @relation(fields: [id], references: [id])
userId String @unique
}

model Company {
id String @id @default(cuid())
name String
description String?
industry Industry
location String
createdAt DateTime @default(now())
roles Role[]
}

model Role {
id String @id @default(cuid())
title String
description String

reviews Review[]

Company Company? @relation(fields: [companyId], references: [id])
companyId String?
}

model Review {
id String @id @default(cuid())
workTerm WorkTerm
workYear Int
startDate DateTime?
endDate DateTime?
hourlyPay Decimal
interviewDifficulty Int?
interviewExperience Int?
supervisorRating Int?
cultureRating Int?
overallRating Int
textReview String
workEnvironment WorkEnvironment
freeLunch Boolean
drugTest Boolean
federalHolidays Boolean
overtimeNormal Boolean
createdAt DateTime @default(now())

Role Role? @relation(fields: [roleId], references: [id])
roleId String?

Profile Profile? @relation(fields: [profileId], references: [id])
profileId String?
}

enum Industry {
TECHNOLOGY
HEALTHCARE
FINANCE
EDUCATION
MANUFACTURING
HOSPITALITY
RETAIL
TRANSPORTATION
ENERGY
MEDIA
AEROSPACE
TELECOMMUNICATIONS
BIOTECHNOLOGY
PHARMACEUTICAL
CONSTRUCTION
REALESTATE
FASHIONANDBEAUTY
ENTERTAINMENT
GOVERNMENT
NONPROFIT
FOODANDBEVERAGE
GAMING
SPORTS
MARKETING
CONSULTING
FITNESS
ECOMMERCE
ENVIRONMENTAL
ROBOTICS
MUSIC
INSURANCE
DESIGN
PUBLISHING
ARCHITECTURE
VETERINARY
}

enum WorkEnvironment {
IN_PERSON
HYBRID
REMOTE
}

enum WorkTerm {
FALL
SPRING
SUMMER
}
5 changes: 4 additions & 1 deletion src/server/api/root.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { createTRPCRouter } from "~/server/api/trpc";
import { companyRouter } from "./routers/company";

/**
* This is the primary router for your server.
*
* All routers added in /api/routers should be manually added here.
*/
export const appRouter = createTRPCRouter({});
export const appRouter = createTRPCRouter({
companyRouter,
banushi-a marked this conversation as resolved.
Show resolved Hide resolved
});

// export type definition of API
export type AppRouter = typeof appRouter;
77 changes: 77 additions & 0 deletions src/server/api/routers/company.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { z } from "zod";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { Industry } from "@prisma/client";

export const companyRouter = createTRPCRouter({
getAll: publicProcedure.query(({ ctx }) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last change: could we rename the endpoints to list (in place of getAll), getByName, create, update, and delete to keep the API minimal?

return ctx.db.company.findMany();
}),
getByName: publicProcedure
.input(
z.object({
name: z.string(),
}),
)
.query(({ ctx, input }) => {
return ctx.db.company.findFirst({
where: {
name: input.name,
},
});
}),
deleteByID: publicProcedure
.input(
z.object({
id: z.string(),
}),
)
.mutation(({ ctx, input }) => {
// TODO : should we delete all of the roles + reviews associated with a company?
banushi-a marked this conversation as resolved.
Show resolved Hide resolved
return ctx.db.company.delete({
where: {
id: input.id,
},
});
}),
postCompany: publicProcedure
banushi-a marked this conversation as resolved.
Show resolved Hide resolved
.input(
z.object({
name: z.string(),
description: z.string().optional(),
industry: z.nativeEnum(Industry),
location: z.string(),
}),
)
.mutation(({ ctx, input }) => {
return ctx.db.company.create({
data: {
name: input.name,
description: input.description,
industry: input.industry,
location: input.location,
},
});
}),
updateCompanyById: publicProcedure
.input(
z.object({
id: z.string(),
data: z.object({
name: z.string(),
description: z.string(),
banushi-a marked this conversation as resolved.
Show resolved Hide resolved
industry: z.nativeEnum(Industry),
location: z.string(),
}),
}),
)
.mutation(({ ctx, input }) => {
return ctx.db.company.update({
where: {
id: input.id,
},
data: {
...input.data,
},
});
}),
});
3 changes: 3 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export default {
fontFamily: {
sans: ["var(--font-sans)", ...fontFamily.sans],
},
colors: {
"cooper-blue": "#000088",
},
},
},
plugins: [],
Expand Down
Loading