import { Injectable } from "@nestjs/common"; import { PrismaService } from "../prisma/prisma.service.js"; // Q-3 裝置推播 token 註冊:同一個 token 重複註冊(例如 APP 重新啟動)視為更新,不會產生重複紀錄。 @Injectable() export class PushTokenService { constructor(private readonly prisma: PrismaService) {} async register(userId: string, token: string, platform: string) { return this.prisma.client.pushToken.upsert({ where: { token }, update: { userId, platform }, create: { userId, token, platform }, }); } async listForUser(userId: string) { return this.prisma.client.pushToken.findMany({ where: { userId } }); } }