Skip to content

Commit

Permalink
fixes #2: join adjacent roles of the same company
Browse files Browse the repository at this point in the history
  • Loading branch information
ivancea committed Oct 25, 2023
1 parent ecfa7d2 commit cca07c1
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CV/MAC.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
"name": "Corunet",
"image": {
"alt": "corunet.svg",
"link": "https://media-asgard.s3.eu-west-1.amazonaws.com/22/04/22/2e8009b8-f641-4f6e-abdf-3d119ea6ced5_corunet.svg"
"link": "https://media-asgard.s3.eu-west-1.amazonaws.com/22/04/22/22bca95a-64d7-45d2-b99a-15bda6276fe6_corunet.svg"
}
},
"roles": [
Expand Down
16 changes: 0 additions & 16 deletions CV/snapshot.html
Original file line number Diff line number Diff line change
Expand Up @@ -576,22 +576,6 @@

</div>

</div>

</div>

<div class="right-column__job">
<div class="right-column__job-organization">
<div class="right-column__job-organization-title">
<img class="right-column__job-organization-image" src="https://media-asgard.s3.eu-west-1.amazonaws.com/22/04/22/2e8009b8-f641-4f6e-abdf-3d119ea6ced5_corunet.svg" alt="corunet.svg"/>
<div class="right-column__job-organization-name">
Corunet
</div>
</div>

</div>

<div class="common__roles">
<div class="common__role">
<div class="common__role-dates">
09/2017 - 01/2018
Expand Down
49 changes: 48 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEqual, isNil } from "lodash";
import { Highlight, Job, Project, Study } from "./mac";

export function generatorFrom<T extends unknown[]>(
Expand Down Expand Up @@ -25,7 +26,11 @@ export function sortByDates(
return elements;
}

if (isArrayOfType<Job[] | Project[]>(elements, (e) => "roles" in e)) {
if (isArrayOfType<Job[]>(elements, (e) => "organization" in e && "roles" in e)) {
return sortJobs(elements);
}

if (isArrayOfType<Project[]>(elements, (e) => "roles" in e)) {
return sortByDatesInternal(
elements,
(e) => e.roles[0].startDate,
Expand Down Expand Up @@ -54,6 +59,48 @@ export function sortByDates(
});
}

function sortJobs(jobs: Job[]): Job[] {
const flattenedRoles = jobs.flatMap((job) => {
return job.roles.map((role) => {
return {
role: role,
organization: job.organization,
type: job.type,
};
});
});

const sortedRoles = sortByDatesInternal(
flattenedRoles,
(e) => e.role.startDate,
(e) => e.role.finishDate
);

const finalJobs: Job[] = [];

for (const role of sortedRoles) {
const lastJob = finalJobs[finalJobs.length - 1];

if (
isNil(lastJob) ||
!isEqual(
{ organization: lastJob.organization, type: lastJob.type },
{ organization: role.organization, type: role.type }
)
) {
finalJobs.push({
organization: role.organization,
type: role.type,
roles: [role.role],
});
} else {
lastJob.roles.push(role.role);
}
}

return finalJobs;
}

function isArrayOfType<T extends object[]>(
elements: object[],
typeGuard: (element: object) => boolean
Expand Down
7 changes: 3 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"commander": "10.0.0",
"escape-html": "1.0.3",
"jsonschema": "1.4.1",
"lodash": "4.17.21",
"marked": "4.2.12"
},
"repository": {
Expand Down

0 comments on commit cca07c1

Please sign in to comment.