import { ForbiddenException, Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.module'; import type { AuthUser } from '../guards/jwt-auth.guard'; @Injectable() export class StoreMembershipService { constructor(private readonly prisma: PrismaService) {} async assertStoreMembership(accountId: bigint, storeId: bigint) { const binding = await this.prisma.storeAccountStore.findUnique({ where: { storeAccountId_storeId: { storeAccountId: accountId, storeId }, }, }); if (!binding) { throw new ForbiddenException('无权访问该门店'); } return binding; } requireShopStoreId(user: AuthUser): bigint { if (!user.storeId) { throw new ForbiddenException('请先选择门店'); } return user.storeId; } }