mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 21:34:54 +00:00
convert project from microservices to rest apis
This commit is contained in:
@ -22,7 +22,7 @@ import { UserRepository } from '../modules/user/repositories';
|
||||
}),
|
||||
HelperModule,
|
||||
],
|
||||
providers: [JwtStrategy, UserSessionRepository,AuthService,UserRepository],
|
||||
providers: [JwtStrategy, UserSessionRepository, AuthService, UserRepository],
|
||||
exports: [AuthService],
|
||||
})
|
||||
export class AuthModule {}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { HelperHashService } from '../../helper/services';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository';
|
||||
import { UserSessionEntity } from '@app/common/modules/session/entities';
|
||||
import { UserRepository } from '../../../../common/src/modules/user/repositories';
|
||||
import { UserSessionRepository } from '../../../../common/src/modules/session/repositories/session.repository';
|
||||
import { UserSessionEntity } from '../../../../common/src/modules/session/entities';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
|
||||
@ -2,7 +2,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { UserSessionRepository } from '@app/common/modules/session/repositories/session.repository';
|
||||
import { UserSessionRepository } from '../../../src/modules/session/repositories/session.repository';
|
||||
import { AuthInterface } from '../interfaces/auth.interface';
|
||||
|
||||
@Injectable()
|
||||
|
||||
@ -8,8 +8,8 @@ import config from './config';
|
||||
import { EmailService } from './util/email.service';
|
||||
|
||||
@Module({
|
||||
providers: [CommonService,EmailService],
|
||||
exports: [CommonService, HelperModule, AuthModule,EmailService],
|
||||
providers: [CommonService, EmailService],
|
||||
exports: [CommonService, HelperModule, AuthModule, EmailService],
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
load: config,
|
||||
|
||||
@ -5,7 +5,7 @@ export default registerAs(
|
||||
(): Record<string, any> => ({
|
||||
SMTP_HOST: process.env.SMTP_HOST,
|
||||
SMTP_PORT: parseInt(process.env.SMTP_PORT),
|
||||
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
||||
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
||||
SMTP_USER: process.env.SMTP_USER,
|
||||
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
||||
}),
|
||||
|
||||
@ -19,7 +19,7 @@ import { UserOtpEntity } from '../modules/user-otp/entities';
|
||||
username: configService.get('DB_USER'),
|
||||
password: configService.get('DB_PASSWORD'),
|
||||
database: configService.get('DB_NAME'),
|
||||
entities: [UserEntity, UserSessionEntity,UserOtpEntity],
|
||||
entities: [UserEntity, UserSessionEntity, UserOtpEntity],
|
||||
namingStrategy: new SnakeNamingStrategy(),
|
||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||
logging: true,
|
||||
@ -32,7 +32,6 @@ import { UserOtpEntity } from '../modules/user-otp/entities';
|
||||
},
|
||||
continuationLocalStorage: true,
|
||||
ssl: Boolean(JSON.parse(configService.get('DB_SSL'))),
|
||||
|
||||
}),
|
||||
}),
|
||||
],
|
||||
|
||||
@ -32,7 +32,6 @@ export class SnakeNamingStrategy
|
||||
firstTableName: string,
|
||||
secondTableName: string,
|
||||
firstPropertyName: any,
|
||||
_secondPropertyName: string,
|
||||
): string {
|
||||
return snakeCase(
|
||||
firstTableName +
|
||||
|
||||
@ -2,7 +2,7 @@ import { UnauthorizedException } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||
handleRequest(err, user, info) {
|
||||
handleRequest(err, user) {
|
||||
if (err || !user) {
|
||||
throw err || new UnauthorizedException();
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
export * from './helper.hash.service'
|
||||
export * from './helper.hash.service';
|
||||
|
||||
@ -1 +1 @@
|
||||
export * from './abstract.dto'
|
||||
export * from './abstract.dto';
|
||||
|
||||
@ -8,11 +8,11 @@ import {
|
||||
} from 'typeorm';
|
||||
|
||||
import { AbstractDto } from '../dtos';
|
||||
import { Constructor } from '@app/common/util/types';
|
||||
import { Constructor } from '../../../../../common/src/util/types';
|
||||
|
||||
export abstract class AbstractEntity<
|
||||
T extends AbstractDto = AbstractDto,
|
||||
O = never
|
||||
O = never,
|
||||
> {
|
||||
@PrimaryGeneratedColumn('increment')
|
||||
@Exclude()
|
||||
@ -38,7 +38,7 @@ export abstract class AbstractEntity<
|
||||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
||||
if (!dtoClass) {
|
||||
throw new Error(
|
||||
`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`
|
||||
`You need to use @UseDto on class (${this.constructor.name}) be able to call toDto function`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -22,5 +22,4 @@ export class SessionDto {
|
||||
@IsBoolean()
|
||||
@IsNotEmpty()
|
||||
public isLoggedOut: boolean;
|
||||
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
export * from './session.entity'
|
||||
export * from './session.entity';
|
||||
|
||||
@ -5,7 +5,7 @@ import { SessionDto } from '../dtos/session.dto';
|
||||
@Entity({ name: 'userSession' })
|
||||
export class UserSessionEntity extends AbstractEntity<SessionDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
|
||||
@ -1 +1 @@
|
||||
export * from './user-otp.dto'
|
||||
export * from './user-otp.dto';
|
||||
|
||||
@ -4,7 +4,7 @@ export class UserOtpDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public uuid: string;
|
||||
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
public email: string;
|
||||
|
||||
@ -1 +1 @@
|
||||
export * from './user-otp.entity'
|
||||
export * from './user-otp.entity';
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { Column, Entity } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { UserOtpDto } from '../dtos';
|
||||
import { OtpType } from '@app/common/constants/otp-type.enum';
|
||||
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
|
||||
@Entity({ name: 'user-otp' })
|
||||
export class UserOtpEntity extends AbstractEntity<UserOtpDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()',
|
||||
nullable: false,
|
||||
})
|
||||
public uuid: string;
|
||||
|
||||
@ -5,7 +5,7 @@ import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
@Entity({ name: 'user' })
|
||||
export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
type: 'uuid',
|
||||
default: () => 'gen_random_uuid()', // Use gen_random_uuid() for default value
|
||||
nullable: false,
|
||||
})
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const ResponseMessage = (message: string) =>
|
||||
SetMetadata('response_message', message);
|
||||
SetMetadata('response_message', message);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export interface Response<T> {
|
||||
statusCode: number;
|
||||
message: string;
|
||||
data?: T;
|
||||
}
|
||||
statusCode: number;
|
||||
message: string;
|
||||
data?: T;
|
||||
}
|
||||
|
||||
@ -1,46 +1,45 @@
|
||||
export type Constructor<T, Arguments extends unknown[] = undefined[]> = new (
|
||||
...arguments_: Arguments
|
||||
) => T;
|
||||
|
||||
export type Plain<T> = T;
|
||||
export type Optional<T> = T | undefined;
|
||||
export type Nullable<T> = T | null;
|
||||
|
||||
export type PathImpl<T, Key extends keyof T> = Key extends string
|
||||
? T[Key] extends Record<string, any>
|
||||
?
|
||||
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> &
|
||||
string}`
|
||||
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
|
||||
...arguments_: Arguments
|
||||
) => T;
|
||||
|
||||
export type Plain<T> = T;
|
||||
export type Optional<T> = T | undefined;
|
||||
export type Nullable<T> = T | null;
|
||||
|
||||
export type PathImpl<T, Key extends keyof T> = Key extends string
|
||||
? T[Key] extends Record<string, any>
|
||||
?
|
||||
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> &
|
||||
string}`
|
||||
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
|
||||
: never
|
||||
: never;
|
||||
|
||||
export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
|
||||
|
||||
export type Path<T> = keyof T extends string
|
||||
? PathImpl2<T> extends string | keyof T
|
||||
? PathImpl2<T>
|
||||
: keyof T
|
||||
: never;
|
||||
|
||||
export type PathValue<
|
||||
T,
|
||||
P extends Path<T>,
|
||||
> = P extends `${infer Key}.${infer Rest}`
|
||||
? Key extends keyof T
|
||||
? Rest extends Path<T[Key]>
|
||||
? PathValue<T[Key], Rest>
|
||||
: never
|
||||
: never;
|
||||
|
||||
export type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
|
||||
|
||||
export type Path<T> = keyof T extends string
|
||||
? PathImpl2<T> extends string | keyof T
|
||||
? PathImpl2<T>
|
||||
: keyof T
|
||||
: never;
|
||||
|
||||
export type PathValue<
|
||||
T,
|
||||
P extends Path<T>
|
||||
> = P extends `${infer Key}.${infer Rest}`
|
||||
? Key extends keyof T
|
||||
? Rest extends Path<T[Key]>
|
||||
? PathValue<T[Key], Rest>
|
||||
: never
|
||||
: never
|
||||
: P extends keyof T
|
||||
: never
|
||||
: P extends keyof T
|
||||
? T[P]
|
||||
: never;
|
||||
|
||||
export type KeyOfType<Entity, U> = {
|
||||
[P in keyof Required<Entity>]: Required<Entity>[P] extends U
|
||||
? P
|
||||
: Required<Entity>[P] extends U[]
|
||||
|
||||
export type KeyOfType<Entity, U> = {
|
||||
[P in keyof Required<Entity>]: Required<Entity>[P] extends U
|
||||
? P
|
||||
: Required<Entity>[P] extends U[]
|
||||
? P
|
||||
: never;
|
||||
}[keyof Entity];
|
||||
|
||||
}[keyof Entity];
|
||||
|
||||
@ -3,7 +3,7 @@ import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
export function setupSwaggerAuthentication(app: INestApplication): void {
|
||||
const options = new DocumentBuilder()
|
||||
.setTitle('Authentication-Service')
|
||||
.setTitle('APIs Documentation')
|
||||
.addBearerAuth({
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
@ -13,7 +13,7 @@ export function setupSwaggerAuthentication(app: INestApplication): void {
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, options);
|
||||
SwaggerModule.setup('api/authentication/documentation', app, document, {
|
||||
SwaggerModule.setup('api', app, document, {
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user