Skip to content

Commit

Permalink
feat: user repository relations
Browse files Browse the repository at this point in the history
  • Loading branch information
supalarry committed Dec 11, 2023
1 parent 7cf813d commit 1802b25
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,53 @@ import { PrismaReadService } from "@/modules/prisma/prisma-read.service";
import { Injectable } from "@nestjs/common";
import type { User } from "@prisma/client";

type UserRelations = {
eventTypes?: boolean;
credentials?: boolean;
teams?: boolean;
bookings?: boolean;
schedules?: boolean;
selectedCalendars?: boolean;
availability?: boolean;
webhooks?: boolean;
destinationCalendar?: boolean;
metadata?: boolean;
impersonatedUsers?: boolean;
impersonatedBy?: boolean;
apiKeys?: boolean;
accounts?: boolean;
sessions?: boolean;
Feedback?: boolean;
ownedEventTypes?: boolean;
workflows?: boolean;
routingForms?: boolean;
verifiedNumbers?: boolean;
hosts?: boolean;
organization?: boolean;
accessCodes?: boolean;
platformOAuthClients?: boolean;
};

@Injectable()
export class UserRepository {
constructor(private readonly dbRead: PrismaReadService) {}

async findById(userId: number) {
async findById(userId: number, includeRelations?: UserRelations) {
const user = await this.dbRead.prisma.user.findUniqueOrThrow({
where: {
id: userId,
},
include: includeRelations,
});
return this.sanitize(user);
}

async findByEmail(email: string) {
async findByEmail(email: string, includeRelations?: UserRelations) {
const user = await this.dbRead.prisma.user.findUniqueOrThrow({
where: {
email,
},
include: includeRelations,
});
return this.sanitize(user);
}
Expand Down

0 comments on commit 1802b25

Please sign in to comment.