본문 바로가기
prisma

프리즈마 업데이트 시간 자동 업데이트 하기

by momomoo 2024. 6. 19.

DateTime @updatedAt

이거 넣으면 자동 수정된다

 

 

 

그래도 안된다면

export class UsersRepository {
  constructor(prisma) {
    this.prisma = prisma;
  }

  createUsers = async ({ email, hashedPassword, name, introduce, profileImage }) => {
    return await this.prisma.user.create({
      data: {
        email,
        password: hashedPassword,
        name,
        introduce,
        profileImage,
      },
    });
  };

  findOneEmail = async (email) => {
    return await this.prisma.user.findUnique({
      where: { email },
    });
  };

  findOneId = async (id) => {
    return await this.prisma.user.findUnique({
      where: { id },
      select: {
        id: true,
        email: true,
        name: true,
        introduce: true,
        profileImage: true,
        createdAt: true,
        updatedAt: true,
      },
    });
  };

  findOneRefreshTokenId = async (id) => {
    return await this.prisma.refreshToken.findUnique({
      where: { userId: id },
    });
  };

  update = async (userId, userData) => {
    return await this.prisma.user.update({
      where: { id: userId },
      data: {
        ...userData,
        updatedAt: new Date(), // 명시적으로 updatedAt 필드를 현재 시간으로 설정
      },
      select: {
        id: true,
        email: true,
        name: true,
        introduce: true,
        profileImage: true,
        createdAt: true,
        updatedAt: true,
      },
    });
  };

  updatepassword = async () => {
    // 비밀번호 업데이트 로직 추가 (필요한 경우)
  };
}

 

명시적으로 지정하기