Skip to content

Commit eeeac04

Browse files
committed
feat: change roles
1 parent eb7ee2f commit eeeac04

File tree

67 files changed

+932
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+932
-104
lines changed

.github/workflows/ci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,11 @@ jobs:
2222
with:
2323
version: 9
2424

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

32-
3330
# Cache node_modules
3431
- uses: actions/setup-node@v4
3532
with:

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pnpm dev
4949

5050
## Para commits
5151

52+
Antes de escrever seu commit, execute lint, test e build dos projetos afetados pela sua alteração.
53+
54+
```sh
55+
pnpm affected
56+
```
57+
5258
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.
5359

5460
```sh

apps/devmx/public/photos/default.svg

+9
Loading

apps/devmx/src/styles.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@use '@angular/cdk/overlay-prebuilt.css';
1+
// @use '@angular/cdk/overlay-prebuilt.css';
22
@use '@angular/material' as mat;
33
// @use '/node_modules/@angular/material/core/theming/color-api-backwards-compatibility' as mat;
44
@use './scss/theme' as theme;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"scripts": {
66
"dev": "nx run-many -t serve --projects=server,devmx --configuration=development",
7+
"affected": "nx affected -t lint test build --parallel=10",
78
"cmt": "czg"
89
},
910
"private": true,

packages/account/data-access/src/lib/account.providers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
provideFindAccountByUsernameUseCase,
1818
provideCityService,
1919
provideFindAccountsUseCase,
20+
provideChangeRolesUseCase,
2021
} from './providers';
2122

2223
export function provideAccount() {
@@ -36,6 +37,7 @@ export function provideAccount() {
3637
provideUpdateAccountUseCase(),
3738
provideRemoveAccountUseCase(),
3839
provideChangePasswordUseCase(),
40+
provideChangeRolesUseCase(),
3941
provideUploadPhotoUseCase(),
4042

4143
provideAuthFacade(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ChangeRolesBy } from '@devmx/account-domain';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { ChangeRoles } from '@devmx/account-domain';
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from './change-password';
2+
export * from './change-roles-by';
3+
export * from './change-roles';
24
export * from './filter-account';
35
export * from './update-account';

packages/account/data-access/src/lib/facades/account-nav.ts

+7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ interface AccountNavState {
88
export class AccountNavFacade extends State<AccountNavState> {
99
items$ = this.select((state) => Array.from(state.items));
1010

11+
#initialItems: NavItem[] = [];
12+
1113
constructor(items: NavItem[] = []) {
1214
super({ items: new Set(items) });
15+
this.#initialItems = items;
1316
}
1417

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

3235
this.setState({ items });
3336
}
37+
38+
reset() {
39+
this.setItems(this.#initialItems);
40+
}
3441
}

packages/account/data-access/src/lib/facades/account.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { ChangePassword, UpdateAccount } from '@devmx/account-domain';
1+
import {
2+
ChangePassword,
3+
ChangeRoles,
4+
UpdateAccount,
5+
} from '@devmx/account-domain';
26
import { State } from '@devmx/shared-data-access';
37
import { FilterAccount } from '../dtos';
48
import { take } from 'rxjs';
@@ -16,6 +20,7 @@ import {
1620
UploadPhotoUseCase,
1721
FindAccountByUsernameUseCase,
1822
FindAccountsUseCase,
23+
ChangeRolesUseCase,
1924
} from '@devmx/account-domain/client';
2025

2126
interface AccountState {
@@ -43,6 +48,7 @@ export class AccountFacade extends State<AccountState> {
4348
private updateAccountUseCase: UpdateAccountUseCase,
4449
private removeAccountUseCase: RemoveAccountUseCase,
4550
private changePasswordUseCase: ChangePasswordUseCase,
51+
private changeRolesUseCase: ChangeRolesUseCase,
4652
private uploadPhotoUseCase: UploadPhotoUseCase
4753
) {
4854
super({
@@ -132,6 +138,12 @@ export class AccountFacade extends State<AccountState> {
132138
request$.pipe(take(1)).subscribe(() => this.loadOne(data.id));
133139
}
134140

141+
changeRoles(data: ChangeRoles) {
142+
const request$ = this.changeRolesUseCase.execute(data);
143+
144+
request$.pipe(take(1)).subscribe(() => this.loadOne(data.id));
145+
}
146+
135147
uploadPhoto(photo: Blob) {
136148
const request$ = this.uploadPhotoUseCase.execute(photo);
137149

packages/account/data-access/src/lib/facades/auth.ts

+7
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,11 @@ export class AuthFacade extends State<AuthState> {
7575
clearAccessToken() {
7676
localStorage.removeItem('accessToken');
7777
}
78+
79+
signOut() {
80+
const user = null;
81+
const level = null;
82+
this.setState({ user, level });
83+
this.clearAccessToken();
84+
}
7885
}

packages/account/data-access/src/lib/providers/facades.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
UploadPhotoUseCase,
1212
FindAccountByUsernameUseCase,
1313
FindAccountsUseCase,
14+
ChangeRolesUseCase,
1415
} from '@devmx/account-domain/client';
1516

1617
export function provideAuthFacade() {
@@ -38,6 +39,7 @@ export function provideAccountFacade() {
3839
updateAccount: UpdateAccountUseCase,
3940
removeAccount: RemoveAccountUseCase,
4041
changePassword: ChangePasswordUseCase,
42+
changeRoles: ChangeRolesUseCase,
4143
uploadPhoto: UploadPhotoUseCase
4244
) {
4345
return new AccountFacade(
@@ -48,6 +50,7 @@ export function provideAccountFacade() {
4850
updateAccount,
4951
removeAccount,
5052
changePassword,
53+
changeRoles,
5154
uploadPhoto
5255
);
5356
},
@@ -59,6 +62,7 @@ export function provideAccountFacade() {
5962
UpdateAccountUseCase,
6063
RemoveAccountUseCase,
6164
ChangePasswordUseCase,
65+
ChangeRolesUseCase,
6266
UploadPhotoUseCase,
6367
],
6468
};

packages/account/data-access/src/lib/providers/use-cases.ts

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
UploadPhotoUseCase,
1414
FindAccountByUsernameUseCase,
1515
FindAccountsUseCase,
16+
ChangeRolesUseCase,
1617
} from '@devmx/account-domain/client';
1718

1819
export function provideSignInUseCase() {
@@ -57,6 +58,10 @@ export function provideChangePasswordUseCase() {
5758
return createUseCaseProvider(ChangePasswordUseCase, [AccountService]);
5859
}
5960

61+
export function provideChangeRolesUseCase() {
62+
return createUseCaseProvider(ChangeRolesUseCase, [AccountService]);
63+
}
64+
6065
export function provideUploadPhotoUseCase() {
6166
return createUseCaseProvider(UploadPhotoUseCase, [AccountService]);
6267
}

packages/account/data-access/src/lib/services/account.impl.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { ChangePassword, UpdateAccount } from '@devmx/account-domain';
21
import { AccountService } from '@devmx/account-domain/client';
32
import { Env } from '@devmx/shared-api-interfaces/client';
43
import { HttpClient } from '@devmx/shared-data-access';
4+
import {
5+
ChangeRoles,
6+
UpdateAccount,
7+
ChangePassword,
8+
} from '@devmx/account-domain';
59
import {
610
Page,
711
AccountOut,
@@ -48,6 +52,10 @@ export class AccountServiceImpl implements AccountService {
4852
return this.http.patch<AccountOut>(`${this.url}/password`, data);
4953
}
5054

55+
changeRoles(id: string, data: ChangeRoles) {
56+
return this.http.patch<AccountOut>(`${this.url}/${id}/roles`, data);
57+
}
58+
5159
remove(id: string) {
5260
return this.http.delete<AccountOut>(`${this.url}/${id}`);
5361
}

packages/account/data-source/src/lib/dtos/account.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AccountRole, Gender } from '@devmx/shared-api-interfaces';
22
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
33
import { Exclude, Type } from 'class-transformer';
44
import { NameDto } from './name';
5+
import { AccountRoleDto } from './account-role';
56

67
export class AccountDto {
78
@ApiProperty()
@@ -46,7 +47,8 @@ export class AccountDto {
4647
@ApiPropertyOptional()
4748
birthday?: string;
4849

49-
@Exclude()
50+
@Type(() => AccountRoleDto)
51+
@ApiProperty({ type: () => AccountRoleDto })
5052
roles: AccountRole;
5153

5254
@ApiProperty()

packages/account/data-source/src/lib/dtos/change-roles.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { Type } from 'class-transformer';
77
export class ChangeRolesDto implements ChangeRoles {
88
id: string;
99

10-
@IsObject()
11-
@Type(() => AccountRoleDto)
12-
@ApiProperty({ type: () => AccountRoleDto })
13-
currentRoles: AccountRoleDto;
10+
// @IsObject()
11+
// @Type(() => AccountRoleDto)
12+
// @ApiProperty({ type: () => AccountRoleDto })
13+
// currentRoles: AccountRoleDto;
1414

1515
@IsObject()
1616
@Type(() => AccountRoleDto)
1717
@ApiProperty({ type: () => AccountRoleDto })
18-
newRoles: AccountRoleDto;
18+
roles: AccountRoleDto;
1919
}

packages/account/data-source/src/lib/services/accounts.impl.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ export class AccountsServiceImpl implements AccountsService {
4444
async findOneBy(filter: FindFilterDto<Account>) {
4545
const account = await this.accountModel.findOne(filter).exec();
4646

47-
if (!account) {
48-
throw `Conta não encontrada`;
49-
}
50-
51-
return account.toJSON();
47+
return account ? account.toJSON() : null;
5248
}
5349

5450
async update(id: string, data: Partial<UpdateAccountDto>) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const accountRole = {
2+
member: false,
3+
speaker: false,
4+
donor: false,
5+
neighbor: false,
6+
leader: false,
7+
staff: false,
8+
fellow: false,
9+
manager: false,
10+
director: false,
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export const account = {
2+
name: {
3+
first: 'Guilherme',
4+
last: 'Siquinelli',
5+
},
6+
username: 'guiseek',
7+
password: '',
8+
9+
roles: {
10+
member: true,
11+
speaker: false,
12+
neighbor: false,
13+
donor: false,
14+
leader: false,
15+
staff: false,
16+
fellow: false,
17+
manager: false,
18+
director: true,
19+
},
20+
gender: 'male',
21+
photo: '9c14863726af550ff0666c128c32286a',
22+
minibio: '',
23+
birthday: '1986-12-29T02:00:00.000Z',
24+
active: true,
25+
city: {
26+
id: '',
27+
ibge: 4115200,
28+
name: 'Maringá',
29+
lat: -23.4205,
30+
lng: -51.9333,
31+
capital: false,
32+
ibgeState: 41,
33+
siafi: 7691,
34+
ddd: 44,
35+
timeZone: 'America/Sao_Paulo',
36+
},
37+
id: '66f706967d818c4004effb48',
38+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const authUser = {
2+
id: '66f706967d818c4004effb48',
3+
name: {
4+
first: 'Guilherme',
5+
last: 'Siquinelli',
6+
},
7+
8+
photo: '9c14863726af550ff0666c128c32286a',
9+
roles: {
10+
member: false,
11+
speaker: false,
12+
neighbor: false,
13+
donor: false,
14+
leader: false,
15+
staff: false,
16+
fellow: false,
17+
manager: false,
18+
director: false,
19+
},
20+
username: 'guiseek',
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './account-role';
2+
export * from './account';
3+
export * from './auth-user';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './dtos';
2+
export * from './services';

0 commit comments

Comments
 (0)