Skip to content

Commit

Permalink
feat: change roles
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Sep 29, 2024
1 parent eb7ee2f commit eeeac04
Show file tree
Hide file tree
Showing 67 changed files with 932 additions and 104 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ jobs:
with:
version: 9



# This enables task distribution via Nx Cloud
# Run this command as early as possible, before dependencies are installed
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
- run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build"


# Cache node_modules
- uses: actions/setup-node@v4
with:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ pnpm dev

## Para commits

Antes de escrever seu commit, execute lint, test e build dos projetos afetados pela sua alteração.

```sh
pnpm affected
```

Os commits podem ser feitos em português, mas use inglês para termos técnicos, não tente traduzi-los quando eles são conhecidos e usados em inglês.

```sh
Expand Down
9 changes: 9 additions & 0 deletions apps/devmx/public/photos/default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/devmx/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use '@angular/cdk/overlay-prebuilt.css';
// @use '@angular/cdk/overlay-prebuilt.css';
@use '@angular/material' as mat;
// @use '/node_modules/@angular/material/core/theming/color-api-backwards-compatibility' as mat;
@use './scss/theme' as theme;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"scripts": {
"dev": "nx run-many -t serve --projects=server,devmx --configuration=development",
"affected": "nx affected -t lint test build --parallel=10",
"cmt": "czg"
},
"private": true,
Expand Down
2 changes: 2 additions & 0 deletions packages/account/data-access/src/lib/account.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
provideFindAccountByUsernameUseCase,
provideCityService,
provideFindAccountsUseCase,
provideChangeRolesUseCase,
} from './providers';

export function provideAccount() {
Expand All @@ -36,6 +37,7 @@ export function provideAccount() {
provideUpdateAccountUseCase(),
provideRemoveAccountUseCase(),
provideChangePasswordUseCase(),
provideChangeRolesUseCase(),
provideUploadPhotoUseCase(),

provideAuthFacade(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ChangeRolesBy } from '@devmx/account-domain';
1 change: 1 addition & 0 deletions packages/account/data-access/src/lib/dtos/change-roles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ChangeRoles } from '@devmx/account-domain';
2 changes: 2 additions & 0 deletions packages/account/data-access/src/lib/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './change-password';
export * from './change-roles-by';
export * from './change-roles';
export * from './filter-account';
export * from './update-account';
7 changes: 7 additions & 0 deletions packages/account/data-access/src/lib/facades/account-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ interface AccountNavState {
export class AccountNavFacade extends State<AccountNavState> {
items$ = this.select((state) => Array.from(state.items));

#initialItems: NavItem[] = [];

constructor(items: NavItem[] = []) {
super({ items: new Set(items) });
this.#initialItems = items;
}

setItems(newItems: NavItem[]) {
Expand All @@ -31,4 +34,8 @@ export class AccountNavFacade extends State<AccountNavState> {

this.setState({ items });
}

reset() {
this.setItems(this.#initialItems);
}
}
14 changes: 13 additions & 1 deletion packages/account/data-access/src/lib/facades/account.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ChangePassword, UpdateAccount } from '@devmx/account-domain';
import {
ChangePassword,
ChangeRoles,
UpdateAccount,
} from '@devmx/account-domain';
import { State } from '@devmx/shared-data-access';
import { FilterAccount } from '../dtos';
import { take } from 'rxjs';
Expand All @@ -16,6 +20,7 @@ import {
UploadPhotoUseCase,
FindAccountByUsernameUseCase,
FindAccountsUseCase,
ChangeRolesUseCase,
} from '@devmx/account-domain/client';

interface AccountState {
Expand Down Expand Up @@ -43,6 +48,7 @@ export class AccountFacade extends State<AccountState> {
private updateAccountUseCase: UpdateAccountUseCase,
private removeAccountUseCase: RemoveAccountUseCase,
private changePasswordUseCase: ChangePasswordUseCase,
private changeRolesUseCase: ChangeRolesUseCase,
private uploadPhotoUseCase: UploadPhotoUseCase
) {
super({
Expand Down Expand Up @@ -132,6 +138,12 @@ export class AccountFacade extends State<AccountState> {
request$.pipe(take(1)).subscribe(() => this.loadOne(data.id));
}

changeRoles(data: ChangeRoles) {
const request$ = this.changeRolesUseCase.execute(data);

request$.pipe(take(1)).subscribe(() => this.loadOne(data.id));
}

uploadPhoto(photo: Blob) {
const request$ = this.uploadPhotoUseCase.execute(photo);

Expand Down
7 changes: 7 additions & 0 deletions packages/account/data-access/src/lib/facades/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ export class AuthFacade extends State<AuthState> {
clearAccessToken() {
localStorage.removeItem('accessToken');
}

signOut() {
const user = null;
const level = null;
this.setState({ user, level });
this.clearAccessToken();
}
}
4 changes: 4 additions & 0 deletions packages/account/data-access/src/lib/providers/facades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
UploadPhotoUseCase,
FindAccountByUsernameUseCase,
FindAccountsUseCase,
ChangeRolesUseCase,
} from '@devmx/account-domain/client';

export function provideAuthFacade() {
Expand Down Expand Up @@ -38,6 +39,7 @@ export function provideAccountFacade() {
updateAccount: UpdateAccountUseCase,
removeAccount: RemoveAccountUseCase,
changePassword: ChangePasswordUseCase,
changeRoles: ChangeRolesUseCase,
uploadPhoto: UploadPhotoUseCase
) {
return new AccountFacade(
Expand All @@ -48,6 +50,7 @@ export function provideAccountFacade() {
updateAccount,
removeAccount,
changePassword,
changeRoles,
uploadPhoto
);
},
Expand All @@ -59,6 +62,7 @@ export function provideAccountFacade() {
UpdateAccountUseCase,
RemoveAccountUseCase,
ChangePasswordUseCase,
ChangeRolesUseCase,
UploadPhotoUseCase,
],
};
Expand Down
5 changes: 5 additions & 0 deletions packages/account/data-access/src/lib/providers/use-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
UploadPhotoUseCase,
FindAccountByUsernameUseCase,
FindAccountsUseCase,
ChangeRolesUseCase,
} from '@devmx/account-domain/client';

export function provideSignInUseCase() {
Expand Down Expand Up @@ -57,6 +58,10 @@ export function provideChangePasswordUseCase() {
return createUseCaseProvider(ChangePasswordUseCase, [AccountService]);
}

export function provideChangeRolesUseCase() {
return createUseCaseProvider(ChangeRolesUseCase, [AccountService]);
}

export function provideUploadPhotoUseCase() {
return createUseCaseProvider(UploadPhotoUseCase, [AccountService]);
}
10 changes: 9 additions & 1 deletion packages/account/data-access/src/lib/services/account.impl.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ChangePassword, UpdateAccount } from '@devmx/account-domain';
import { AccountService } from '@devmx/account-domain/client';
import { Env } from '@devmx/shared-api-interfaces/client';
import { HttpClient } from '@devmx/shared-data-access';
import {
ChangeRoles,
UpdateAccount,
ChangePassword,
} from '@devmx/account-domain';
import {
Page,
AccountOut,
Expand Down Expand Up @@ -48,6 +52,10 @@ export class AccountServiceImpl implements AccountService {
return this.http.patch<AccountOut>(`${this.url}/password`, data);
}

changeRoles(id: string, data: ChangeRoles) {
return this.http.patch<AccountOut>(`${this.url}/${id}/roles`, data);
}

remove(id: string) {
return this.http.delete<AccountOut>(`${this.url}/${id}`);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/account/data-source/src/lib/dtos/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AccountRole, Gender } from '@devmx/shared-api-interfaces';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Exclude, Type } from 'class-transformer';
import { NameDto } from './name';
import { AccountRoleDto } from './account-role';

export class AccountDto {
@ApiProperty()
Expand Down Expand Up @@ -46,7 +47,8 @@ export class AccountDto {
@ApiPropertyOptional()
birthday?: string;

@Exclude()
@Type(() => AccountRoleDto)
@ApiProperty({ type: () => AccountRoleDto })
roles: AccountRole;

@ApiProperty()
Expand Down
10 changes: 5 additions & 5 deletions packages/account/data-source/src/lib/dtos/change-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { Type } from 'class-transformer';
export class ChangeRolesDto implements ChangeRoles {
id: string;

@IsObject()
@Type(() => AccountRoleDto)
@ApiProperty({ type: () => AccountRoleDto })
currentRoles: AccountRoleDto;
// @IsObject()
// @Type(() => AccountRoleDto)
// @ApiProperty({ type: () => AccountRoleDto })
// currentRoles: AccountRoleDto;

@IsObject()
@Type(() => AccountRoleDto)
@ApiProperty({ type: () => AccountRoleDto })
newRoles: AccountRoleDto;
roles: AccountRoleDto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ export class AccountsServiceImpl implements AccountsService {
async findOneBy(filter: FindFilterDto<Account>) {
const account = await this.accountModel.findOne(filter).exec();

if (!account) {
throw `Conta não encontrada`;
}

return account.toJSON();
return account ? account.toJSON() : null;
}

async update(id: string, data: Partial<UpdateAccountDto>) {
Expand Down
11 changes: 11 additions & 0 deletions packages/account/domain/src/__tests__/mocks/dtos/account-role.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const accountRole = {
member: false,
speaker: false,
donor: false,
neighbor: false,
leader: false,
staff: false,
fellow: false,
manager: false,
director: false,
};
38 changes: 38 additions & 0 deletions packages/account/domain/src/__tests__/mocks/dtos/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export const account = {
name: {
first: 'Guilherme',
last: 'Siquinelli',
},
username: 'guiseek',
password: '',
email: 'guilherme@devpr.org',
roles: {
member: true,
speaker: false,
neighbor: false,
donor: false,
leader: false,
staff: false,
fellow: false,
manager: false,
director: true,
},
gender: 'male',
photo: '9c14863726af550ff0666c128c32286a',
minibio: '',
birthday: '1986-12-29T02:00:00.000Z',
active: true,
city: {
id: '',
ibge: 4115200,
name: 'Maringá',
lat: -23.4205,
lng: -51.9333,
capital: false,
ibgeState: 41,
siafi: 7691,
ddd: 44,
timeZone: 'America/Sao_Paulo',
},
id: '66f706967d818c4004effb48',
};
21 changes: 21 additions & 0 deletions packages/account/domain/src/__tests__/mocks/dtos/auth-user.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const authUser = {
id: '66f706967d818c4004effb48',
name: {
first: 'Guilherme',
last: 'Siquinelli',
},
email: 'guilherme@devpr.org',
photo: '9c14863726af550ff0666c128c32286a',
roles: {
member: false,
speaker: false,
neighbor: false,
donor: false,
leader: false,
staff: false,
fellow: false,
manager: false,
director: false,
},
username: 'guiseek',
};
3 changes: 3 additions & 0 deletions packages/account/domain/src/__tests__/mocks/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './account-role';
export * from './account';
export * from './auth-user';
2 changes: 2 additions & 0 deletions packages/account/domain/src/__tests__/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './dtos';
export * from './services';
Loading

0 comments on commit eeeac04

Please sign in to comment.