Skip to content

Commit 27d2714

Browse files
fix: get projects (#24)
* fix: improve error handling * fix: get project list * chore: bump to 1.0.5
1 parent 9e7be46 commit 27d2714

File tree

7 files changed

+38
-12
lines changed

7 files changed

+38
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "factorial-cli",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"type": "module",
55
"description": "Fill your factorial shifts with ease",
66
"main": "dist/src/infrastructure/cli/main.js",

src/infrastructure/cli/main.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createApp } from "./createApp.js";
88
import { DayRange } from "../../domain/models/DayRange.js";
99
import { MomentOfTheDay } from "../../domain/models/MomentOfTheDay.js";
1010
import { Minute } from "../../domain/models/Minute.js";
11+
import { HttpClientError } from "../http-client/HttpClientFetch.js";
1112

1213
const now = new Date();
1314

@@ -89,4 +90,18 @@ yargs(hideBin(process.argv))
8990
},
9091
)
9192
.demandCommand(1)
93+
.fail((msg, err) => {
94+
if (err) {
95+
if (err instanceof HttpClientError) {
96+
const data = err.response.data;
97+
console.error(JSON.stringify(data, null, 2));
98+
process.exit(1);
99+
}
100+
101+
throw err;
102+
}
103+
console.error(msg);
104+
console.error(err);
105+
process.exit(1);
106+
})
92107
.parse();

src/infrastructure/factorial-client/FactorialClient.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,26 @@ export class FactorialClient {
8686
}
8787

8888
async getProjects(employeeId: number) {
89-
const query = `query GetProjectsAssignedToProjectWorkers($employeeIds: [Int!]!, $onlyActiveProjects: Boolean!, $assigned: Boolean!) {
89+
const query = `query GetProjectsAssignedToProjectWorkers($assigned: Boolean!, $employeeIds: [Int!]!, $includeSubprojects: Boolean = false, $onlyActiveProjects: Boolean!) {
9090
projectManagement {
9191
projectWorkers(
92+
assigned: $assigned
9293
employeeIds: $employeeIds
9394
projectActive: $onlyActiveProjects
94-
assigned: $assigned
9595
) {
9696
id
9797
assigned
98-
project {
98+
employee {
99+
id
100+
}
101+
imputableProject {
99102
id
100103
name
101104
status
105+
subprojects @include(if: $includeSubprojects) {
106+
id
107+
name
108+
}
102109
}
103110
}
104111
}
@@ -107,9 +114,10 @@ export class FactorialClient {
107114
const response = await this.client.post("/graphql", {
108115
operationName: "GetProjectsAssignedToProjectWorkersQuery",
109116
variables: {
117+
assigned: true,
110118
employeeIds: [employeeId],
119+
includeSubprojects: true,
111120
onlyActiveProjects: true,
112-
assigned: true,
113121
},
114122
query,
115123
});

src/infrastructure/factorial-client/schema/gql/ProjectWorker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { Project } from "./Project.js";
44
export const ProjectWorker = z.object({
55
id: z.number(),
66
assigned: z.boolean(),
7-
project: Project,
7+
imputableProject: Project,
88
});

src/infrastructure/http-client/HttpClientFetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type PrivateHttpClientOptions = {
1010
headers: Record<string, string>;
1111
};
1212

13-
class HttpClientError<T> extends Error {
13+
export class HttpClientError<T> extends Error {
1414
constructor(public response: HttpResponse<T>) {
1515
super(`Request failed with status code ${response.status}`);
1616
}

src/infrastructure/repositories/ProjectRepositoryFactorial.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export class ProjectRepositoryFactorial implements ProjectRepository {
1313
);
1414

1515
return projects.map(
16-
(project) => new Project(new ProjectId(project.id), project.project.name),
16+
(project) =>
17+
new Project(new ProjectId(project.id), project.imputableProject.name),
1718
);
1819
}
1920
}

test/fixtures/projects.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
{
66
"id": 193161,
77
"assigned": true,
8-
"project": {
8+
"imputableProject": {
99
"id": 60154,
1010
"name": "Apple",
11-
"status": "active"
11+
"status": "active",
12+
"subprojects": []
1213
}
1314
},
1415
{
1516
"id": 691157,
1617
"assigned": true,
17-
"project": {
18+
"imputableProject": {
1819
"id": 11566,
1920
"name": "Microsoft",
20-
"status": "active"
21+
"status": "active",
22+
"subprojects": []
2123
}
2224
}
2325
]

0 commit comments

Comments
 (0)