-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from MatheusSanchez/SFD-88-get-project-returni…
…ng-user-data Get project routes - returning user data
- Loading branch information
Showing
12 changed files
with
234 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/repositories/prisma/prisma-project-with-user-data-type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Prisma } from '@prisma/client' | ||
|
||
const userAvatarUrlAndNameData = Prisma.validator<Prisma.UserDefaultArgs>()({ | ||
select: { avatar_url: true, name: true, surname: true }, | ||
}) | ||
|
||
const projectsWithUserData = Prisma.validator<Prisma.ProjectDefaultArgs>()({ | ||
include: { user: userAvatarUrlAndNameData }, | ||
}) | ||
|
||
export type ProjectWithUserData = Prisma.ProjectGetPayload< | ||
typeof projectsWithUserData | ||
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { Prisma, Project } from '@prisma/client' | ||
import { ProjectWithUserData } from './prisma/prisma-project-with-user-data-type' | ||
|
||
export interface ProjectRepository { | ||
create(data: Prisma.ProjectUncheckedCreateInput): Promise<Project> | ||
fetchProjectsByUserId(userId: string): Promise<Project[]> | ||
fetchProjectById(projectId: string): Promise<Project | null> | ||
fetchProjectById(projectId: string): Promise<ProjectWithUserData | null> | ||
addPhotoUrl(projectId: string, photoUrl: string): Promise<Project> | ||
fetchProjectByTags(tags: string[]): Promise<Project[]> | ||
fetchProjectByTags(tags: string[]): Promise<ProjectWithUserData[]> | ||
edit(data: Prisma.ProjectUncheckedCreateInput): Promise<Project> | ||
deleteProjectByID(projectID: string): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
|
||
import { InMemoryProjectRepository } from '../../repositories/in-memory-db/inMemoryProjectRepository' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { ResourceNotFoundError } from '../errors/ResourceNotFoundError' | ||
import { EditProjectUseCase } from './editProjectUseCase' | ||
import { User } from '@prisma/client' | ||
|
||
let projectRepository: ProjectRepository | ||
let projectRepository: InMemoryProjectRepository | ||
let editProjectUseCase: EditProjectUseCase | ||
let newUser: User | ||
|
||
describe('Edit Project By Id Use Case', () => { | ||
beforeEach(() => { | ||
beforeEach(async () => { | ||
projectRepository = new InMemoryProjectRepository() | ||
editProjectUseCase = new EditProjectUseCase(projectRepository) | ||
newUser = await projectRepository.dbUser.create({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password_hash: '123456', | ||
}) | ||
}) | ||
|
||
it('should be able edit one project by ID', async () => { | ||
|
@@ -20,7 +27,7 @@ describe('Edit Project By Id Use Case', () => { | |
description: 'Best Project', | ||
tags: ['react', 'node'], | ||
link: 'https://github.com/luiseduardo3/nodets-petcanil', | ||
user_id: 'user_id', | ||
user_id: newUser.id, | ||
}) | ||
|
||
const { project: projectEdited } = await editProjectUseCase.execute({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
import { expect, describe, it, beforeEach } from 'vitest' | ||
|
||
import { InMemoryProjectRepository } from '../../repositories/in-memory-db/inMemoryProjectRepository' | ||
import { ProjectRepository } from '../../repositories/project-repository' | ||
import { ResourceNotFoundError } from '../errors/ResourceNotFoundError' | ||
import { GetProjectsByIdUseCase } from './getProjectsByIdUseCase' | ||
|
||
let projectRepository: ProjectRepository | ||
let projectRepository: InMemoryProjectRepository | ||
let getProjectByIdUseCase: GetProjectsByIdUseCase | ||
|
||
describe('Get Project By Id Use Case', () => { | ||
|
@@ -15,12 +14,18 @@ describe('Get Project By Id Use Case', () => { | |
}) | ||
|
||
it('should be able get project by ID', async () => { | ||
const newUser = await projectRepository.dbUser.create({ | ||
name: 'John', | ||
surname: 'Doe', | ||
email: '[email protected]', | ||
password_hash: '123456', | ||
}) | ||
const newProject = await projectRepository.create({ | ||
title: 'React Typescript 1', | ||
description: 'Best Project', | ||
tags: ['react', 'node'], | ||
link: 'https://github.com/luiseduardo3/nodets-petcanil', | ||
user_id: 'user_id', | ||
user_id: newUser.id, | ||
}) | ||
|
||
const { project } = await getProjectByIdUseCase.execute({ | ||
|
@@ -32,6 +37,7 @@ describe('Get Project By Id Use Case', () => { | |
title: 'React Typescript 1', | ||
id: newProject.id, | ||
tags: ['react', 'node'], | ||
user: { name: 'John', surname: 'Doe', avatar_url: null }, | ||
}), | ||
) | ||
}) | ||
|
Oops, something went wrong.