Skip to content

Commit

Permalink
Merge pull request #65 from GustavoCesarSantos/feature/#61
Browse files Browse the repository at this point in the history
Feature/#61 - Cria recomendação de mentor
  • Loading branch information
oliveirabalsa authored Jul 20, 2023
2 parents 021b88d + e3698ac commit 3510480
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 13 deletions.
18 changes: 18 additions & 0 deletions prisma/migrations/20230714020352_add_recommendation/migration.sql
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;
37 changes: 25 additions & 12 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ model User {
availability Json?
events EventsOnUsers[]
temporaryCodes TemporaryCode[]
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Event Event? @relation(fields: [eventId], references: [id])
eventId String?
notificationsData NotificationData[]
notifications Notification[]
writtenTestimonies Testimony[] @relation("WrittenTestimonies")
testimonies Testimony[] @relation("Testimonies")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
Event Event? @relation(fields: [eventId], references: [id])
eventId String?
notificationsData NotificationData[]
notifications Notification[]
writtenTestimonies Testimony[] @relation("WrittenTestimonies")
testimonies Testimony[] @relation("Testimonies")
writtenRecommendations Recommendation[] @relation("WrittenRecommendations")
recommendations Recommendation[] @relation("Recommendations")
@@map("users")
}

Expand Down Expand Up @@ -109,7 +109,6 @@ model Notification {
notificationDataId String @map("notification_data_id")
userId String @map("user_id")
read Boolean @default(false)
user User @relation(fields: [userId], references: [id])
data NotificationData? @relation(fields: [notificationDataId], references: [id], onDelete: Cascade)
Expand Down Expand Up @@ -143,3 +142,17 @@ model Testimony {
@@map("testimonies")
}

model Recommendation {
id String @id @default(uuid())
learnerId String
mentorId String
text String
approved Boolean
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
learner User @relation("WrittenRecommendations", fields: [learnerId], references: [id])
mentor User @relation("Recommendations", fields: [mentorId], references: [id])
@@map("recommendations")
}
16 changes: 16 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ type CreateTestimonyOutput {
text: String!
}

type Recommendation {
id: ID!
mentorId: String!
learnerId: String!
text: String!
approved: Boolean!
}

type Query {
sayHello: String!
findMentors(findMentorsInput: FindMentorInput!): [User!]!
Expand Down Expand Up @@ -189,6 +197,7 @@ type Mutation {
createTestimony(createTestimonyInput: CreateTestimonyInput!): Testimony!
updateTestimony(UpdateTestimonyInput: UpdateTestimonyInput!): Testimony!
deleteTestimony(id: Int!): Testimony!
createRecommendation(createRecommendationInput: CreateRecommendationInput!): Recommendation!
}

input CreateUserInput {
Expand Down Expand Up @@ -339,4 +348,11 @@ input UpdateTestimonyInput {
learnerId: String
text: String
id: String!
}

input CreateRecommendationInput {
mentorId: String!
learnerId: String!
text: String!
approved: Boolean!
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import GraphQLUpload = require('graphql-upload/GraphQLUpload.js');
import { TestimonyModule } from './modules/testimony/testimony.module';
import { APP_GUARD } from '@nestjs/core';
import { GqlThrottlerGuard } from '@common/throttler/throttler.guard';
import { RecommendationModule } from './modules/recommendation/recommendation.module';

@Module({
imports: [
Expand Down Expand Up @@ -54,6 +55,7 @@ import { GqlThrottlerGuard } from '@common/throttler/throttler.guard';
SkillModule,
NotificationsModule,
TestimonyModule,
RecommendationModule,
],
controllers: [AppController, AuthenticationController, StaticFilesController],
providers: [
Expand Down
24 changes: 24 additions & 0 deletions src/modules/recommendation/dto/create-recommendation.input.ts
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 src/modules/recommendation/entities/recommendation.entity.ts
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;
}
9 changes: 9 additions & 0 deletions src/modules/recommendation/recommendation.module.ts
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 {}
20 changes: 20 additions & 0 deletions src/modules/recommendation/recommendation.resolver.ts
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);
}
}
12 changes: 12 additions & 0 deletions src/modules/recommendation/recommendation.service.ts
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 });
}
}
1 change: 0 additions & 1 deletion src/modules/testimony/entities/testimony.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FieldId } from '@common/decorators';
//import { User } from '@modules/user/entities/user.entity';
import { ObjectType, Field, Directive } from '@nestjs/graphql';

@ObjectType()
Expand Down

0 comments on commit 3510480

Please sign in to comment.