feature: Phase3 - Task templates + generation on send
This commit is contained in:
25
backend/src/common/guards/lab-org.guard.ts
Normal file
25
backend/src/common/guards/lab-org.guard.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import {
|
||||
CanActivate,
|
||||
ExecutionContext,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { PrismaService } from '../../../prisma/prisma.service';
|
||||
import { assertLabOrganization } from '../../common/organization-type';
|
||||
|
||||
@Injectable()
|
||||
export class LabOrgGuard implements CanActivate {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
const request = context.switchToHttp().getRequest<{ user?: { organizationId?: string } }>();
|
||||
const organizationId = request.user?.organizationId;
|
||||
|
||||
if (!organizationId) {
|
||||
throw new UnauthorizedException('Organization is not selected');
|
||||
}
|
||||
|
||||
await assertLabOrganization(this.prisma, organizationId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user