-
Notifications
You must be signed in to change notification settings - Fork 1
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
8 changed files
with
999 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { App, AppDocument } from '../schemas/App.schema' | ||
import { FilterQuery, Model } from 'mongoose'; | ||
import { InjectModel } from '@nestjs/mongoose' | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class AppRepository { | ||
constructor(@InjectModel(App.name) private readonly appModel: Model<AppDocument>) {} | ||
|
||
async findOne(appFilterQuery: FilterQuery<App>): Promise<App>{ | ||
return this.appModel.findOne(appFilterQuery); | ||
} | ||
|
||
async find(appsFilterQuery: FilterQuery<App>): Promise<App[]>{ | ||
return this.appModel.find(appsFilterQuery); | ||
} | ||
|
||
async create(app: App): Promise<App>{ | ||
const newapp = new this.appModel(app) | ||
return newapp.save(); | ||
} | ||
|
||
async findOneAndUpdate(appFilterQuery: FilterQuery<App>, app: Partial<App>): Promise<App>{ | ||
return this.appModel.findOneAndUpdate(appFilterQuery, app); | ||
} | ||
|
||
|
||
|
||
} |
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,56 +1,55 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IApp } from '../types/App.types'; | ||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; | ||
import { Document } from 'mongoose'; | ||
|
||
export type AppDocument = App & Document; | ||
|
||
@Schema() | ||
export class App { | ||
|
||
// TODO: this should be changed into mongo db schema | ||
export class AppSchema implements IApp { | ||
@ApiProperty({ | ||
description: "User DID", | ||
example: "did:hid:testnet:123123" | ||
}) | ||
@Prop() | ||
userId: string; | ||
|
||
@ApiProperty({ | ||
description: "Application name", | ||
example: "demo app" | ||
}) | ||
@Prop() | ||
appName: string; | ||
|
||
@ApiProperty({ | ||
description: "Application id", | ||
example: "app-1" | ||
}) | ||
@Prop() | ||
appId: string; | ||
|
||
@ApiProperty({ | ||
description: "Application Secret", | ||
example: "app-secret-1" | ||
}) | ||
@Prop() | ||
appSecret: string; | ||
|
||
@ApiProperty({ | ||
description: "Data Vault Id", | ||
example: "hs-edv-id-1" | ||
}) | ||
@Prop() | ||
edvId: string; | ||
|
||
@ApiProperty({ | ||
description: "Keymanagement Service Id", | ||
example: "hs-kms-id-1" | ||
}) | ||
@Prop() | ||
kmsId: string; | ||
constructor(params: { | ||
userId, | ||
appName, | ||
appId, | ||
appSecret, | ||
edvId, | ||
kmsId | ||
}){ | ||
this.userId = params.userId | ||
this.appName = params.appName; | ||
this.appId = params.appId | ||
this.appSecret = params.appSecret | ||
this.edvId = params.edvId | ||
this.kmsId = params.kmsId | ||
} | ||
} | ||
|
||
} | ||
|
||
export const AppSchema = SchemaFactory.createForClass(App) |
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,29 +1,28 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { IApp } from '../../types/App.types'; | ||
import { CreateAppDto } from '../../dtos/CreateApp.dto'; | ||
import { AppSchema } from 'src/app-auth/schemas/App.schema'; | ||
import { App } from 'src/app-auth/schemas/App.schema'; | ||
import { AppRepository } from 'src/app-auth/repositories/App.repository'; | ||
import { uuid } from 'uuidv4'; | ||
|
||
@Injectable() | ||
export class AppAuthService { | ||
private apps: IApp[] = [] | ||
constructor(private readonly appRepository: AppRepository) {} | ||
|
||
createAnApp(createAppDto: CreateAppDto): IApp{ | ||
const appSchema = new AppSchema({ | ||
createAnApp(createAppDto: CreateAppDto): Promise<App>{ | ||
return this.appRepository.create({ | ||
...createAppDto, | ||
appId: 'demo-app1', // generate app id | ||
appSecret: 'demo-secret-1', // generate app secret | ||
appId: uuid(), // generate app id | ||
appSecret: uuid(), // TODO: generate app secret and should be handled like password by hashing and all... | ||
edvId: 'hs-edv-1', // generate edvId by called hypersign edv service | ||
kmsId: 'demo-kms-1' | ||
}) | ||
this.apps.push(appSchema); | ||
return appSchema | ||
} | ||
|
||
getAllApps () { | ||
return this.apps | ||
getAllApps (): Promise<App[]>{ | ||
return this.appRepository.find({}) | ||
} | ||
|
||
getAppById (appId: string) { | ||
return this.apps.find(app => app.appId === appId) | ||
getAppById (appId: string): Promise<App> { | ||
return this.appRepository.findOne({ appId }) | ||
} | ||
} |
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.