project 同data science 有關就會用python
雖然香港係少
import { REQUEST } from '@nestjs/core';
import { Inject, PipeTransform, ForbiddenException } from '@nestjs/common';
import { FastifyRequest } from 'fastify';
export class UserPipe implements PipeTransform {
constructor(
@Inject(REQUEST)
private readonly request: FastifyRequest
) {}
async transform(value: unknown): Promise<unknown> {
if (!this.request.user) {
throw new ForbiddenException();
}
return value;
}
}
updateUser(@Body(UserRolePipe) dto: UpdateUserDto) {
// ....
}