Skip to content

Commit

Permalink
Merge branch 'main' into fix/activity-duration-when-changing-role
Browse files Browse the repository at this point in the history
  • Loading branch information
Manumartin95 committed Oct 4, 2023
2 parents b7683cf + f6f92ac commit 519cbaf
Show file tree
Hide file tree
Showing 112 changed files with 1,463 additions and 563 deletions.
9 changes: 9 additions & 0 deletions src/app-routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { RequireBlockRole } from './shared/router/require-block-role'
import { RequireActivityApproval } from './shared/router/require-activity-approval'
import { LazyActivitiesPage } from './features/binnacle/features/activity/ui/activities-page.lazy'
import { useIsMobile } from './shared/hooks/use-is-mobile'
import { LazyAvailabilityPage } from './features/binnacle/features/availability/ui/availability-page.lazy'

export const AppRoutes: FC = () => {
const isMobile = useIsMobile()
Expand Down Expand Up @@ -108,6 +109,14 @@ export const AppRoutes: FC = () => {
</RequireBlockRole>
}
/>
<Route
path={rawPaths.availability}
element={
<RequireAuth>
<LazyAvailabilityPage />
</RequireAuth>
}
/>
</Routes>
</Suspense>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mock } from 'jest-mock-extended'
import { ProjectRepository } from '../domain/project-repository'
import { BlockProjectCmd } from './block-project-cmd'
import { ProjectRepository } from '../../../../shared/project/domain/project-repository'

describe('BlockProjectCmd', () => {
it('should block a project', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Command, UseCaseKey } from '@archimedes/arch'
import { ADMINISTRATION_PROJECT_REPOSITORY } from '../../../../../shared/di/container-tokens'
import { PROJECT_REPOSITORY } from '../../../../../shared/di/container-tokens'
import { Id } from '../../../../../shared/types/id'
import { inject, singleton } from 'tsyringe'
import type { ProjectRepository } from '../domain/project-repository'
import type { ProjectRepository } from '../../../../shared/project/domain/project-repository'

@UseCaseKey('BlockProjectCmd')
@singleton()
export class BlockProjectCmd extends Command<{ projectId: Id; date: Date }> {
constructor(
@inject(ADMINISTRATION_PROJECT_REPOSITORY) private projectRepository: ProjectRepository
) {
constructor(@inject(PROJECT_REPOSITORY) private projectRepository: ProjectRepository) {
super()
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { GetUsersListQry } from '../../../../shared/user/application/get-users-list-qry'
import { mock } from 'jest-mock-extended'
import { ProjectRepository } from '../domain/project-repository'
import { GetProjectsWithBlockerUserName } from './get-projects-with-blocker-user-name'
import { ProjectsWithUserName } from '../domain/services/projects-with-user-name'
import { GetProjectsListQry } from './get-projects-list-qry'
import { ProjectMother } from '../domain/tests/project-mother'
import { GetProjectsQry } from '../../../../shared/project/application/binnacle/get-projects-qry'
import { ProjectMother } from '../../../../../test-utils/mothers/project-mother'

describe('GetProjectsListQry', () => {
describe('GetProjectsWithBlockerUserName', () => {
it('should get the project list', async () => {
const { getProjectsListQry, projectRepository, getUsersListQry } = setup()
const organizationWithStatus = {
organizationId: 1,
open: true
}

projectRepository.getProjects.mockResolvedValue(
projectRepository.execute.mockResolvedValue(
ProjectMother.projectsFilteredByOrganizationDateIso()
)

await getProjectsListQry.internalExecute(organizationWithStatus)

expect(projectRepository.getProjects).toBeCalledWith(organizationWithStatus)
expect(projectRepository.execute).toBeCalledWith(organizationWithStatus)
expect(getUsersListQry.execute).toHaveBeenCalledWith({ ids: [2, 1] })
})

Expand All @@ -30,29 +30,29 @@ describe('GetProjectsListQry', () => {
open: true
}

projectRepository.getProjects.mockResolvedValue([
projectRepository.execute.mockResolvedValue([
ProjectMother.projectsFilteredByOrganizationDateIso()[2]
])

await getProjectsListQry.internalExecute(organizationWithStatus)

expect(projectRepository.getProjects).toBeCalledWith(organizationWithStatus)
expect(projectRepository.execute).toBeCalledWith(organizationWithStatus)
expect(getUsersListQry.execute).not.toHaveBeenCalled()
})
})

function setup() {
const projectRepository = mock<ProjectRepository>()
const getProjectQry = mock<GetProjectsQry>()
const getUsersListQry = mock<GetUsersListQry>()
const projectsWithUserName = mock<ProjectsWithUserName>()

return {
getProjectsListQry: new GetProjectsListQry(
projectRepository,
getProjectsListQry: new GetProjectsWithBlockerUserName(
getProjectQry,
getUsersListQry,
projectsWithUserName
),
projectRepository,
projectRepository: getProjectQry,
getUsersListQry,
projectsWithUserName
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { InvalidateCache, Query, UseCaseKey } from '@archimedes/arch'
import { GetUsersListQry } from '../../../../shared/user/application/get-users-list-qry'
import { singleton } from 'tsyringe'
import { Id } from '../../../../../shared/types/id'
import { Project } from '../../../../shared/project/domain/project'
import { ProjectOrganizationFilters } from '../../../../shared/project/domain/project-organization-filters'
import { ProjectsWithUserName } from '../domain/services/projects-with-user-name'
import { GetProjectsQry } from '../../../../shared/project/application/binnacle/get-projects-qry'

@UseCaseKey('GetProjectsWithBlockerUserName')
@InvalidateCache
@singleton()
export class GetProjectsWithBlockerUserName extends Query<Project[], ProjectOrganizationFilters> {
constructor(
private getProjectsQry: GetProjectsQry,
private getUsersListQry: GetUsersListQry,
private projectsWithUserName: ProjectsWithUserName
) {
super()
}

async internalExecute(organizationStatus?: ProjectOrganizationFilters): Promise<Project[]> {
if (organizationStatus) {
const projects = await this.getProjectsQry.execute(organizationStatus)

const blockerUserIds = projects
.map((project) => project.blockedByUser)
.filter((id) => id !== null) as Id[]

if (blockerUserIds.length > 0) {
const uniqueBlockerUserIds = Array.from(new Set(blockerUserIds))
const usersList = await this.getUsersListQry.execute({
ids: uniqueBlockerUserIds
})
return this.projectsWithUserName.addProjectBlockerUserName(projects, usersList)
}
return projects
}
return []
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mock } from 'jest-mock-extended'
import { ProjectRepository } from '../domain/project-repository'
import { UnblockProjectCmd } from './unblock-project-cmd'
import { ProjectRepository } from '../../../../shared/project/domain/project-repository'

describe('UnblockProjectCmd', () => {
it('should unblock a project', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Command, Id, UseCaseKey } from '@archimedes/arch'
import { ADMINISTRATION_PROJECT_REPOSITORY } from '../../../../../shared/di/container-tokens'
import { PROJECT_REPOSITORY } from '../../../../../shared/di/container-tokens'
import { inject, singleton } from 'tsyringe'
import type { ProjectRepository } from '../domain/project-repository'
import type { ProjectRepository } from '../../../../shared/project/domain/project-repository'

@UseCaseKey('UnblockProjectCmd')
@singleton()
export class UnblockProjectCmd extends Command<Id> {
constructor(
@inject(ADMINISTRATION_PROJECT_REPOSITORY) private projectRepository: ProjectRepository
) {
constructor(@inject(PROJECT_REPOSITORY) private projectRepository: ProjectRepository) {
super()
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { singleton } from 'tsyringe'
import { UserInfo } from '../../../../../shared/user/domain/user-info'
import { Project } from '../project'
import { Project } from '../../../../../shared/project/domain/project'

@singleton()
export class ProjectsWithUserName {
addUserNameToProjects(projectsWithoutUserName: Project[], usersList: UserInfo[]): Project[] {
addProjectBlockerUserName(projectsWithoutUserName: Project[], usersList: UserInfo[]): Project[] {
return projectsWithoutUserName.map((projectWithoutUserName) => {
const { blockedByUser, ...projectDetails } = projectWithoutUserName

Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 519cbaf

Please sign in to comment.