Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #44 - query mentorias #54

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
10 changes: 10 additions & 0 deletions src/modules/event/event.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ 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,
@Args('weeks', { nullable: true }) weeks?: number,
) {
return this.eventService.findEventsPerWeek({ learnerId, mentorId, weeks });
}

@UseGuards(AuthGuard)
@Query(() => CreateEventOutput, { name: 'findOneEvent' })
findOne(@Args('id', { type: () => String }) id: string) {
Expand Down
51 changes: 51 additions & 0 deletions src/modules/event/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -199,6 +200,56 @@ export class EventService {
});
}

@Role('ADMIN')
async findEventsPerWeek({
learnerId,
mentorId,
weeks,
}: {
learnerId?: string;
mentorId?: string;
weeks?: number;
}) {
const options = {
...(mentorId && {
mentorId,
}),
...(learnerId && {
participants: {
some: {
user: {
id: learnerId,
},
},
},
}),
...(weeks && {
weeks,
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no caso essa weeks não precisa estar aqui, você vai faz a conversão delas abaixo e só a conversão que precisa ir

};
const currentDate = dayjs();
const subtractWeeks = currentDate.subtract(weeks, 'weeks');

const eventsPerWeek = await this.prisma.event.findMany({
where: {
...options,
...subtractWeeks.toDate(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aqui precisa fazer uma validação, só subtrair as semanas se weeks existir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no caso seria um if() dentro do where mesmo né?

},
include: {
participants: {
include: {
user: true,
},
},
},
orderBy: {
startDate: 'asc',
},
});

return eventsPerWeek;
}

async findOne(id: string) {
return this.prisma.event.findUnique({
where: {
Expand Down