Fix graphql queries

This commit is contained in:
Charles Bochet
2023-05-26 00:31:43 +02:00
parent b0044ed1a2
commit 17f5cf1766
1012 changed files with 301 additions and 19768 deletions

View File

@ -4,51 +4,61 @@ import { PrismaService } from 'src/database/prisma.service';
@Injectable()
export class UserRepository {
constructor(private prisma: PrismaService) {}
constructor(private prisma: PrismaService) {}
async findMany(params: {
skip?: number;
take?: number;
cursor?: Prisma.UserWhereUniqueInput;
where?: Prisma.UserWhereInput;
orderBy?: Prisma.UserOrderByWithRelationInput;
}): Promise<User[]> {
const { skip, take, cursor, where, orderBy } = params;
return this.prisma.user.findMany({ skip, take, cursor, where, orderBy });
}
async findMany(params: {
skip?: number;
take?: number;
cursor?: Prisma.UserWhereUniqueInput;
where?: Prisma.UserWhereInput;
orderBy?: Prisma.UserOrderByWithRelationInput;
}): Promise<User[]> {
const { skip, take, cursor, where, orderBy } = params;
return this.prisma.user.findMany({ skip, take, cursor, where, orderBy });
}
async upsertUser(params: { data: Prisma.UserCreateInput, workspaceId: string }): Promise<User> {
const { data } = params;
return await this.prisma.user.upsert({
where: {
email: data.email
},
create: {
id: data.id,
displayName: data.displayName,
email: data.email,
locale: data.locale,
},
update: {
}
});
}
async findUnique(params: {
where?: Prisma.UserWhereInput;
}): Promise<User | null> {
const { where } = params;
return this.prisma.user.findFirst({ where });
}
async upsertWorkspaceMember(params: { data: Prisma.WorkspaceMemberUncheckedCreateInput }): Promise<WorkspaceMember> {
const { data } = params;
return await this.prisma.workspaceMember.upsert({
where: {
userId: data.userId
},
create: {
id: data.id,
userId: data.userId,
workspaceId: data.workspaceId,
},
update: {
}
});
}
async upsertUser(params: {
data: Prisma.UserCreateInput;
workspaceId: string;
}): Promise<User> {
const { data } = params;
return await this.prisma.user.upsert({
where: {
email: data.email,
},
create: {
id: data.id,
displayName: data.displayName,
email: data.email,
locale: data.locale,
},
update: {},
});
}
async upsertWorkspaceMember(params: {
data: Prisma.WorkspaceMemberUncheckedCreateInput;
}): Promise<WorkspaceMember> {
const { data } = params;
return await this.prisma.workspaceMember.upsert({
where: {
userId: data.userId,
},
create: {
id: data.id,
userId: data.userId,
workspaceId: data.workspaceId,
},
update: {},
});
}
}