src/userInteraction/user-interaction.service.ts
Methods |
|
constructor(prismaService: PrismaService)
|
||||||
|
Parameters :
|
| Async create | ||||||
create(createUserInteractionDto: CreateUserInteractionDto)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async findByCriteria | ||||||||||||
findByCriteria(projectId?: string, userId?: string, interactionType?: InteractionType)
|
||||||||||||
|
Parameters :
Returns :
unknown
|
| Async remove | ||||||
remove(id: number)
|
||||||
|
Parameters :
Returns :
unknown
|
import { Injectable } from "@nestjs/common";
import { InteractionType } from "./entities/user-interaction.entity";
import { PrismaService } from "../common/prisma/prisma.service";
import { CreateUserInteractionDto } from "./dto/create-user-interaction.dto";
@Injectable()
export class UserInteractionService {
constructor(private readonly prismaService: PrismaService) {}
async create(createUserInteractionDto: CreateUserInteractionDto) {
return this.prismaService.userInteraction.create({
data: {
userId: createUserInteractionDto.userId?.toLowerCase() ?? null,
projectId: createUserInteractionDto.projectId ?? null,
interactionType: createUserInteractionDto.interactionType,
},
});
}
async findByCriteria(
projectId?: string,
userId?: string,
interactionType?: InteractionType,
) {
const where: any = {};
if (projectId !== undefined) {
where.projectId = parseInt(projectId);
}
if (userId !== undefined) {
where.userId = userId.toLowerCase();
}
if (interactionType !== undefined) {
where.interactionType = interactionType;
}
return this.prismaService.userInteraction.findMany({
where,
});
}
async remove(id: number) {
return this.prismaService.userInteraction.delete({
where: { id },
});
}
}