Skip to content

Commit

Permalink
chore(types): update types and add default return
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed May 24, 2023
1 parent a12ca71 commit ea8051b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/routes/v2/authenticated/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
ReviewRequestDto,
BlobDiffDto,
EditedItemDto,
BaseEditedItemDto,
} from "@root/types/dto/review"
import ReviewRequestService from "@services/review/ReviewRequestService"
// eslint-disable-next-line import/prefer-default-export
Expand Down Expand Up @@ -88,7 +87,7 @@ export class ReviewsRouter {

compareDiff: RequestHandler<
{ siteName: string },
{ items: (EditedItemDto | BaseEditedItemDto)[] } | ResponseErrorBody,
{ items: EditedItemDto[] } | ResponseErrorBody,
unknown,
unknown,
{ userWithSiteSessionData: UserWithSiteSessionData }
Expand Down
19 changes: 16 additions & 3 deletions src/services/review/ReviewRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ import * as ReviewApi from "@services/db/review"
import { PageService } from "../fileServices/MdPageServices/PageService"
import { ConfigService } from "../fileServices/YmlFileServices/ConfigService"

const injectDefaultEditMeta = ({
path,
name,
}: BaseEditedItemDto): WithEditMeta<EditedPageDto> => ({
lastEditedBy: "Unknown",
lastEditedTime: 0,
type: "page",
cmsFileUrl: "",
stagingUrl: "",
path,
name,
})

/**
* NOTE: This class does not belong as a subset of GitHub service.
* This is because GitHub service exists to operate on _files_
Expand Down Expand Up @@ -107,7 +120,7 @@ export default class ReviewRequestService {
compareDiff = (
userWithSiteSessionData: UserWithSiteSessionData,
stagingLink: StagingPermalink
) =>
): ResultAsync<WithEditMeta<EditedItemDto>[], NetworkError | DatabaseError> =>
ResultAsync.fromPromise(
this.apiService.getCommitDiff(userWithSiteSessionData.siteName),
// TODO: Write a handler for github errors to our own internal errors
Expand All @@ -129,8 +142,8 @@ export default class ReviewRequestService {
).map((res) =>
res
// NOTE: Need to type-hint so that we can recover
.map<BaseEditedItemDto | WithEditMeta<EditedItemDto>>(_.identity)
.orElse((baseItem) => okAsync(baseItem))
.map<WithEditMeta<EditedItemDto>>(_.identity)
.orElse((baseItem) => okAsync(injectDefaultEditMeta(baseItem)))
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/types/dto/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface ReviewRequestDto {
reviewers: string[]
reviewRequestedTime: number
status: ReviewRequestStatus
changedItems: (WithEditMeta<EditedItemDto> | BaseEditedItemDto)[]
changedItems: WithEditMeta<EditedItemDto>[]
}

export interface UpdateReviewRequestDto {
Expand Down

0 comments on commit ea8051b

Please sign in to comment.