test: add keys folder

This commit is contained in:
mahyargdz
2025-03-15 14:25:52 +03:30
parent 146c38025a
commit cb9860853e
8 changed files with 123 additions and 17 deletions
+2 -12
View File
@@ -3,18 +3,8 @@ import Decimal from "decimal.js";
import { ValueTransformer } from "typeorm";
export class DecimalTransformer implements ValueTransformer {
// to(value: Decimal | string | number): string {
// return new Decimal(value).toString();
// }
// from(value: string): number {
// return new Decimal(value).toNumber();
// }
to(value: Decimal | number | null): string | null {
if (value === null) return "0";
return value instanceof Decimal ? value.toString() : new Decimal(value).toString();
to(value: Decimal | null): string | null {
return value ? value.toString() : "0";
}
from(value: string | null): number {
+16 -3
View File
@@ -1,11 +1,24 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { ConfigService } from "@nestjs/config";
import { JwtModuleAsyncOptions } from "@nestjs/jwt";
export function jwtConfig(): JwtModuleAsyncOptions {
return {
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
secret: configService.getOrThrow<string>("JWT_SECRET_KEY"),
}),
useFactory: (configService: ConfigService) => {
const privateKeyPath = join(process.cwd(), "keys", "private.pem");
const publicKeyPath = join(process.cwd(), "keys", "public.pem");
return {
privateKey: readFileSync(privateKeyPath, "utf8"),
publicKey: readFileSync(publicKeyPath, "utf8"),
signOptions: {
algorithm: "RS256",
issuer: configService.getOrThrow<string>("JWT_ISSUER"),
},
};
},
};
}
+5 -1
View File
@@ -1,3 +1,5 @@
import { readFileSync } from "fs";
import { Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { PassportStrategy } from "@nestjs/passport";
@@ -12,7 +14,9 @@ export class JwtStrategy extends PassportStrategy(Strategy, JWT_STRATEGY_NAME) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.getOrThrow<string>("JWT_SECRET_KEY"),
secretOrKey: readFileSync(`${process.cwd()}/keys/public.pem`, "utf8"),
algorithms: ["RS256"],
issuer: configService.getOrThrow<string>("JWT_ISSUER"),
});
}