-
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
250 changed files
with
5,015 additions
and
63 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,10 @@ | ||
{ | ||
"name": "@dev/account-data-access", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
}, | ||
"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)) | ||
} | ||
} |
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,5 @@ | ||
export * from './auth.service.impl' | ||
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) | ||
} | ||
} |
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,29 @@ | ||
import {AuthService} from '@dev/account-domain' | ||
import {AuthServiceImpl} from '../infrastructure' | ||
import {Http} from '@dev/shared-data-access' | ||
import {AuthFacade} from '../application' | ||
|
||
export function getAuthService() { | ||
return AuthService | ||
} | ||
|
||
export function provideAuthService(url: string) { | ||
return { | ||
provide: getAuthService(), | ||
useFactory(http: Http) { | ||
return new AuthServiceImpl(http, url) | ||
}, | ||
deps: [Http], | ||
} | ||
} | ||
|
||
export function provideAuthFacade() { | ||
return { | ||
provide: AuthFacade, | ||
deps: [getAuthService()], | ||
} | ||
} | ||
|
||
export function provideAuth(url: string) { | ||
return [provideAuthService(url), provideAuthFacade()] | ||
} |
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,37 @@ | ||
import {GroupServiceImpl, GroupServiceMock} from '../infrastructure' | ||
import {Http, provideServiceMock} from '@dev/shared-data-access' | ||
import {Group, GroupService} from '@dev/account-domain' | ||
import {GroupFacade} from '../application' | ||
|
||
export function provideGroupService(api: string) { | ||
return { | ||
provide: GroupService, | ||
useFactory(http: Http) { | ||
return new GroupServiceImpl(http, api) | ||
}, | ||
deps: [Http], | ||
} | ||
} | ||
|
||
export function provideGroupServiceMock(collection: Group[] = []) { | ||
return provideServiceMock(GroupService, GroupServiceMock, collection) | ||
} | ||
|
||
export function provideGroupFacade() { | ||
return { | ||
provide: GroupFacade, | ||
deps: [GroupService], | ||
} | ||
} | ||
|
||
export function provideGroup(production = false, api: string | Group[] = []) { | ||
const providers = [] | ||
providers.push( | ||
production | ||
? provideGroupService(api as string) | ||
: provideGroupServiceMock(api as Group[]) | ||
) | ||
|
||
providers.push(provideGroupFacade()) | ||
return providers | ||
} |
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' | ||
export * from './group' | ||
export * from './user' |
Oops, something went wrong.