Skip to content

Commit

Permalink
feat(rr): services + routes (#519)
Browse files Browse the repository at this point in the history
* feat(services): add initial services for rr

* feat(types): add github types

* feat(reviewrequestservice): add features

* chore(review): wip for review routes

* feat(types): add new types

* feat(reviewrequestservice): add impl for computing sha mappings

* feat(usersservice): add nwe method to user service to retrieve site admins

* feat(review): add route for creating review request

* refactor(collaboratorsservice): refactor method api for clarity

* feat(types): add more types

* refactor(collaborators): fix typings and add more steuff to return

* chore(routes): update authenticated routes

* chore(review): refactor to use collaborators service

* refactor(reviewrequestservice): update methods

* chore(server): add init code

* refactor(reviewmeta): updat eto use belongs to

* feat(types): add more types

* feat(requestnotfounderror): add new error type

* feat(review): add methods for listing review requests and retrieval of rr

* refactor(types/dto): update review types

* refactor(rrservice): update enum type

* feat(rrservice): add new method to merge rr

* feat(review): add new route to merge rr

* fix(collaborators): remove erroneous destructuring

* fix(routes/review): add siteId prop

* chore(review dto): add status

* chore(requestrequestservice): remove old comment

* fix(reviewrequestservice): changed some stuff to be optional

* refactor(rr service): split retrieving db/github view into 2 methods

* feat(rr service): add methods to close/approve rr

* refactor(rr service): refactor merge rr method

* chore(collaboratorsservice): remove extra typecasts

* feat(rr): add new endpoint to update rr

* chore(types): minor cleanup

* feat(rr routes): add new routes for close and approve pr

* chore(review): update to userwithsitesesiontoken

* refactor(reviewrequestservice): migrate api calls into own file

* refactor(authenticated): shift review router dpes to init function

* fix(index): fixed faulty init

* refactor(reviewrequestservice): add site to reviewreq object

* fix(review.ts): add explicit bearer token to api call

* refactor(rrservice): refactor to retrieve user from db

* chore(settingsservice): remove extra console log

* chore(github): remove extra `patch` property

* chore(review): add logging

* fix(server): update imports from rebase

* Chore: Update src/routes/v2/authenticated/review.ts

Co-authored-by: Hsu Zhong Jun <[email protected]>

* Chore: Update src/routes/v2/authenticated/review.ts

Co-authored-by: Hsu Zhong Jun <[email protected]>

* feat(rr status): add rr status enum

* chore(rr): update db model

* refactor(rrservice): updat to use enum

* chore(rrservice): fix commennt

* chore(review): update error codes

* chore(usersservice): rename hasAccess to getSiteMember

* chore(usersservice): update method name

* feat(rr): allow updating of admins (#539)

* chore(server): add init code

* chore(dto): removed trailing space on folder name

* refactor(reviewrequestservice): update to remove title/desc from update api

* chore(collaborators): update import

* chore(routes/review): updaterr api

Co-authored-by: Hsu Zhong Jun <[email protected]>
  • Loading branch information
2 people authored and alexanderleegs committed Mar 16, 2023
1 parent ec885d0 commit b93e81f
Show file tree
Hide file tree
Showing 22 changed files with 1,415 additions and 45 deletions.
7 changes: 7 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ export enum CollaboratorRoles {
Contributor = "CONTRIBUTOR",
}

export enum ReviewRequestStatus {
Approved = "APPROVED",
Open = "OPEN",
Merged = "MERGED",
Closed = "CLOSED",
}

export const E2E_ISOMER_ID = "-1"
export const E2E_TEST_EMAIL = "test@e2e"
export const E2E_TEST_CONTACT = "12345678"
Expand Down
5 changes: 4 additions & 1 deletion src/database/models/ReviewMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Model,
Table,
ForeignKey,
BelongsTo,
} from "sequelize-typescript"

import { ReviewRequest } from "./ReviewRequest"
Expand All @@ -24,9 +25,11 @@ export class ReviewMeta extends Model {
reviewerId!: number

@ForeignKey(() => ReviewRequest)
@Column
reviewId!: number

@BelongsTo(() => ReviewRequest)
reviewRequest!: ReviewRequest

@Column({
allowNull: false,
type: DataType.BIGINT,
Expand Down
5 changes: 3 additions & 2 deletions src/database/models/ReviewRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {

import { Site } from "@database/models/Site"
import { User } from "@database/models/User"
import { ReviewRequestStatus } from "@root/constants"

import { Reviewer } from "./Reviewers"
import { ReviewMeta } from "./ReviewMeta"
Expand Down Expand Up @@ -54,9 +55,9 @@ export class ReviewRequest extends Model {
@Column({
allowNull: false,
defaultValue: "OPEN",
type: DataType.ENUM("OPEN", "APPROVED", "MERGED", "CLOSED"),
type: DataType.ENUM(...Object.values(ReviewRequestStatus)),
})
reviewStatus!: "OPEN" | "APPROVED" | "MERGED" | "CLOSED"
reviewStatus!: ReviewRequestStatus

@BelongsToMany(() => User, {
onUpdate: "CASCADE",
Expand Down
10 changes: 1 addition & 9 deletions src/database/models/Reviewers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
Column,
CreatedAt,
DataType,
ForeignKey,
Model,
Table,
UpdatedAt,
} from "sequelize-typescript"
import { Column, ForeignKey, Model, Table } from "sequelize-typescript"

import { User } from "@database/models/User"

Expand Down
10 changes: 10 additions & 0 deletions src/errors/RequestNotFoundError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NotFoundError } from "./NotFoundError"

export default class RequestNotFoundError extends NotFoundError {
constructor(message = "The specified review request could not be found!") {
super()
Error.captureStackTrace(this, this.constructor)
this.name = this.constructor.name
this.message = message
}
}
12 changes: 9 additions & 3 deletions src/routes/v2/authenticated/collaborators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import UserWithSiteSessionData from "@classes/UserWithSiteSessionData"
import { BaseIsomerError } from "@root/errors/BaseError"
import { attachSiteHandler } from "@root/middleware"
import { RequestHandler } from "@root/types"
import { UserDto } from "@root/types/dto/review"
import CollaboratorsService from "@services/identity/CollaboratorsService"

interface CollaboratorsRouterProps {
Expand Down Expand Up @@ -71,18 +72,23 @@ export class CollaboratorsRouter {
}

listCollaborators: RequestHandler<
{ siteName: string },
{ collaborators: UserDto[] },
never,
unknown,
never,
{ siteName: string },
{ userWithSiteSessionData: UserWithSiteSessionData }
> = async (req, res) => {
const { siteName } = req.params
const { userWithSiteSessionData } = res.locals
const collaborators = await this.collaboratorsService.list(
const rawCollaborators = await this.collaboratorsService.list(
siteName,
userWithSiteSessionData.isomerUserId
)
const collaborators = rawCollaborators.map((collaborator) => ({
...collaborator.toJSON(),
email: collaborator.email || "",
role: collaborator.SiteMember.role,
}))

return res.status(200).json({ collaborators })
}
Expand Down
11 changes: 10 additions & 1 deletion src/routes/v2/authenticated/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { attachSiteHandler } from "@root/middleware"

const express = require("express")

const {
Expand All @@ -17,6 +19,7 @@ const getAuthenticatedSubrouter = ({
isomerAdminsService,
collaboratorsService,
authorizationMiddleware,
reviewRouter,
}) => {
const netlifyTomlService = new NetlifyTomlService()

Expand All @@ -42,7 +45,13 @@ const getAuthenticatedSubrouter = ({
"/sites/:siteName/collaborators",
collaboratorsRouter.getRouter()
)
authenticatedSubrouter.use("/sites", sitesV2Router.getRouter())
const baseSitesV2Router = sitesV2Router.getRouter()
const sitesRouterWithReviewRequest = baseSitesV2Router.use(
"/:siteName/review",
attachSiteHandler,
reviewRouter.getRouter()
)
authenticatedSubrouter.use("/sites", sitesRouterWithReviewRequest)
authenticatedSubrouter.use("/user", usersRouter.getRouter())
authenticatedSubrouter.use("/netlify-toml", netlifyTomlV2Router.getRouter())

Expand Down
Loading

0 comments on commit b93e81f

Please sign in to comment.