我有多种身份验证策略,例如其中之一:
@Injectable()
export class EmployeeStrategy extends PassportStrategy(Strategy, 'employee') {
constructor(
private authService: AuthService,
@Inject(appConfig.KEY)
configService: ConfigType<typeof appConfig>,
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: configService.EMPLOYEE_KEY,
});
}
async validate({ phone }: JwtPayload) {
const employee = await this.authService.authByRole(phone, Role.Employee);
if (!employee) {
throw new UnauthorizedException('insufficient scope');
}
return employee;
}
Run Code Online (Sandbox Code Playgroud)
还有一些人大多喜欢这个。但是因为我在其中抛出了未经授权的异常,所以我不能在同一个路由/控制器上使用多个异常。例如
@UseGuards(AuthGuard(['employee', 'admin']))
Run Code Online (Sandbox Code Playgroud)
第一个崩溃导致错误的。如何解决这个问题?
文档对我来说似乎很混乱。如何从对象数组创建文档,每个对象代表一行并将其保存为缓冲区?
我有一个这样的函数,它检查适当的帐户类型:
CREATE OR REPLACE FUNCTION acc_is_exclusive(acc_no integer, acc_type char) RETURNS integer AS $$
BEGIN
RETURN (SELECT 1 FROM account WHERE account_no = acc_no AND account_type = acc_type);
END;
$$ LANGUAGE plpgsql;
Run Code Online (Sandbox Code Playgroud)
返回类型为整数,如果没有找到记录,则返回 NULL。这有道理吗?或者我需要以某种方式显式声明返回类型将是整数或空?
I'm trying to implement template function, for reading from byte array in big endian order. This is my current implementation:
template<typename T>
T load_big_endian(const unsigned char* buf) {
T res {};
std::size_t size = sizeof(T) - 1;
for (int i = 0; i <= size; i += 1) {
res |= static_cast<T>(buf[size - i] << (i * 8));
}
return res;
}
Run Code Online (Sandbox Code Playgroud)
Is this a good solution? Or better use a separate functions for each type, like load32_big_endian? And …