-
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.
feat: connect to a mocked mongo sandbox
- Loading branch information
1 parent
463cbcc
commit 59c6de2
Showing
17 changed files
with
966 additions
and
128 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,47 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Get, | ||
HttpException, | ||
HttpStatus, | ||
Param, | ||
Post, | ||
} from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { MongoRepository } from 'typeorm'; | ||
import { CreateOidcClientDto } from './oidc-client.dto'; | ||
import { OidcClientSaver } from './oidc-client.saver'; | ||
import { Controller, Get, NotFoundException, Param } from '@nestjs/common'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Model } from 'mongoose'; | ||
import { ServiceProvider } from './service-provider-adapter-mongo.schema'; | ||
|
||
@Controller('oidc-clients') | ||
export class OidcClientController { | ||
constructor( | ||
private readonly oidcClientSaver: OidcClientSaver, | ||
@InjectRepository(ServiceProvider) | ||
private readonly serviceProvider: MongoRepository<ServiceProvider>, | ||
) { | ||
this.oidcClientSaver = oidcClientSaver; | ||
} | ||
|
||
@InjectModel(ServiceProvider.name, 'sandbox') | ||
private readonly serviceProvider: Model<ServiceProvider>, | ||
) {} | ||
@Get() | ||
async findAll() { | ||
console.log(this.serviceProvider.find()); | ||
return [ | ||
{ | ||
clientDescription: 'Description', | ||
clientId: 'clientId', | ||
clientSecret: 'ClientSecret', | ||
clientName: 'Rebecca Project 123', | ||
redirectUris: ['http://example.com/callback'], | ||
postLogoutRedirectUris: ['http://example.com/logout'], | ||
scope: ['firstname', 'lastname'], | ||
}, | ||
] satisfies CreateOidcClientDto[]; | ||
return await this.serviceProvider.find().exec(); | ||
} | ||
|
||
@Get('/:id') | ||
async find_by_id(@Param('id') id: string) { | ||
@Get('/:key') | ||
async find_by_id(@Param('key') key: string) { | ||
const service = await this.serviceProvider.findOne({ key }).exec(); | ||
if (!service) throw new NotFoundException(); | ||
return { | ||
clientDescription: 'Description', | ||
clientId: 'clientId', | ||
clientSecret: 'ClientSecret', | ||
clientName: 'Rebecca Project 123', | ||
redirectUris: ['http://example.com/callback'], | ||
postLogoutRedirectUris: ['http://example.com/logout'], | ||
scope: ['firstname', 'lastname'], | ||
} satisfies CreateOidcClientDto; | ||
} | ||
|
||
@Post() | ||
async create(@Body() createOidcClientDto: CreateOidcClientDto) { | ||
try { | ||
return await this.oidcClientSaver.save(createOidcClientDto); | ||
} catch (error) { | ||
throw new HttpException( | ||
{ | ||
status: HttpStatus.BAD_REQUEST, | ||
error: `Error occurs : ${error.message}`, | ||
}, | ||
HttpStatus.BAD_REQUEST, | ||
{ | ||
cause: error, | ||
}, | ||
); | ||
} | ||
clientName: service.name, | ||
clientDescription: service.email, | ||
clientId: service.entityId, | ||
clientSecret: service.client_secret, | ||
scope: service.scopes, | ||
postLogoutRedirectUris: service.post_logout_redirect_uris, | ||
redirectUris: service.redirect_uris, | ||
}; | ||
} | ||
// @Post() | ||
// async create(@Body() createOidcClientDto: CreateOidcClientDto) { | ||
// try { | ||
// return await this.oidcClientSaver.save(createOidcClientDto); | ||
// } catch (error) { | ||
// throw new HttpException( | ||
// { | ||
// status: HttpStatus.BAD_REQUEST, | ||
// error: `Error occurs : ${error.message}`, | ||
// }, | ||
// HttpStatus.BAD_REQUEST, | ||
// { | ||
// cause: 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 |
---|---|---|
@@ -1,14 +1,20 @@ | ||
// | ||
|
||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { OidcClientController } from './oidc-client.controller'; | ||
import { OidcClient } from './oidc-client.entity'; | ||
import { OidcClientSaver } from './oidc-client.saver'; | ||
import { ServiceProvider } from './service-provider-adapter-mongo.schema'; | ||
import { | ||
ServiceProvider, | ||
ServiceProviderSchema, | ||
} from './service-provider-adapter-mongo.schema'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([OidcClient, ServiceProvider])], | ||
imports: [ | ||
MongooseModule.forFeature( | ||
[{ name: ServiceProvider.name, schema: ServiceProviderSchema }], | ||
'sandbox', | ||
), | ||
], | ||
controllers: [OidcClientController], | ||
providers: [OidcClientSaver], | ||
exports: [OidcClientSaver], | ||
}) | ||
export class OidcClientModule {} |
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
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
Oops, something went wrong.