-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mirko Mollik <[email protected]>
- Loading branch information
Showing
51 changed files
with
741 additions
and
124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
{ | ||
"files.eol": "\n", | ||
"cSpell.words": ["keycloak", "sphereon"] | ||
"cSpell.words": ["keycloak", "sphereon"], | ||
"sqltools.connections": [ | ||
{ | ||
"previewLimit": 50, | ||
"server": "localhost", | ||
"port": 5432, | ||
"driver": "PostgreSQL", | ||
"database": "nestjs", | ||
"username": "csalkfenvcda", | ||
"password": "hwafkjhea", | ||
"name": "Wallet-DB" | ||
} | ||
] | ||
} |
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,50 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Column, CreateDateColumn, Entity, PrimaryColumn } from 'typeorm'; | ||
|
||
type HistoryStatus = 'pending' | 'accepted' | 'declined'; | ||
|
||
@Entity() | ||
export class History { | ||
/** | ||
* Unique ID of the history entry | ||
*/ | ||
@PrimaryColumn({ primary: true }) | ||
id: string; | ||
|
||
/** | ||
* The user that owns the key | ||
*/ | ||
@Column({ primary: true }) | ||
user: string; | ||
|
||
/** | ||
* Values | ||
*/ | ||
@Column() | ||
value: string; | ||
|
||
/** | ||
* Relying party | ||
*/ | ||
@Column() | ||
relyingParty: string; | ||
|
||
/** | ||
* | ||
*/ | ||
@Column() | ||
relyingPartyLogo: string; | ||
|
||
/** | ||
* Status of the history entry | ||
*/ | ||
@ApiProperty({ type: 'string', enum: ['pending', 'accepted', 'declined'] }) | ||
@Column() | ||
status: HistoryStatus; | ||
|
||
/** | ||
* Date of creation | ||
*/ | ||
@CreateDateColumn() | ||
created_at: Date; | ||
} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { HistoryController } from './history.controller'; | ||
|
||
describe('HistoryController', () => { | ||
let controller: HistoryController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [HistoryController], | ||
}).compile(); | ||
|
||
controller = module.get<HistoryController>(HistoryController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
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 @@ | ||
import { Controller, Get, Param, UseGuards } from '@nestjs/common'; | ||
import { ApiOAuth2, ApiOperation, ApiTags } from '@nestjs/swagger'; | ||
import { AuthGuard, AuthenticatedUser } from 'nest-keycloak-connect'; | ||
import { HistoryService } from './history.service'; | ||
import { KeycloakUser } from 'src/auth/user'; | ||
|
||
@UseGuards(AuthGuard) | ||
@ApiOAuth2([]) | ||
@ApiTags('history') | ||
@Controller('history') | ||
export class HistoryController { | ||
constructor(private historyService: HistoryService) {} | ||
|
||
@ApiOperation({ summary: 'get all elements' }) | ||
@Get() | ||
all(@AuthenticatedUser() user: KeycloakUser) { | ||
return this.historyService.all(user.sub); | ||
} | ||
|
||
@ApiOperation({ summary: 'get one element' }) | ||
@Get(':id') | ||
getOne(@AuthenticatedUser() user: KeycloakUser, @Param('id') id: string) { | ||
return this.historyService.getOne(id, user.sub); | ||
} | ||
} |
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,13 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { HistoryController } from './history.controller'; | ||
import { HistoryService } from './history.service'; | ||
import { History } from './entities/history.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([History])], | ||
controllers: [HistoryController], | ||
providers: [HistoryService], | ||
exports: [HistoryService], | ||
}) | ||
export class HistoryModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { HistoryService } from './history.service'; | ||
|
||
describe('HistoryService', () => { | ||
let service: HistoryService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [HistoryService], | ||
}).compile(); | ||
|
||
service = module.get<HistoryService>(HistoryService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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,41 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { History } from './entities/history.entity'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
|
||
@Injectable() | ||
export class HistoryService { | ||
constructor( | ||
@InjectRepository(History) | ||
private historyRepository: Repository<History> | ||
) {} | ||
|
||
all(user: string) { | ||
return this.historyRepository.find({ where: { user } }); | ||
} | ||
|
||
getOne(id: string, user: string) { | ||
return this.historyRepository.findOne({ where: { id, user } }); | ||
} | ||
|
||
add( | ||
session: string, | ||
user: string, | ||
relyingParty: string, | ||
logo: string, | ||
url: string | ||
) { | ||
const history = new History(); | ||
history.id = session; | ||
history.user = user; | ||
history.relyingParty = relyingParty; | ||
history.relyingPartyLogo = logo; | ||
history.value = url; | ||
history.status = 'pending'; | ||
return this.historyRepository.save(history); | ||
} | ||
|
||
setStatus(id: string, status: 'accepted' | 'declined') { | ||
return this.historyRepository.update({ id }, { status }); | ||
} | ||
} |
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
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
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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.