Skip to content

Commit

Permalink
Merge pull request #388 from 51ngul4r1ty/issue/000386/fix-end-of-spri…
Browse files Browse the repository at this point in the history
…nt-view-issue

Fix End of Sprint View Issue
  • Loading branch information
51ngul4r1ty authored Apr 13, 2022
2 parents ff01e3a + be62c91 commit fa362c4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "atoll",
"version": "0.48.1",
"version": "0.48.3",
"author": {
"name": "Kevin Berry",
"email": "[email protected]"
Expand Down Expand Up @@ -59,7 +59,7 @@
"check:prereqs": "ts-node ./scripts/check-prereqs.ts"
},
"dependencies": {
"@atoll/shared": "0.48.1",
"@atoll/shared": "0.48.3",
"@flopflip/memory-adapter": "1.6.0",
"@flopflip/react-broadcast": "10.1.11",
"axios": "0.21.2",
Expand Down
1 change: 1 addition & 0 deletions src/server/api/handlers/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const rootHandler = function (req, res) {
const packageJsonPath = getPackageJsonPath();
const data = fs.readFileSync(packageJsonPath, { encoding: "utf8", flag: "r" });
const packageJson = JSON.parse(data);
// NOTE: X-App-Version is reported at api/v1/users/{self}/preferences endpoint.
res.set(
"X-Atoll-Info",
JSON.stringify({
Expand Down
6 changes: 5 additions & 1 deletion src/server/api/handlers/userPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Request, Response } from "express";
import * as HttpStatus from "http-status-codes";
import * as findPackageJson from "find-package-json";

// libraries
import { timeNow } from "@atoll/shared";

// interfaces/types
import type { RestApiErrorResult } from "../utils/responseBuilder";

Expand All @@ -17,7 +20,8 @@ export const userPreferencesHandler = async function (req: Request, res: Respons
const userId = req.params.userId || "";
const result = await getUserPreferences(userId, () => getLoggedInAppUserId(req));
if (result.status === HttpStatus.OK) {
res.header("x-app-version", version).json(result);
// NOTE: X-Atoll-Info also reports version info (app & library versions) at api/vi endpoint.
res.header("x-app-version", version).header("x-server-time", timeNow().toISOString()).json(result);
} else {
const errorResult = result as RestApiErrorResult;
res.status(errorResult.status).json({
Expand Down
36 changes: 27 additions & 9 deletions src/server/api/handlers/views/planViewBff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import type { Request, Response } from "express";
import * as HttpStatus from "http-status-codes";

// libraries
import { mapApiItemsToSprints } from "@atoll/shared";
import { ApiSprint, DateOnly, determineSprintStatus, mapApiItemsToSprints, SprintStatus } from "@atoll/shared";

// interfaces/types
import type { UserPreferencesItemResult } from "../fetchers/userPreferencesFetcher";
import type { SprintBacklogItemsResult } from "../fetchers/sprintBacklogItemFetcher";
import type { RestApiCollectionResult, RestApiErrorResult } from "../../utils/responseBuilder";
import { isRestApiErrorResult, RestApiCollectionResult, RestApiErrorResult } from "../../utils/responseBuilder";

// utils
import { fetchBacklogItems } from "../fetchers/backlogItemFetcher";
Expand Down Expand Up @@ -40,12 +40,29 @@ export const planViewBffGetHandler = async (req: Request, res: Response) => {
let sprintBacklogItemsResult: SprintBacklogItemsResult | RestApiErrorResult;
let sprintBacklogItemsStatus = HttpStatus.OK;
let sprintBacklogItemsMessage = "";
let expandedSprintId: string;
if (sprints.length) {
const mappedSprints = mapApiItemsToSprints(sprints);
const expandedSprints = mappedSprints.filter((item) => item.expanded);
if (expandedSprints.length) {
const firstExpandedSprint = expandedSprints[0];
sprintBacklogItemsResult = await fetchSprintBacklogItemsWithLinks(firstExpandedSprint.id);
const notStartedSprints = sprints.filter((sprint: ApiSprint) => {
const status = determineSprintStatus(
DateOnly.fromISODate(sprint.startdate),
DateOnly.fromISODate(sprint.finishdate)
);
return status === SprintStatus.NotStarted;
});
if (notStartedSprints.length) {
const firstNotStartedSprint = notStartedSprints[0];
sprintBacklogItemsResult = await fetchSprintBacklogItemsWithLinks(firstNotStartedSprint.id);
if (!isRestApiErrorResult(sprintBacklogItemsResult)) {
expandedSprintId = firstNotStartedSprint.id;
}
} else if (sprints.length > 0) {
const lastSprint = sprints[sprints.length - 1];
sprintBacklogItemsResult = await fetchSprintBacklogItemsWithLinks(lastSprint.id);
if (!isRestApiErrorResult(sprintBacklogItemsResult)) {
expandedSprintId = lastSprint.id;
}
}
if (sprintBacklogItemsResult) {
sprintBacklogItemsStatus = sprintBacklogItemsResult.status;
sprintBacklogItemsMessage = sprintBacklogItemsResult.message;
}
Expand All @@ -60,8 +77,9 @@ export const planViewBffGetHandler = async (req: Request, res: Response) => {
buildResponseWithData({
backlogItems: backlogItemsResult.data?.items,
sprints,
sprintBacklogItems: sprintBacklogItemsResult?.data?.items,
userPreferences: (userPreferencesResult as UserPreferencesItemResult).data?.item
sprintBacklogItems: sprintBacklogItemsResult?.data?.items || [],
userPreferences: (userPreferencesResult as UserPreferencesItemResult).data?.item,
expandedSprintId: expandedSprintId || null
})
);
} else {
Expand Down

0 comments on commit fa362c4

Please sign in to comment.