Skip to content

Commit eb7ee2f

Browse files
committed
feat: feature admin
1 parent ef5acbc commit eb7ee2f

Some content is hidden

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

62 files changed

+678
-50
lines changed

.github/workflows/ci.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,29 @@ jobs:
1717
- uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20-
20+
2121
- uses: pnpm/action-setup@v4
2222
with:
2323
version: 9
24-
25-
24+
25+
2626

2727
# This enables task distribution via Nx Cloud
2828
# Run this command as early as possible, before dependencies are installed
2929
# Learn more at https://nx.dev/ci/reference/nx-cloud-cli#npx-nxcloud-startcirun
3030
- run: pnpm dlx nx-cloud start-ci-run --distribute-on="3 linux-medium-js" --stop-agents-after="build"
31-
32-
31+
32+
3333
# Cache node_modules
3434
- uses: actions/setup-node@v4
3535
with:
3636
node-version: 20
3737
cache: 'pnpm'
38-
38+
3939
- run: pnpm install --frozen-lockfile
4040
- uses: nrwl/nx-set-shas@v4
4141

4242
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
4343
# - run: pnpm exec nx-cloud record -- echo Hello World
4444
# Nx Affected runs only tasks affected by the changes in this PR/commit. Learn more: https://nx.dev/ci/features/affected
45-
- run: pnpm exec nx affected -t lint test build
45+
- run: pnpm exec nx affected -t lint test build --parallel=10

packages/account/data-access/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"@devmx/account-domain": "0.0.1",
77
"@devmx/shared-data-access": "0.0.1",
88
"rxjs": "^7.8.0",
9-
"@devmx/shared-api-interfaces": "0.0.1"
9+
"@devmx/shared-api-interfaces": "0.0.1",
10+
"@devmx/shared-util-data": "0.0.1"
1011
},
1112
"type": "commonjs",
1213
"main": "./src/index.js",

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

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
provideUploadPhotoUseCase,
1717
provideFindAccountByUsernameUseCase,
1818
provideCityService,
19+
provideFindAccountsUseCase,
1920
} from './providers';
2021

2122
export function provideAccount() {
@@ -28,6 +29,7 @@ export function provideAccount() {
2829
provideSignUpUseCase(),
2930
provideLoadAuthUserUseCase(),
3031

32+
provideFindAccountsUseCase(),
3133
provideFindAccountByIDUseCase(),
3234
provideFindAccountByUsernameUseCase(),
3335
provideFindAccountPresentationsUseCase(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface FilterAccount {
2+
name: string
3+
username: string;
4+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './change-password';
2+
export * from './filter-account';
23
export * from './update-account';

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

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChangePassword, UpdateAccount } from '@devmx/account-domain';
22
import { State } from '@devmx/shared-data-access';
3+
import { FilterAccount } from '../dtos';
34
import { take } from 'rxjs';
45
import {
56
Page,
@@ -14,13 +15,15 @@ import {
1415
ChangePasswordUseCase,
1516
UploadPhotoUseCase,
1617
FindAccountByUsernameUseCase,
18+
FindAccountsUseCase,
1719
} from '@devmx/account-domain/client';
1820

1921
interface AccountState {
2022
presentations: Page<PresentationOut>;
2123
accounts: Page<AccountOut>;
2224
account: AccountOut | null;
2325
username: boolean | null;
26+
filter: FilterAccount;
2427
}
2528

2629
export class AccountFacade extends State<AccountState> {
@@ -33,6 +36,7 @@ export class AccountFacade extends State<AccountState> {
3336
username$ = this.select((state) => state.username);
3437

3538
constructor(
39+
private findAccountsUseCase: FindAccountsUseCase,
3640
private findAccountByIDUseCase: FindAccountByIDUseCase,
3741
private findAccountByUsernameUseCase: FindAccountByUsernameUseCase,
3842
private findAccountPresentationsUseCase: FindAccountPresentationsUseCase,
@@ -44,11 +48,33 @@ export class AccountFacade extends State<AccountState> {
4448
super({
4549
accounts: { data: [], items: 0, pages: 0 },
4650
presentations: { data: [], items: 0, pages: 0 },
51+
filter: { name: '', username: '' },
4752
account: null,
4853
username: null,
4954
});
5055
}
5156

57+
setFilter(filter: FilterAccount) {
58+
this.setState({ filter });
59+
}
60+
61+
clearFilter() {
62+
this.setState({ filter: { name: '', username: '' } });
63+
}
64+
65+
load(page = 0, size = 10) {
66+
const filter = this.state.filter;
67+
const params = { filter, page, size };
68+
69+
const request$ = this.findAccountsUseCase.execute(params);
70+
71+
const onAccounts = (accounts: Page<AccountOut>) => {
72+
this.setState({ accounts });
73+
};
74+
75+
request$.pipe(take(1)).subscribe(onAccounts);
76+
}
77+
5278
loadOne(id: string) {
5379
const request$ = this.findAccountByIDUseCase.execute(id);
5480

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

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ChangePasswordUseCase,
1111
UploadPhotoUseCase,
1212
FindAccountByUsernameUseCase,
13+
FindAccountsUseCase,
1314
} from '@devmx/account-domain/client';
1415

1516
export function provideAuthFacade() {
@@ -30,6 +31,7 @@ export function provideAccountFacade() {
3031
return {
3132
provide: AccountFacade,
3233
useFactory(
34+
findAccounts: FindAccountsUseCase,
3335
findAccountByID: FindAccountByIDUseCase,
3436
findAccountUsernameID: FindAccountByUsernameUseCase,
3537
findAccountPresentations: FindAccountPresentationsUseCase,
@@ -39,6 +41,7 @@ export function provideAccountFacade() {
3941
uploadPhoto: UploadPhotoUseCase
4042
) {
4143
return new AccountFacade(
44+
findAccounts,
4245
findAccountByID,
4346
findAccountUsernameID,
4447
findAccountPresentations,
@@ -49,6 +52,7 @@ export function provideAccountFacade() {
4952
);
5053
},
5154
deps: [
55+
FindAccountsUseCase,
5256
FindAccountByIDUseCase,
5357
FindAccountByUsernameUseCase,
5458
FindAccountPresentationsUseCase,

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

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ChangePasswordUseCase,
1313
UploadPhotoUseCase,
1414
FindAccountByUsernameUseCase,
15+
FindAccountsUseCase,
1516
} from '@devmx/account-domain/client';
1617

1718
export function provideSignInUseCase() {
@@ -26,6 +27,10 @@ export function provideLoadAuthUserUseCase() {
2627
return createUseCaseProvider(LoadAuthUserUseCase, [AuthService]);
2728
}
2829

30+
export function provideFindAccountsUseCase() {
31+
return createUseCaseProvider(FindAccountsUseCase, [AccountService]);
32+
}
33+
2934
export function provideFindAccountByIDUseCase() {
3035
return createUseCaseProvider(FindAccountByIDUseCase, [AccountService]);
3136
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { QueryFilterDto, QueryParamsDto } from '@devmx/shared-data-source';
1+
import { FindFilterDto, FindParamsDto } from '@devmx/shared-data-source';
22
import { AccountsService } from '@devmx/account-domain/server';
33
import { Account } from '@devmx/shared-api-interfaces';
44
import { SignUpDto, UpdateAccountDto } from '../dtos';
@@ -12,11 +12,12 @@ export class AccountsServiceImpl implements AccountsService {
1212
return createdAccount.save();
1313
}
1414

15-
async find(params: QueryParamsDto<Account>) {
15+
async find(params: FindParamsDto<Account>) {
1616
const { page = 0, size = 10, filter } = params;
1717

1818
const skip = page * size;
1919
const where = { ...filter };
20+
2021
const accounts = await this.accountModel
2122
.find(where)
2223
.skip(skip)
@@ -40,7 +41,7 @@ export class AccountsServiceImpl implements AccountsService {
4041
return account.toJSON();
4142
}
4243

43-
async findOneBy(filter: QueryFilterDto<Account>) {
44+
async findOneBy(filter: FindFilterDto<Account>) {
4445
const account = await this.accountModel.findOne(filter).exec();
4546

4647
if (!account) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createQueryParams } from '@devmx/shared-util-data';
2+
import { AccountService } from '../services';
3+
import {
4+
Page,
5+
Account,
6+
UseCase,
7+
AccountOut,
8+
QueryParams,
9+
} from '@devmx/shared-api-interfaces';
10+
11+
export class FindAccountsUseCase
12+
implements UseCase<QueryParams<Account>, Page<AccountOut>>
13+
{
14+
constructor(private accountService: AccountService) {}
15+
16+
execute(params: QueryParams<Account>) {
17+
return this.accountService.find(createQueryParams(params));
18+
}
19+
}

packages/account/domain/src/client/use-cases/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './change-password';
22
export * from './find-account-by-id';
33
export * from './find-account-by-username';
44
export * from './find-account-presentations';
5+
export * from './find-accounts';
56
export * from './load-auth-user';
67
export * from './remove-account';
78
export * from './sign-in';

packages/account/domain/src/server/services/accounts.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import {
33
Page,
44
Account,
55
Creatable,
6-
QueryFilter,
7-
QueryParams,
6+
FindFilter,
7+
FindParams,
88
} from '@devmx/shared-api-interfaces';
99

1010
// prettier-ignore
1111
export abstract class AccountsService {
1212
abstract create(data: Creatable<Account>): Promise<Account>;
1313

14-
abstract find(params: QueryParams<Account>): Promise<Page<Account>>;
14+
abstract find(params: FindParams<Account>): Promise<Page<Account>>;
1515

1616
abstract findOne(id: string): Promise<Account | null>;
1717

18-
abstract findOneBy(filter: QueryFilter<Account>): Promise<Account | null>;
18+
abstract findOneBy(filter: FindFilter<Account>): Promise<Account | null>;
1919

2020
abstract update(id: string, data: Partial<UpdateAccount>): Promise<Account | null>;
2121

packages/account/domain/src/server/use-cases/find-accounts.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
Account,
55
UseCase,
66
QueryParams,
7+
FindFilter,
8+
FindParams,
79
} from '@devmx/shared-api-interfaces';
810

911
export class FindAccountsUseCase
@@ -12,6 +14,28 @@ export class FindAccountsUseCase
1214
constructor(private accountsService: AccountsService) {}
1315

1416
async execute(params: QueryParams<Account>) {
15-
return this.accountsService.find(params);
17+
const filter: FindFilter<Account> = {};
18+
19+
if (params.filter) {
20+
if (params.filter.name) {
21+
filter['name.first'] = new RegExp(params.filter.name.toString(), 'i');
22+
} else {
23+
delete params.filter.name
24+
}
25+
26+
if (params.filter.username) {
27+
filter.username = new RegExp(params.filter.username, 'i');
28+
} else {
29+
delete params.filter.username;
30+
}
31+
}
32+
33+
const findParams: FindParams<Account> = {
34+
page: params.page,
35+
size: params.size,
36+
filter,
37+
};
38+
39+
return this.accountsService.find(findParams);
1640
}
1741
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"extends": ["../../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": [
8+
"plugin:@nx/angular",
9+
"plugin:@angular-eslint/template/process-inline-templates"
10+
],
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "devmx",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "devmx",
25+
"style": "kebab-case"
26+
}
27+
],
28+
"@angular-eslint/component-class-suffix": [
29+
"error",
30+
{
31+
"suffixes": ["Component", "Container"]
32+
}
33+
]
34+
}
35+
},
36+
{
37+
"files": ["*.html"],
38+
"extends": ["plugin:@nx/angular-template"],
39+
"rules": {}
40+
}
41+
]
42+
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# account-feature-admin
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test account-feature-admin` to execute the unit tests.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'account-feature-admin',
4+
preset: '../../../jest.preset.js',
5+
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
6+
coverageDirectory: '../../../coverage/packages/account/feature-admin',
7+
transform: {
8+
'^.+\\.(ts|mjs|js|html)$': [
9+
'jest-preset-angular',
10+
{
11+
tsconfig: '<rootDir>/tsconfig.spec.json',
12+
stringifyContentPathRegex: '\\.(html|svg)$',
13+
},
14+
],
15+
},
16+
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
17+
snapshotSerializers: [
18+
'jest-preset-angular/build/serializers/no-ng-attributes',
19+
'jest-preset-angular/build/serializers/ng-snapshot',
20+
'jest-preset-angular/build/serializers/html-comment',
21+
],
22+
};

0 commit comments

Comments
 (0)