Skip to content

Commit

Permalink
Refactor: Refoldering
Browse files Browse the repository at this point in the history
  • Loading branch information
ialiaslani committed Dec 30, 2022
1 parent 07f89f2 commit 5fb0a77
Show file tree
Hide file tree
Showing 76 changed files with 159 additions and 251 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
9. add user status *DONE
10. validate permission (no match, wrong structure) *DONE
11. model generator (crud gnerator) *DONE
12. refolder *DONE

12. name the routes
13. seed
14. update role's permission
15. notification
16. socket (emqx) (for backup service)
17. refolder
17. name the routes
18. add excel too Crud Generator
19. add ELASTIC
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"rich": "ts-node ./commander.ts"
"rich": "ts-node ./rich/commander/commander.ts"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
Expand Down
12 changes: 6 additions & 6 deletions commander.ts → rich/commander/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class CrudCommand extends CommandRunner {
const EntityName = this.generateModuleName(name, true)

return `
import { CommonEntity } from "src/common/models/common.entity";
import { CommonEntity } from "@rich";
import { Entity } from "typeorm";
@Entity("${name}s")
Expand All @@ -84,7 +84,7 @@ export class CrudCommand extends CommandRunner {
const SearchDtoName = this.generateModuleName(name, true)

return `
import { CommonSearchDto } from "src/common/Dtos/common.search.dto"
import { CommonSearchDto } from "@rich"
export class ${SearchDtoName}SearchDto extends CommonSearchDto { }
`
Expand All @@ -95,7 +95,7 @@ export class CrudCommand extends CommandRunner {
const ParamsDtoName = this.generateModuleName(name, true)

return `
import { CommonParamsDto } from 'src/common/Dtos/common.params.dto';
import { CommonParamsDto } from '@rich';
export class ${ParamsDtoName}${type}Dto extends CommonParamsDto {}
`
Expand Down Expand Up @@ -133,7 +133,7 @@ export class CrudCommand extends CommandRunner {
import { ${ModuleName} } from './model/${name}.entity';
import { ${ModuleName}Service } from './${name}.service';
import { ${ModuleName}Controller } from './${name}.controller';
import { CommonModule } from 'src/common/common.module';
import { CommonModule } from '@rich';
@Module({
imports: [
Expand All @@ -160,7 +160,7 @@ export class CrudCommand extends CommandRunner {
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ${ServiceName} } from './model/${name}.entity';
import { CommonService } from 'src/common/common.service';
import { CommonService } from '@rich';
@Injectable()
export class ${ServiceName}Service extends CommonService {
Expand Down Expand Up @@ -196,7 +196,7 @@ export class CrudCommand extends CommandRunner {
Delete
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from 'src/auth/auth.guard';
import { AuthGuard } from '@rich';
import { ${ControllerName}CreateDto } from './dto/${name}.create.dto';
import { ${ControllerName}DeleteDto } from './dto/${name}.delete.dto';
import { ${ControllerName}UpdatePayloadDto, ${ControllerName}UpdateParamsDto } from './dto/${name}.update.dto';
Expand Down
45 changes: 45 additions & 0 deletions rich/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//rich module
export * from "./modules/rich.module"

export * from "./modules/excel/excel.service"
export * from "./modules/cache/cache.service"
export * from "./modules/file/file.utils"



export * from "./modules/permission/permission.guard"
export * from "./modules/permission/permission.decorator"

export * from "./modules/auth/auth.guard"


//commons
export * from "./modules/common/common.module"
export * from "./modules/common/common.service"
export * from "./modules/common/models/common.entity"
export * from "./modules/common/Dtos/common.params.dto"
export * from "./modules/common/Dtos/common.search.dto"

export * from "./modules/permission/permission.gurd.service"
export * from "./modules/permission/permission.module"
export * from "./modules/permission/models/permission.entity"


export * from "./modules/request_log/request_log.middleware"
export * from "./modules/request_log/request_log.service"
export * from "./modules/request_log/models/request_log.entity"

export * from "./modules/auth/auth.module"

export * from "./modules/cache/cache.module"


export * from "./modules/request_log/request_log.module"

export * from "./modules/role/role.module"
export * from "./modules/role/models/role.entity"

export * from "./modules/user/user.module"
export * from "./modules/user/models/user.entity"
export * from "./modules/user/user.service"

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Body, Controller, Post, NotFoundException, BadRequestException, Res, UseInterceptors, ClassSerializerInterceptor } from '@nestjs/common';
import { UserService } from 'src/user/user.service';
import { Body, Controller, Post, NotFoundException, BadRequestException, UseInterceptors, ClassSerializerInterceptor } from '@nestjs/common';
import { LoginDto } from './Dtos/login.dto';
import { RegisterDto } from './Dtos/register.dto';
import * as bcrypt from "bcrypt"
import { JwtService } from '@nestjs/jwt';
import { ApiTags } from '@nestjs/swagger';
import { HasPermission } from 'src/permission/permission.decorator';
import { AuthService } from './auth.service';
import { User } from 'src/user/models/user.entity';
import { UserService } from '../user/user.service';
import { HasPermission } from '../permission/permission.decorator';
import { User } from '../user/models/user.entity';

@UseInterceptors(ClassSerializerInterceptor)
@Controller()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { JwtModule, JwtService } from '@nestjs/jwt';
import { UserModule } from 'src/user/user.module';
import { UserModule } from '../user/user.module';
import { AuthController } from './auth.controller';
import { AuthGuard } from './auth.guard';
import { AuthService } from './auth.service';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common';
import { CacheService } from 'src/cache/cache.service';
import { CacheService } from '../cache/cache.service';

@Injectable()
export class AuthService extends CacheService {}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { CacheService } from './cache.service';
],
providers: [CacheService],
})

export class CacheModule implements OnModuleInit {

constructor (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CacheService {
async getCache(key: string): Promise<{
key: string, value: string, ttl: number
}> {
const value = await this.cache.get(key) as string;
const value: string = await this.cache.get(key)
const ttl = await this.cache.store.ttl(key)
return {
key, value, ttl
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Module } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { AuthGuard } from 'src/auth/auth.guard';
import { AuthGuard } from '../auth/auth.guard';

@Module({
providers: [JwtService, AuthGuard],
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ExcelService } from 'src/excel/excel.service';
import { Repository } from 'typeorm';
import { ExcelService } from '../excel/excel.service';

@Injectable()
export abstract class CommonService extends ExcelService {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { CommonEntity } from 'src/common/models/common.entity';
import * as excel from 'exceljs';
import { format } from 'date-fns-jalali';
import { CommonEntity } from '../common/models/common.entity';

@Injectable()
export class ExcelService {
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions rich/modules/permission/Dtos/permission.delete.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CommonParamsDto } from "../../common/Dtos/common.params.dto";

export class PermissionDeleteDto extends CommonParamsDto {}
3 changes: 3 additions & 0 deletions rich/modules/permission/Dtos/permission.search.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CommonSearchDto } from "../../common/Dtos/common.search.dto";

export class PermissionSearchDto extends CommonSearchDto { }
3 changes: 3 additions & 0 deletions rich/modules/permission/Dtos/permission.show.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CommonParamsDto } from "../../common/Dtos/common.params.dto";

export class PermissionShowDto extends CommonParamsDto {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';
import { CommonParamsDto } from 'src/common/Dtos/common.params.dto';
import { CommonParamsDto } from '../../common/Dtos/common.params.dto';


export class PermissionUpdateParamsDto extends CommonParamsDto {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonEntity } from "src/common/models/common.entity";
import { CommonEntity } from "../../common/models/common.entity";
import { Column, Entity } from "typeorm";

@Entity("permissions")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Controller, Request, UseGuards, UseInterceptors, ClassSerializerInterceptor, Get, Delete, Param, Body, Query, Put, Post } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from 'src/auth/auth.guard';
import { PermissionCreateDto } from './Dtos/permission.create.dto';
import { PermissionDeleteDto } from './Dtos/permission.delete.dto';
import { PermissionSearchDto } from './Dtos/permission.search.dto';
import { PermissionShowDto } from './Dtos/permission.show.dto';
import { PermissionUpdateParamsDto, PermissionUpdatePayloadDto } from './Dtos/permission.update.dto';
import { PermissionService } from './permission.service';
import { PermissionGenerateDto } from './Dtos/permission.generate.dto';
import { AuthGuard } from '../auth/auth.guard';

@ApiBearerAuth("access-token")
@UseGuards(AuthGuard)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
import { Observable } from 'rxjs';
import { PermissionGuardService } from './permission.gurd.service';
import { Reflector } from '@nestjs/core';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import { JwtService } from "@nestjs/jwt";
import { UserService } from "src/user/user.service";
import { PermissionUtils } from "./permission.utils";
import { UserService } from "../user/user.service";

@Injectable()
export class PermissionGuardService extends PermissionUtils {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Module } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthGuard } from 'src/auth/auth.guard';
import { Permission } from './models/permission.entity';
import { PermissionController } from './permission.controller';
import { PermissionService } from './permission.service';
import { PermissionUtils } from './permission.utils';
import { AuthGuard } from '../auth/auth.guard';

@Module({
imports: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Router } from 'express';
import { CommonService } from 'src/common/common.service';
import { Repository } from 'typeorm';
import { Permission } from './models/permission.entity';
import { PermissionUtils } from './permission.utils';
import { PermissionGenerateDto } from './Dtos/permission.generate.dto';
import { CommonService } from '../common/common.service';

@Injectable()
export class PermissionService extends CommonService {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonEntity } from "src/common/models/common.entity";
import { User } from "src/user/models/user.entity";
import { CommonEntity } from "../../common/models/common.entity";
import { User } from "../../user/models/user.entity";
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";

@Entity("request_logs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ClassSerializerInterceptor, Controller, Get, Query, UseGuards, UseInter
import { RequestLogSearchDto } from './Dtos/reaquest_log.search.dto';
import { RequestLogService } from './request_log.service';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from 'src/auth/auth.guard';
import { AuthGuard } from '../auth/auth.guard';

@UseInterceptors(ClassSerializerInterceptor)
@ApiBearerAuth("access-token")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RequestLogController } from './request_log.controller';
import { RequestLogService } from './request_log.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RequestLog } from './models/request_log.entity';
import { CommonModule } from 'src/common/common.module';
import { CommonModule } from '../common/common.module';

@Module({
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { RequestLog } from "./models/request_log.entity";
import { Repository } from "typeorm";
import { CommonService } from "src/common/common.service";
import { CommonService } from "../common/common.service";

@Injectable()
export class RequestLogService extends CommonService {
Expand Down
47 changes: 47 additions & 0 deletions rich/modules/rich.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MulterModule } from '@nestjs/platform-express';
import { APP_GUARD } from '@nestjs/core';
import { AuthModule } from './auth/auth.module';
import { UserModule } from './user/user.module';
import { PermissionModule } from './permission/permission.module';
import { RoleModule } from './role/role.module';
import { CommonModule } from './common/common.module';
import { RequestLog } from './request_log/models/request_log.entity';
import { RequestLogModule } from './request_log/request_log.module';
import { PermissionGuard } from './permission/permission.guard';
import { PermissionGuardService } from './permission/permission.gurd.service';
import { RequestLogService } from './request_log/request_log.service';
import { AppLoggerMiddleware } from './request_log/request_log.middleware';
import { CacheModule } from './cache/cache.module';

@Module({})
export class RichModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
consumer.apply(AppLoggerMiddleware).forRoutes('*');
}
}

export const RichImports = (dbConfig: object) => [
TypeOrmModule.forRoot(dbConfig),
AuthModule,
UserModule,
PermissionModule,
RoleModule,
CommonModule,
TypeOrmModule.forFeature([RequestLog]),
RequestLogModule,
CacheModule,
MulterModule.register({
dest: './upload',
})
]

export const RichProviders = [
{
provide: APP_GUARD,
useClass: PermissionGuard
},
PermissionGuardService,
RequestLogService
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonEntity } from "src/common/models/common.entity";
import { Permission } from "src/permission/models/permission.entity";
import { Permission } from "../../permission/models/permission.entity";
import { CommonEntity } from "../../common/models/common.entity";
import { Column, Entity, JoinTable, ManyToMany } from "typeorm";

@Entity("roles")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
Delete
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from 'src/auth/auth.guard';
import { RoleCreateDto } from './Dtos/role.create.dto';
import { RoleDeleteDto } from './Dtos/role.delete.dto';
import { RoleUpdatePayloadDto, RoleUpdateParamsDto } from './Dtos/role.update.dto';
import { RoleShowDto } from './Dtos/role.show.dto';
import { RoleSearchDto } from './Dtos/role.search.dto';
import { RoleService } from './role.service';
import { AuthGuard } from '../auth/auth.guard';

@ApiBearerAuth("access-token")
@UseGuards(AuthGuard)
Expand Down
Loading

0 comments on commit 5fb0a77

Please sign in to comment.