Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Dec 21, 2023
1 parent 7997be9 commit fde94b7
Show file tree
Hide file tree
Showing 131 changed files with 417 additions and 694 deletions.
6 changes: 4 additions & 2 deletions apps/levansy-access-service/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Module } from '@nestjs/common'
import { infrastructureMetadata } from './infrastructure'
import { useCaseMetadata } from './domain'
import { presentationMetadata } from './presentation'
import { configMetadata } from './config'

@Module(
concatModuleMetadata([
presentationMetadata,
useCaseMetadata,
configMetadata,
infrastructureMetadata,
useCaseMetadata,
presentationMetadata,
]),
)
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { IsEnum, IsNotEmpty, IsNumber, IsString } from 'class-validator'
import { Expose } from 'class-transformer'
import { NodeEnv } from '@diut/common'

import { IAppConfig } from 'src/domain'

export class AppConfig implements IAppConfig {
export class AppConfig {
@Expose()
@IsNumber()
HTTP_PORT: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { makeConfigLoader } from '@diut/nest-core'
import { Expose } from 'class-transformer'
import { IsNotEmpty, IsString } from 'class-validator'

import { IAuthConfig } from 'src/domain'

export class AuthConfig implements IAuthConfig {
export class AuthConfig {
@Expose()
@IsString()
@IsNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { makeConfigLoader } from '@diut/nest-core'
import { Expose } from 'class-transformer'
import { IsString, MinLength } from 'class-validator'
import { registerAs } from '@nestjs/config'

export class ClientConfig {
@Expose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { makeConfigLoader } from '@diut/nest-core'
import { Expose } from 'class-transformer'
import { IsNumber, IsString, MinLength } from 'class-validator'

import { IMinioConfig } from 'src/domain'

export class MinioConfig implements IMinioConfig {
export class MinioConfig {
@Expose()
@IsString()
@MinLength(1)
Expand Down
21 changes: 21 additions & 0 deletions apps/levansy-access-service/src/config/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ConfigModule } from '@diut/nest-core'
import { ModuleMetadata } from '@nestjs/common'

import { loadAppConfig } from './app.config'
import { loadAuthConfig } from './auth.config'
import { loadMinioConfig } from './minio.config'
import { loadClientConfig } from './client.config'
import { loadMongoConfig } from './mongo.config'
import { loadLogConfig } from './log.config'

export const configMetadata: ModuleMetadata = {
imports: [
ConfigModule.forRoot({}),
ConfigModule.forFeature(loadAppConfig),
ConfigModule.forFeature(loadAuthConfig),
ConfigModule.forFeature(loadClientConfig),
ConfigModule.forFeature(loadLogConfig),
ConfigModule.forFeature(loadMinioConfig),
ConfigModule.forFeature(loadMongoConfig),
],
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { makeConfigLoader } from '@diut/nest-core'
import { Expose } from 'class-transformer'
import { IsString, MinLength } from 'class-validator'
import { registerAs } from '@nestjs/config'

export class MongoConfig {
@Expose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum AuthSubject {
BioProduct = 'bio-product',
TestCategory = 'test-category',
}
32 changes: 0 additions & 32 deletions apps/levansy-access-service/src/domain/entity/bio-product.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BaseEntity } from '../base-entity'

export type BioProduct = BaseEntity & {
index: number
name: string
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { EntityExample } from '../base-entity'
import { BioProduct } from './entity'

export const exampleBioProduct: EntityExample<BioProduct> = {
index: {
example: 1,
description: 'index',
},
name: {
example: 'CHIV Advia centaur',
description: 'name',
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './entity'
export * from './example'
export * from './permission'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AuthSubject } from '../auth-subject'
import { EntityPermission } from '../permission'

export enum BioProductActions {
Manage = 'manage',
Read = 'read',
}

export type BioProductPermissions = EntityPermission<
AuthSubject.BioProduct,
BioProductActions
>
26 changes: 0 additions & 26 deletions apps/levansy-access-service/src/domain/entity/permission.ts

This file was deleted.

17 changes: 17 additions & 0 deletions apps/levansy-access-service/src/domain/entity/permission/entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MongoQuery } from '@casl/ability'

import { BaseEntity } from '../base-entity'
import { EntityPermission } from './mapping'

export type Permission<TMapping extends EntityPermission = EntityPermission> =
BaseEntity & {
index: number
name: string
description: string
rule: {
subject: TMapping['subject']
action: TMapping['actions'][number]
inverted?: boolean
conditions?: MongoQuery<TMapping['subject']>
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './entity'
export * from './mapping'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AuthSubject } from '../auth-subject'

export type EntityPermission<
TSubject extends AuthSubject = AuthSubject,
TAction extends string = string,
> = {
subject: TSubject
actions: TAction[]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseEntity } from './base-entity'
import { Permission } from './permission'
import { BaseEntity } from '../base-entity'
import { Permission } from '../permission/entity'

export type Role = BaseEntity & {
index: string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './entity'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseEntity } from '../base-entity'

export type TestCategory = BaseEntity & {
index: number
name: string
reportIndex: number
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { BaseEntity, EntityExample } from './base-entity'

export type TestCategory = BaseEntity & {
index: number
name: string
reportIndex: number
}
import { EntityExample } from '../base-entity'
import { TestCategory } from './entity'

export const exampleTestCategory: EntityExample<TestCategory> = {
index: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './entity'
export * from './example'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseEntity } from './base-entity'
import { BaseEntity } from '../base-entity'
// import { Permission } from './permission'
// import { Role } from './role'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './entity'
14 changes: 0 additions & 14 deletions apps/levansy-access-service/src/domain/interface/auth/context.ts

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ExecutionContext } from '@nestjs/common'

import { User } from 'src/domain/entity'

export const AuthorizationContextToken = Symbol('AuthorizationContext')

export interface IAuthorizationContext {
prepareData(context: ExecutionContext): Promise<void>
getData(): ContextData
}

export type ContextData = {
user: User
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { DomainException } from '../exception'

export class AuthorizationException extends DomainException {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './context'
export * from './exception'

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class DomainException extends Error {}

This file was deleted.

This file was deleted.

5 changes: 2 additions & 3 deletions apps/levansy-access-service/src/domain/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './config'
export * from './repository'
export * from './external'
export * from './auth'
export * from './service'
export * from './authorization'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './puppeteer'
export * from './storage'
Loading

0 comments on commit fde94b7

Please sign in to comment.