File

src/userInteraction/user-interaction.service.ts

Index

Methods

Constructor

constructor(prismaService: PrismaService)
Parameters :
Name Type Optional
prismaService PrismaService No

Methods

Async create
create(createUserInteractionDto: CreateUserInteractionDto)
Parameters :
Name Type Optional
createUserInteractionDto CreateUserInteractionDto No
Returns : unknown
Async findByCriteria
findByCriteria(projectId?: string, userId?: string, interactionType?: InteractionType)
Parameters :
Name Type Optional
projectId string Yes
userId string Yes
interactionType InteractionType Yes
Returns : unknown
Async remove
remove(id: number)
Parameters :
Name Type Optional
id number No
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 },
    });
  }
}

results matching ""

    No results matching ""