Skip to content

Commit

Permalink
Merge pull request #332 from WizelineLabs/profiles_is_billable
Browse files Browse the repository at this point in the history
Add new columns to perfile table #305
  • Loading branch information
jackbravo authored Jun 20, 2024
2 parents e717716 + 9dab126 commit 38643d3
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/kysely.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export interface Profiles {
firstName: string;
githubUser: string | null;
id: string;
isBillable: Generated<boolean>;
jobLevelTier: string | null;
jobLevelTitle: string | null;
jobTitleId: string | null;
Expand Down
2 changes: 2 additions & 0 deletions app/lake.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function findProfileData(email: string) {
const query = `SELECT contact__wizeos_profile_id, contact__employee_number, contact__email,
contact__first_name, contact__preferred_name, contact__last_name,
contact__photo__url,
contact__is_billable,
contact__location, contact__country,
contact__status, contact__department, contact__business_unit,
contact__employee_status,
Expand Down Expand Up @@ -41,6 +42,7 @@ export async function getActiveProfiles() {
const query = `SELECT contact__wizeos_profile_id, contact__employee_number, contact__email,
contact__first_name, contact__preferred_name, contact__last_name,
contact__photo__url,
contact__is_billable,
contact__location, contact__country,
contact__status, contact__department, contact__business_unit,
contact__employee_status,
Expand Down
39 changes: 39 additions & 0 deletions app/models/profile.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export async function updateProfile(
jobLevelTitle: data.jobLevelTitle,
department: data.department,
businessUnit: data.businessUnit,
isBillable: data.isBillable,
location: data.location,
country: data.country,
employeeStatus: data.employeeStatus,
Expand Down Expand Up @@ -277,6 +278,7 @@ interface SearchProfilesFullInput {
benchStatus?: string[];
employeeStatus?: string[];
skill?: string[];
isBillable?: boolean;
itemsPerPage: number;
}

Expand All @@ -294,6 +296,7 @@ export async function searchProfilesFull({
benchStatus = [],
employeeStatus = [],
skill = [],
isBillable,
itemsPerPage = 50,
}: SearchProfilesFullInput) {
if (page < 1) page = 1;
Expand All @@ -304,6 +307,7 @@ export async function searchProfilesFull({
};

if (department.length > 0) {
console.log("Hello world! "+department);
where = {
...where,
department: { in: department },
Expand Down Expand Up @@ -348,6 +352,14 @@ export async function searchProfilesFull({
};
}

if (isBillable != undefined) {
where = {
...where,
isBillable: isBillable,

};
}

// Get ids
const profileIds = await prisma.profiles.findMany({
select: {
Expand All @@ -356,6 +368,8 @@ export async function searchProfilesFull({
where,
});



const ids = profileIds.map((id) => id.id);
const count = ids.length;

Expand All @@ -377,6 +391,7 @@ export async function searchProfilesFull({
preferredName: true,
benchStatus: true,
businessUnit: true,
isBillable: true,
employeeStatus: true,
githubUser: true,
projectMembers: {
Expand Down Expand Up @@ -502,6 +517,20 @@ export async function searchProfilesFull({
}
});

const isBillables = await prisma.profiles.groupBy({
by : ["isBillable"],
where:{
id: {
in: ids,
},
},
orderBy: {
isBillable: "asc",
},
_count: {
isBillable: true
},
});
return {
profiles,
count,
Expand All @@ -510,6 +539,7 @@ export async function searchProfilesFull({
employeeStatuses: convertCountResult(employeeStatuses, "employeeStatus"),
benchStatuses: convertCountResult(benchStatuses, "benchStatus"),
skills,
isBillables: convertBooleanToString(isBillables),
};
}

Expand All @@ -522,6 +552,15 @@ const convertCountResult = (countResult: any[], countField: string) => {
});
};

const convertBooleanToString = (countResult : any[]) => {
return countResult.map(item => ({
name: item.isBillable.toString(),
count: item._count.isBillable
}));
};



export async function searchProfiles(
searchTerm: string,
project: string | null = null,
Expand Down
4 changes: 3 additions & 1 deletion app/profileMigration.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import type { PrismaClient, Prisma } from "@prisma/client";
async function getMappedProfiles(): Promise<Prisma.ProfilesCreateInput[]> {
const activeProfiles = await getActiveProfiles();
const mappedProfiles = activeProfiles.map((lakeProfile) => {
const isBillable = lakeProfile.contact__is_billable === "Billable";
return {
id: String(lakeProfile.contact__employee_number),
email: lakeProfile.contact__email,
firstName: lakeProfile.contact__first_name,
preferredName:
lakeProfile.contact__preferred_name || lakeProfile.contact__first_name,
lakeProfile.contact__preferred_name || lakeProfile.contact__first_name,
lastName: lakeProfile.contact__last_name,
department: lakeProfile.contact__department,
jobLevelTier: lakeProfile.contact__wizeos__level,
Expand All @@ -21,6 +22,7 @@ async function getMappedProfiles(): Promise<Prisma.ProfilesCreateInput[]> {
employeeStatus: lakeProfile.contact__employee_status,
benchStatus: lakeProfile.contact__status,
businessUnit: lakeProfile.contact__business_unit,
isBillable: isBillable,
};
});
return mappedProfiles;
Expand Down
18 changes: 17 additions & 1 deletion app/routes/profiles._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const FILTERS = [
"businessUnit",
"benchStatus",
"skill",
"isBillable",
];

interface LoaderData {
Expand All @@ -109,7 +110,10 @@ export const loader: LoaderFunction = async ({ request }) => {
const benchStatus = url.searchParams.getAll("benchStatus");
const employeeStatus = url.searchParams.getAll("employeeStatus");
const skill = url.searchParams.getAll("skill");


const isBillable = url.searchParams.get("isBillable") === null ?
undefined :
url.searchParams.get("isBillable") === "true";
const data = await searchProfilesFull({
searchTerm,
page,
Expand All @@ -118,6 +122,7 @@ export const loader: LoaderFunction = async ({ request }) => {
benchStatus,
employeeStatus,
skill,
isBillable,
itemsPerPage: ITEMS_PER_PAGE,
});

Expand Down Expand Up @@ -147,6 +152,7 @@ const Profiles = () => {
benchStatuses,
employeeStatuses,
skills,
isBillables,
},
} = useLoaderData() as unknown as LoaderData;
const theme = useTheme();
Expand Down Expand Up @@ -267,6 +273,13 @@ const Profiles = () => {
items={benchStatuses}
/>
) : null}
{isBillables.length > 0 ?(
<FilterAccordion
title="Is Billable"
filter="isBillable"
items={isBillables}
/>
) : null}
<FilterAccordion title="Skill" filter="skill" items={skills} />
</Paper>
</Grid>
Expand Down Expand Up @@ -365,6 +378,9 @@ const Profiles = () => {
<Typography sx={{ fontWeight: "bold" }}>
{item.employeeStatus}
</Typography>
<Typography sx={{ fontWeight: "bold" }}>
{item.isBillable}
</Typography>
{item.projectMembers.length > 0 ? (
<>
{item.projectMembers.map((projectMember, index) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Profiles" ADD COLUMN "isBillable" BOOLEAN NOT NULL DEFAULT true;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ model Profiles {
jobLevelTitle String?
department String?
businessUnit String?
isBillable Boolean @default(true)
// - null
// - Horizontal
// - Innovation
Expand Down
12 changes: 12 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ async function seed() {
department: "Engineering",
},
});
await db.profiles.upsert({
where: { email: "ramiro.cardona@in.wizeline.com" },
update: {},
create: {
email: "ramiro.cardona@in.wizeline.com",
firstName: "Ramiro",
preferredName: "Ramiro",
lastName: "Cardona",
department: "Engineering",
isBillable: false,
},
});
await db.profiles.upsert({
where: { email: "fernanda.vargas@wizeline.com" },
update: {},
Expand Down

0 comments on commit 38643d3

Please sign in to comment.