-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#61 - Cria recomendação de mentor
- Loading branch information
Showing
10 changed files
with
143 additions
and
13 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
prisma/migrations/20230714020352_add_recommendation/migration.sql
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,18 @@ | ||
-- CreateTable | ||
CREATE TABLE "recommendations" ( | ||
"id" TEXT NOT NULL, | ||
"learnerId" TEXT NOT NULL, | ||
"mentorId" TEXT NOT NULL, | ||
"text" TEXT NOT NULL, | ||
"approved" BOOLEAN NOT NULL, | ||
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated_at" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "recommendations_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "recommendations" ADD CONSTRAINT "recommendations_learnerId_fkey" FOREIGN KEY ("learnerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "recommendations" ADD CONSTRAINT "recommendations_mentorId_fkey" FOREIGN KEY ("mentorId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
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
24 changes: 24 additions & 0 deletions
24
src/modules/recommendation/dto/create-recommendation.input.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,24 @@ | ||
import { Field, InputType } from '@nestjs/graphql'; | ||
import { IsUUID, IsString, IsBoolean, IsNotEmpty } from 'class-validator'; | ||
|
||
@InputType() | ||
export class CreateRecommendationInput { | ||
@IsUUID() | ||
@IsNotEmpty() | ||
@Field(() => String) | ||
mentorId: string; | ||
|
||
@IsUUID() | ||
@IsNotEmpty() | ||
@Field(() => String) | ||
learnerId: string; | ||
|
||
@IsString() | ||
@Field(() => String) | ||
text: string; | ||
|
||
@IsBoolean() | ||
@IsNotEmpty() | ||
@Field(() => Boolean) | ||
approved: boolean; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/modules/recommendation/entities/recommendation.entity.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,17 @@ | ||
import { FieldId } from '@common/decorators'; | ||
import { ObjectType, Field, Directive } from '@nestjs/graphql'; | ||
|
||
@ObjectType() | ||
@Directive('@key(fields: "id")') | ||
export class Recommendation { | ||
@FieldId() | ||
id: string; | ||
@Field(() => String) | ||
mentorId: string; | ||
@Field(() => String) | ||
learnerId: string; | ||
@Field(() => String) | ||
text: string; | ||
@Field(() => Boolean) | ||
approved: boolean; | ||
} |
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,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RecommendationResolver } from './recommendation.resolver'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
import { RecommendationService } from './recommendation.service'; | ||
|
||
@Module({ | ||
providers: [RecommendationResolver, RecommendationService, JwtService], | ||
}) | ||
export class RecommendationModule {} |
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,20 @@ | ||
import { Args, Mutation, Resolver } from '@nestjs/graphql'; | ||
import { Recommendation } from './entities/recommendation.entity'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { AuthGuard } from '@common/auth/auth.guard'; | ||
import { CreateRecommendationInput } from './dto/create-recommendation.input'; | ||
import { RecommendationService } from './recommendation.service'; | ||
|
||
@Resolver(() => Recommendation) | ||
export class RecommendationResolver { | ||
constructor(private readonly recommendationService: RecommendationService) {} | ||
|
||
@UseGuards(AuthGuard) | ||
@Mutation(() => Recommendation) | ||
createRecommendation( | ||
@Args('createRecommendationInput') | ||
createRecommendationInput: CreateRecommendationInput, | ||
) { | ||
return this.recommendationService.create(createRecommendationInput); | ||
} | ||
} |
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,12 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateRecommendationInput } from './dto/create-recommendation.input'; | ||
import { PrismaService } from '../prisma'; | ||
|
||
@Injectable() | ||
export class RecommendationService { | ||
constructor(private readonly prisma: PrismaService) {} | ||
|
||
async create(newRecommendation: CreateRecommendationInput) { | ||
return await this.prisma.recommendation.create({ data: newRecommendation }); | ||
} | ||
} |
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