refactor source code

This commit is contained in:
2024-10-29 17:42:54 +07:00
parent 3b23d9e0b7
commit 152bb50da8
83 changed files with 8473 additions and 7577 deletions

View File

@@ -1,7 +1,7 @@
import { Global, Module } from '@nestjs/common';
import { Global, Module } from '@nestjs/common'
import { CommonGraphqlError } from './graphql/common.graphql.error';
import { JwtUtils } from './utils/jwt.utils';
import { CommonGraphqlError } from './graphql/common.graphql.error'
import { JwtUtils } from './utils/jwt.utils'
@Global()
@Module({
imports: [],

View File

@@ -1,15 +1,15 @@
import { Inject, Injectable } from '@nestjs/common';
import { Builder } from '../../Graphql/graphql.builder';
import { Inject, Injectable } from '@nestjs/common'
import { Builder } from '../../Graphql/graphql.builder'
import {
PothosRef,
PothosSchema,
SchemaBuilderToken,
} from '@smatch-corp/nestjs-pothos';
} from '@smatch-corp/nestjs-pothos'
@Injectable()
export class CommonGraphqlError extends PothosSchema {
constructor(@Inject(SchemaBuilderToken) private readonly builder: Builder) {
super();
super()
}
@PothosRef()
@@ -19,6 +19,6 @@ export class CommonGraphqlError extends PothosSchema {
fields: (t) => ({
message: t.exposeString('message'),
}),
});
})
}
}

View File

@@ -1,29 +1,29 @@
import { sign, verify } from 'jsonwebtoken';
import { sign, verify } from 'jsonwebtoken'
import { Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common'
@Injectable()
export class JwtUtils {
signToken(payload: string, expiresIn: string) {
return sign(payload, process.env.JWT_SECRET!, { expiresIn });
return sign(payload, process.env.JWT_SECRET!, { expiresIn })
}
//eslint-disable-next-line @typescript-eslint/no-explicit-any
signTokenRS256(payload: any, expiresIn: string) {
const privateKey = process.env.JWT_RS256_PRIVATE_KEY!;
const privateKey = process.env.JWT_RS256_PRIVATE_KEY!
return sign(payload, privateKey, {
algorithm: 'RS256',
expiresIn,
});
})
}
verifyTokenRS256(token: string) {
const publicKey = process.env.JWT_RS256_PUBLIC_KEY!;
const publicKey = process.env.JWT_RS256_PUBLIC_KEY!
return verify(token, publicKey, {
algorithms: ['RS256'],
});
})
}
verifyToken(token: string) {
return verify(token, process.env.JWT_SECRET!);
return verify(token, process.env.JWT_SECRET!)
}
}