-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
298 changed files
with
21,912 additions
and
9,679 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.json"], | ||
"parser": "jsonc-eslint-parser", | ||
"rules": { | ||
"@nx/dependency-checks": "error" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# account-data-access | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build account-data-access` to build the library. | ||
|
||
## Running unit tests | ||
|
||
Run `nx test account-data-access` to execute the unit tests via [Jest](https://jestjs.io). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'account-data-access', | ||
preset: '../../jest.preset.js', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', {tsconfig: '<rootDir>/tsconfig.spec.json'}], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/account/data-access', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@dev/account-data-access", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"tslib": "^2.3.0", | ||
"@dev/account-domain": "*", | ||
"@dev/shared-data-access": "*", | ||
"rxjs": "^7.8.0", | ||
"@dev/shared-util-data": "*" | ||
}, | ||
"type": "commonjs", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "account-data-access", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "account/data-access/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": ["{options.outputPath}"], | ||
"options": { | ||
"outputPath": "dist/account/data-access", | ||
"main": "account/data-access/src/index.ts", | ||
"tsConfig": "account/data-access/tsconfig.lib.json", | ||
"assets": ["account/data-access/*.md"] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": [ | ||
"account/data-access/**/*.ts", | ||
"account/data-access/package.json" | ||
] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "account/data-access/jest.config.ts", | ||
"passWithNoTests": true | ||
}, | ||
"configurations": { | ||
"ci": { | ||
"ci": true, | ||
"codeCoverage": true | ||
} | ||
} | ||
} | ||
}, | ||
"tags": ["type:data-access", "scope:account", "side:client"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './public-api' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {AuthService, AuthUser, CreateUser, SignIn} from '@dev/account-domain' | ||
import {Store} from '@dev/shared-data-access' | ||
import {switchMap, take, tap} from 'rxjs' | ||
|
||
interface AuthState { | ||
authUser: AuthUser | null | ||
warning: string | null | ||
loading: boolean | ||
} | ||
export class AuthFacade extends Store<AuthState> { | ||
authUser$ = this.select((state) => state.authUser) | ||
warning$ = this.select((state) => state.warning) | ||
loading$ = this.select((state) => state.loading) | ||
|
||
get accessToken() { | ||
return this.authService.accessToken | ||
} | ||
|
||
constructor(private authService: AuthService) { | ||
super({authUser: null, warning: null, loading: false}) | ||
} | ||
|
||
login<T extends SignIn>(signIn: T) { | ||
this.setState({loading: true}) | ||
const authUser$ = this.authService.login(signIn).pipe( | ||
switchMap(() => this.authService.me()), | ||
take(1) | ||
) | ||
|
||
authUser$.subscribe((authUser) => this.setState({authUser, loading: false})) | ||
} | ||
|
||
me() { | ||
return this.authService.me().pipe( | ||
tap((authUser) => this.setState({authUser})), | ||
take(1) | ||
) | ||
} | ||
|
||
register(createUser: CreateUser) { | ||
this.setState({loading: true}) | ||
const createUser$ = this.authService.register(createUser).pipe(take(1)) | ||
|
||
createUser$.subscribe((authUser) => | ||
this.setState({authUser, loading: false}) | ||
) | ||
} | ||
|
||
logout() { | ||
this.authService.accessToken = null | ||
this.setState({authUser: null}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {Facade} from '@dev/shared-util-data' | ||
import {Group} from '@dev/account-domain' | ||
|
||
export class GroupFacade extends Facade<Group> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './auth.facade' | ||
export * from './group.facade' | ||
export * from './user.facade' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {UpdatePassword, User, UserService} from '@dev/account-domain' | ||
import {Facade} from '@dev/shared-util-data' | ||
import {catchError} from 'rxjs' | ||
|
||
export class UserFacade extends Facade<User, UserService> { | ||
constructor(service: UserService) { | ||
super(service) | ||
} | ||
|
||
updatePassword(value: UpdatePassword) { | ||
const update$ = this.service.updatePassword(value) | ||
update$.pipe(catchError(this.handleError)).subscribe((selected) => { | ||
this.setState({selected}) | ||
this.findOne(value.id) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {CreateGroup} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {CreateUser} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {Group} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export * from './create-group' | ||
export * from './create-user' | ||
export * from './group' | ||
export * from './sign-in' | ||
export * from './update-group' | ||
export * from './update-password' | ||
export * from './update-user' | ||
export * from './user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {SignIn} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {UpdateGroup} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {UpdatePassword} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {UpdateUser} from '@dev/account-domain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {User} from '@dev/account-domain' |
36 changes: 36 additions & 0 deletions
36
account/data-access/src/lib/infrastructure/auth.service.impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { | ||
SignIn, | ||
AuthUser, | ||
AccessToken, | ||
AuthService, | ||
CreateUser, | ||
} from '@dev/account-domain' | ||
import {Http} from '@dev/shared-data-access' | ||
import {take, tap} from 'rxjs' | ||
|
||
export class AuthServiceImpl implements AuthService { | ||
get accessToken() { | ||
return localStorage.getItem('accessToken') | ||
} | ||
set accessToken(value) { | ||
if (value) localStorage.setItem('accessToken', value) | ||
else localStorage.removeItem('accessToken') | ||
} | ||
|
||
constructor(private readonly http: Http, readonly url: string) {} | ||
|
||
login(value: SignIn) { | ||
return this.http.post<AccessToken>(`${this.url}/login`, value).pipe( | ||
tap(({accessToken}) => (this.accessToken = accessToken)), | ||
take(1) | ||
) | ||
} | ||
|
||
register(value: CreateUser) { | ||
return this.http.post<AuthUser>(`${this.url}/register`, value).pipe(take(1)) | ||
} | ||
|
||
me() { | ||
return this.http.get<AuthUser>(`${this.url}/me`).pipe(take(1)) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
account/data-access/src/lib/infrastructure/auth.service.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {AuthService, CreateUser, SignIn} from '@dev/account-domain' | ||
import {of} from 'rxjs' | ||
|
||
const MOCK_USER = { | ||
name: 'mock', | ||
username: 'username', | ||
email: '[email protected]', | ||
id: 'mo-ck-id', | ||
} | ||
const MOCK_AUTH = `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1YjU2YTlkNy0wMWMwLTQ4NjEtYmY0MC1jMzMwNjMzY2E3MWQiLCJuYW1lIjoiR3VpbGhlcm1lIiwidXNlcm5hbWUiOiJndWlzZWVrIiwiZW1haWwiOiJlbWFpbEBndWlzZWVrLmRldiIsImlhdCI6MTY5NjEzMzMzMywiZXhwIjoxNjk2MjE5NzMzfQ.SyeK25DlNIJNl3eu8Jabjd0XaQWm-j_WSB8f5MoYEGE` | ||
|
||
export class AuthServiceMock implements AuthService { | ||
get accessToken() { | ||
return localStorage.getItem('accessToken') | ||
} | ||
set accessToken(value) { | ||
if (value) localStorage.setItem('accessToken', value) | ||
else localStorage.removeItem('accessToken') | ||
} | ||
|
||
login(value: SignIn) { | ||
console.log(`login: `, value) | ||
return of({accessToken: MOCK_AUTH}) | ||
} | ||
register(value: CreateUser) { | ||
console.log(`register: `, value) | ||
return of(MOCK_USER) | ||
} | ||
|
||
me() { | ||
return of(MOCK_USER) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
account/data-access/src/lib/infrastructure/group.service.impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {Group, GroupService} from '@dev/account-domain' | ||
import {BaseService} from '@dev/shared-data-access' | ||
|
||
export class GroupServiceImpl | ||
extends BaseService<Group> | ||
implements GroupService {} |
19 changes: 19 additions & 0 deletions
19
account/data-access/src/lib/infrastructure/group.service.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Group, GroupService} from '@dev/account-domain' | ||
import {MockService} from '@dev/shared-data-access' | ||
import {of} from 'rxjs' | ||
|
||
export class GroupServiceMock | ||
extends MockService<Group> | ||
implements GroupService | ||
{ | ||
create(value: Partial<Group>) { | ||
const entity = { | ||
...value, | ||
id: crypto.randomUUID(), | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
} as Group | ||
this.collection.push(entity) | ||
return of(entity) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './auth.service.impl' | ||
export * from './auth.service.mock' | ||
export * from './group.service.impl' | ||
export * from './group.service.mock' | ||
export * from './user.service.impl' | ||
export * from './user.service.mock' |
9 changes: 9 additions & 0 deletions
9
account/data-access/src/lib/infrastructure/user.service.impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {UpdatePassword, User, UserService} from '@dev/account-domain' | ||
import {BaseService} from '@dev/shared-data-access' | ||
import {Observable} from 'rxjs' | ||
|
||
export class UserServiceImpl extends BaseService<User> implements UserService { | ||
updatePassword(value: UpdatePassword): Observable<User> { | ||
return this.http.put(`${this.url}/password`, value) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
account/data-access/src/lib/infrastructure/user.service.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {UpdatePassword, User, UserService} from '@dev/account-domain' | ||
import {MockService} from '@dev/shared-data-access' | ||
import {of} from 'rxjs' | ||
|
||
export class UserServiceMock extends MockService<User> implements UserService { | ||
updatePassword(value: UpdatePassword) { | ||
return this.findOne(value.id) | ||
} | ||
|
||
create(value: Partial<User>) { | ||
const entity = { | ||
...value, | ||
id: crypto.randomUUID(), | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
} as User | ||
this.collection.push(entity) | ||
return of(entity) | ||
} | ||
} |
Oops, something went wrong.