From e8f8bca94fe97aba279f077deb3816f7d3b6822a Mon Sep 17 00:00:00 2001 From: Pedro Gulinelli Date: Wed, 28 Jun 2023 14:39:02 -0300 Subject: [PATCH 1/3] feat: #44 - query mentorias --- src/modules/event/event.resolver.ts | 18 +++++++ src/modules/event/event.service.ts | 82 +++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/modules/event/event.resolver.ts b/src/modules/event/event.resolver.ts index 895c278..61de230 100644 --- a/src/modules/event/event.resolver.ts +++ b/src/modules/event/event.resolver.ts @@ -26,6 +26,24 @@ export class EventResolver { return this.eventService.findAll({ learnerId, mentorId }); } + @UseGuards(AuthGuard) + @Query(() => [CreateEventOutput], { name: 'findEventsPerWeek' }) + findEventsPerWeek( + @Args('learnerId', { nullable: true }) learnerId?: string, + @Args('mentorId', { nullable: true }) mentorId?: string, + ) { + return this.eventService.findEventsPerWeek({ learnerId, mentorId }); + } + + @UseGuards(AuthGuard) + @Query(() => [CreateEventOutput], { name: 'findCurrentEvents' }) + findCurrentEvents( + @Args('learnerId', { nullable: true }) learnerId?: string, + @Args('mentorId', { nullable: true }) mentorId?: string, + ) { + return this.eventService.findCurrentEvents({ learnerId, mentorId }); + } + @UseGuards(AuthGuard) @Query(() => CreateEventOutput, { name: 'findOneEvent' }) findOne(@Args('id', { type: () => String }) id: string) { diff --git a/src/modules/event/event.service.ts b/src/modules/event/event.service.ts index 492462e..6250833 100644 --- a/src/modules/event/event.service.ts +++ b/src/modules/event/event.service.ts @@ -199,6 +199,88 @@ export class EventService { }); } + async findEventsPerWeek({ + learnerId, + mentorId, + }: { + learnerId?: string; + mentorId?: string; + }) { + const options = { + ...(mentorId && { + mentorId, + }), + ...(learnerId && { + participants: { + some: { + user: { + id: learnerId, + }, + }, + }, + }), + }; + const currentDate = dayjs(); + const oneWeekAgo = currentDate.subtract(1, 'week'); + + const eventsPerWeek = await this.prisma.event.findMany({ + where: { + ...options, + ...oneWeekAgo.toDate(), + }, + include: { + participants: { + include: { + user: true, + }, + }, + }, + }); + + return eventsPerWeek; + } + + async findCurrentEvents({ + learnerId, + mentorId, + }: { + learnerId?: string; + mentorId?: string; + }) { + const options = { + ...(mentorId && { + mentorId, + }), + ...(learnerId && { + participants: { + some: { + user: { + id: learnerId, + }, + }, + }, + }), + }; + + const currentEvent = dayjs(); + + const pendingEvents = await this.prisma.event.findMany({ + where: { + ...options, + ...currentEvent.toDate(), + }, + include: { + participants: { + include: { + user: true, + }, + }, + }, + }); + + return pendingEvents; + } + async findOne(id: string) { return this.prisma.event.findUnique({ where: { From 6c528cc1f041b1dc78076f3bcff032e8c8692139 Mon Sep 17 00:00:00 2001 From: Pedro Gulinelli Date: Wed, 5 Jul 2023 16:37:41 -0300 Subject: [PATCH 2/3] feat: queryMentorias --- schema.gql | 1 + src/modules/event/event.resolver.ts | 12 ++----- src/modules/event/event.service.ts | 55 +++++++---------------------- 3 files changed, 15 insertions(+), 53 deletions(-) diff --git a/schema.gql b/schema.gql index 8cb2cc1..9979abd 100644 --- a/schema.gql +++ b/schema.gql @@ -145,6 +145,7 @@ type Query { isUserLogged: Boolean! findMentorAvailability(mentorId: String!): User! findEvents(learnerId: String, mentorId: String): [CreateEventOutput!]! + findEventsPerWeek(learnerId: String, mentorId: String, weeks: Float): [CreateEventOutput!]! findOneEvent(id: String!): CreateEventOutput! findAllSkills: [Skill!]! skill(id: Int!): Skill! diff --git a/src/modules/event/event.resolver.ts b/src/modules/event/event.resolver.ts index 61de230..f4ced8b 100644 --- a/src/modules/event/event.resolver.ts +++ b/src/modules/event/event.resolver.ts @@ -31,17 +31,9 @@ export class EventResolver { findEventsPerWeek( @Args('learnerId', { nullable: true }) learnerId?: string, @Args('mentorId', { nullable: true }) mentorId?: string, + @Args('weeks', { nullable: true }) weeks?: number, ) { - return this.eventService.findEventsPerWeek({ learnerId, mentorId }); - } - - @UseGuards(AuthGuard) - @Query(() => [CreateEventOutput], { name: 'findCurrentEvents' }) - findCurrentEvents( - @Args('learnerId', { nullable: true }) learnerId?: string, - @Args('mentorId', { nullable: true }) mentorId?: string, - ) { - return this.eventService.findCurrentEvents({ learnerId, mentorId }); + return this.eventService.findEventsPerWeek({ learnerId, mentorId, weeks }); } @UseGuards(AuthGuard) diff --git a/src/modules/event/event.service.ts b/src/modules/event/event.service.ts index 6250833..2c43570 100644 --- a/src/modules/event/event.service.ts +++ b/src/modules/event/event.service.ts @@ -14,6 +14,7 @@ import { MailService } from '@common/services/mail/mail.service'; import { eventScheduledEmailProps } from '@providers/mails'; import { formatDate, formatHour } from '@common/utils/date'; import { NotificationsService } from '@modules/notifications/notifications.service'; +import { Role } from '@common/decorators/roles.decorator'; @Injectable() export class EventService { @@ -199,12 +200,15 @@ export class EventService { }); } + @Role('ADMIN') async findEventsPerWeek({ learnerId, mentorId, + weeks, }: { learnerId?: string; mentorId?: string; + weeks?: number; }) { const options = { ...(mentorId && { @@ -219,14 +223,17 @@ export class EventService { }, }, }), + ...(weeks && { + weeks, + }), }; const currentDate = dayjs(); - const oneWeekAgo = currentDate.subtract(1, 'week'); + const subtractWeeks = currentDate.subtract(weeks, 'weeks'); const eventsPerWeek = await this.prisma.event.findMany({ where: { ...options, - ...oneWeekAgo.toDate(), + ...subtractWeeks.toDate(), }, include: { participants: { @@ -235,50 +242,12 @@ export class EventService { }, }, }, - }); - - return eventsPerWeek; - } - - async findCurrentEvents({ - learnerId, - mentorId, - }: { - learnerId?: string; - mentorId?: string; - }) { - const options = { - ...(mentorId && { - mentorId, - }), - ...(learnerId && { - participants: { - some: { - user: { - id: learnerId, - }, - }, - }, - }), - }; - - const currentEvent = dayjs(); - - const pendingEvents = await this.prisma.event.findMany({ - where: { - ...options, - ...currentEvent.toDate(), - }, - include: { - participants: { - include: { - user: true, - }, - }, + orderBy: { + startDate: 'asc', }, }); - return pendingEvents; + return eventsPerWeek; } async findOne(id: string) { From 06d68399df04534be6e2aa7bd84d6cc4284cb6c1 Mon Sep 17 00:00:00 2001 From: Pedro Gulinelli Date: Mon, 10 Jul 2023 17:11:51 -0300 Subject: [PATCH 3/3] feat: queryMentorias --- schema.gql | 49 +++++------------------------- src/modules/event/event.service.ts | 18 +++++++---- 2 files changed, 20 insertions(+), 47 deletions(-) diff --git a/schema.gql b/schema.gql index 9979abd..002fb24 100644 --- a/schema.gql +++ b/schema.gql @@ -104,24 +104,6 @@ type Skill { name: String! } -type NotificationData { - id: ID! - title: String! - description: String! - imageUrl: String - notifierId: ID - updatedAt: DateTime! - createdAt: DateTime! -} - -type Notification { - id: ID! - notificationDataId: ID! - userId: ID! - read: Boolean! - data: NotificationData! -} - type Testimony { id: ID! mentorId: String! @@ -151,10 +133,7 @@ type Query { skill(id: Int!): Skill! findNotifications(userId: String): [Notification!]! findOneNotification(id: String!): Notification - findTestimonies( - learnerId: String - mentorId: String - ): [CreateTestimonyOutput!]! + findTestimonies(learnerId: String, mentorId: String): [CreateTestimonyOutput!]! findOneTestimony(id: String!): [CreateTestimonyOutput!]! } @@ -196,9 +175,7 @@ type Mutation { resetUserPassword(userInput: ResetPasswordInput!): Boolean! sendResetPassword(email: String!): Boolean! createAvailability(createAvailabilityInput: CreateAvailabilityInput!): User! - updateAvailability( - updateAvailabilityInput: UpdateAvailabilityInput! - ): Availability! + updateAvailability(updateAvailabilityInput: UpdateAvailabilityInput!): Availability! removeAvailability(id: Int!): Availability! createEvent(createEventInput: CreateEventInput!): Event! updateEvent(updateEventInput: UpdateEventInput!): Event! @@ -206,12 +183,8 @@ type Mutation { createSkill(createSkillInput: CreateSkillInput!): Skill! updateSkill(updateSkillInput: UpdateSkillInput!): Skill! removeSkill(id: Int!): Skill! - createNotification( - createNotificationInput: CreateNotificationInput! - ): NotificationData! - updateNotification( - updateNotificationInput: UpdateNotificationInput! - ): NotificationData! + createNotification(createNotificationInput: CreateNotificationInput!): NotificationData! + updateNotification(updateNotificationInput: UpdateNotificationInput!): NotificationData! markRead(id: String!): Notification! removeNotification(id: ID!): Boolean! createTestimony(createTestimonyInput: CreateTestimonyInput!): Testimony! @@ -281,9 +254,7 @@ input SignInUserInput { rememberMe: Boolean } -""" -The `Upload` scalar type represents a file upload. -""" +"""The `Upload` scalar type represents a file upload.""" scalar Upload input ResetPasswordInput { @@ -331,16 +302,12 @@ input UpdateEventInput { } input CreateSkillInput { - """ - Example field (placeholder) - """ + """Example field (placeholder)""" exampleField: Int! } input UpdateSkillInput { - """ - Example field (placeholder) - """ + """Example field (placeholder)""" exampleField: Int id: Int! } @@ -373,4 +340,4 @@ input UpdateTestimonyInput { learnerId: String text: String id: String! -} +} \ No newline at end of file diff --git a/src/modules/event/event.service.ts b/src/modules/event/event.service.ts index 2c43570..4f2e1cb 100644 --- a/src/modules/event/event.service.ts +++ b/src/modules/event/event.service.ts @@ -223,17 +223,20 @@ export class EventService { }, }, }), - ...(weeks && { - weeks, - }), }; + const currentDate = dayjs(); - const subtractWeeks = currentDate.subtract(weeks, 'weeks'); + let subtractWeeks = currentDate; + + if (weeks) { + subtractWeeks = currentDate.subtract(weeks, 'weeks'); + subtractWeeks.toDate(); + } const eventsPerWeek = await this.prisma.event.findMany({ where: { ...options, - ...subtractWeeks.toDate(), + ...subtractWeeks, }, include: { participants: { @@ -247,7 +250,10 @@ export class EventService { }, }); - return eventsPerWeek; + return eventsPerWeek.map((events) => { + if (!weeks) this.findAll(events); + return events; + }); } async findOne(id: string) {