Skip to content

Commit

Permalink
refactor: 💡 cast user dto to exclude values on api response
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Dec 2, 2023
1 parent 1b3b326 commit 19c929d
Show file tree
Hide file tree
Showing 79 changed files with 4,409 additions and 4,173 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ testem.log
Thumbs.db
.env
.angular

.nx/cache
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/dist
/coverage
.angular

/.nx/cache
11 changes: 2 additions & 9 deletions account/data-access/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
Expand All @@ -28,14 +28,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/data-access/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/data-access/jest.config.ts"
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions account/data-access/src/lib/interfaces/account-inject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
UserServiceImpl,
AuthServiceImpl,
GroupServiceImpl,
AuthServiceMock,
UserServiceMock,
GroupServiceMock,
} from '../infrastructure'

export interface AccountInject {
auth: AuthServiceImpl | AuthServiceMock
user: UserServiceImpl | UserServiceMock
group: GroupServiceImpl | GroupServiceMock
}
1 change: 1 addition & 0 deletions account/data-access/src/lib/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './account-inject';
52 changes: 52 additions & 0 deletions account/data-access/src/lib/providers/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {EnvConfig} from '@dev/shared-util-data'
import {Http} from '@dev/shared-data-access'
import {AccountInject} from '../interfaces'
import {AuthService, GroupService, UserService} from '@dev/account-domain'
import {AuthFacade, GroupFacade, UserFacade} from '../application'

function provideServices(env: EnvConfig<AccountInject>) {
return [
{
provide: UserService,
useFactory(http: Http) {
return new env.inject.user(http, env.api.account)
},
deps: [Http],
},
{
provide: AuthService,
useFactory(http: Http) {
return new env.inject.auth(http, env.api.accountAuth)
},
deps: [Http],
},
{
provide: GroupService,
useFactory(http: Http) {
return new env.inject.group(http, env.api.accountGroups)
},
deps: [Http],
},
]
}

export function provideFacades() {
return [
{
provide: UserFacade,
deps: [UserService],
},
{
provide: AuthFacade,
deps: [AuthService],
},
{
provide: GroupFacade,
deps: [GroupService],
},
]
}

export function provideAccount(env: EnvConfig<AccountInject>) {
return [provideServices(env), provideFacades()]
}
4 changes: 1 addition & 3 deletions account/data-access/src/lib/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './auth'
export * from './group'
export * from './user'
export * from './account'
31 changes: 18 additions & 13 deletions account/data-access/src/lib/providers/user.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import {Http, provideByEnv, provideServiceMock} from '@dev/shared-data-access'
import {UserServiceImpl, UserServiceMock} from '../infrastructure'
import {User, UserService} from '@dev/account-domain'
import {UserService} from '@dev/account-domain'
import {EnvConfig} from '@dev/shared-util-data'
import {Http} from '@dev/shared-data-access'
import {AccountInject} from '../interfaces'
import {UserFacade} from '../application'

export function provideUserService(api = '/api/account') {
export function provideUserService(env: EnvConfig<AccountInject>) {
return {
provide: UserService,
useFactory(http: Http) {
return new UserServiceImpl(http, api)
return new env.inject.user(http, env.api.account)
},
deps: [Http],
}
}

export function provideUserServiceMock(collection: User[] = []) {
return provideServiceMock(UserService, UserServiceMock, collection)
}
// export function provideUserServiceMock(collection: User[] = []) {
// return provideServiceMock(UserService, UserServiceMock, collection)
// }

export function provideUserFacade() {
return {
Expand All @@ -24,8 +25,12 @@ export function provideUserFacade() {
}
}

export const provideUser = provideByEnv(
provideUserService,
provideUserServiceMock,
provideUserFacade()
)
export function provideUser(env: EnvConfig<AccountInject>) {
return [provideUserService(env), provideUserFacade()]
}

// export const provideUser = provideByEnv(
// provideUserService,
// provideUserServiceMock,
// provideUserFacade()
// )
1 change: 1 addition & 0 deletions account/data-access/src/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './lib/infrastructure'
export * from './lib/application'
export * from './lib/interfaces'
export * from './lib/providers'
export * from './lib/dtos'
11 changes: 2 additions & 9 deletions account/data-source/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
Expand All @@ -28,14 +28,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/data-source/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/data-source/jest.config.ts"
}
}
},
Expand Down
11 changes: 2 additions & 9 deletions account/domain/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
Expand All @@ -28,14 +28,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/domain/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/domain/jest.config.ts"
}
}
},
Expand Down
11 changes: 2 additions & 9 deletions account/feature/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/feature/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/feature/jest.config.ts"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
Expand Down
6 changes: 2 additions & 4 deletions account/feature/src/lib/account-feature.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import {ReactiveFormsModule} from '@angular/forms'
import {accountFeatureRoutes} from './account-feature.routes'
import {AccountFeatureContainer} from './account-feature.container'
import {UsersContainer, GroupsContainer} from './containers'
import {provideUserFacade, provideUserService} from '@dev/account-data-access'
import {
CreateUserDialog,
UpdateUserDialog,
CreateGroupDialog,
UpdateGroupDialog,
UpdatePasswordDialog,
PermissionComponent,
} from './components'
import {PermissionComponent} from './components/permission/permission.component'

@NgModule({
imports: [
Expand All @@ -37,7 +36,6 @@ import {PermissionComponent} from './components/permission/permission.component'
CreateGroupDialog,
UpdateGroupDialog,
PermissionComponent,
],
providers: [provideUserService(), provideUserFacade()],
]
})
export class AccountFeatureModule {}
1 change: 1 addition & 0 deletions account/feature/src/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './update-password/update-password.dialog'

export * from './create-group/create-group.dialog'
export * from './update-group/update-group.dialog'
export * from './permission/permission.component'
4 changes: 2 additions & 2 deletions account/feature/src/lib/containers/users/users.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import {
import {User, UserFacade, UpdateUser} from '@dev/account-data-access'
import {
CreateUserDialog,
UpdatePasswordDialog,
UpdateUserDialog,
UpdatePasswordDialog,
} from '../../components'
import {Columns, FeatureContainer} from '@dev/shared-ui-base'
import {FilterByFieldOption} from '@dev/shared-ui-forms'
import {MatPaginator} from '@angular/material/paginator'
import {MatSnackBar} from '@angular/material/snack-bar'
import {MatDialog} from '@angular/material/dialog'
import {MatSort} from '@angular/material/sort'
import {FormControl} from '@angular/forms'
import {MatSnackBar} from '@angular/material/snack-bar'

@Component({
selector: 'dev-users',
Expand Down
11 changes: 2 additions & 9 deletions account/resource/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"projectType": "library",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["account/resource/**/*.ts"]
Expand All @@ -15,14 +15,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/resource/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/resource/jest.config.ts"
}
}
},
Expand Down
7 changes: 3 additions & 4 deletions account/resource/src/lib/account-resource.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {PageOptionsDto} from '@dev/shared-data-source'
import {PageOptionsDto, castTo} from '@dev/shared-data-source'
import {ApiPagedResponse} from '@dev/shared-resource'
import {
UserDto,
Expand All @@ -22,7 +22,6 @@ import {
NotFoundException,
BadRequestException,
} from '@nestjs/common'
import {plainToClass} from 'class-transformer'

@ApiTags('account')
@Controller('account')
Expand All @@ -35,15 +34,15 @@ export class AccountResourceController {
return this.userFacade.find({options}).then(({meta, data}) => {
return {
meta,
data: data.map((item) => plainToClass(UserDto, item)),
data: data.map(castTo(UserDto)),
}
})
}

@Get(':id')
async findOne(@Param('id') id: string) {
try {
return await this.userFacade.findOne(id)
return await this.userFacade.findOne(id).then(castTo(UserDto))
} catch {
throw new NotFoundException('Usuário não existe')
}
Expand Down
11 changes: 2 additions & 9 deletions account/ui-auth/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "account/ui-auth/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "account/ui-auth/jest.config.ts"
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
Expand Down
11 changes: 2 additions & 9 deletions api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
},
"lint": {
"executor": "@nx/linter:eslint",
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["api/**/*.ts"]
Expand All @@ -56,14 +56,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "api/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
"jestConfig": "api/jest.config.ts"
}
}
},
Expand Down
Loading

0 comments on commit 19c929d

Please sign in to comment.