Skip to content

Commit

Permalink
added app-auth module
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas1 committed Jan 15, 2023
1 parent d80f266 commit 0c27814
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/app-auth/app-auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common';
import { AppAuthService } from './services/app-auth/app-auth.service';
import { AppAuthController } from './controllers/app-auth/app-auth.controller';

@Module({
providers: [AppAuthService],
controllers: [AppAuthController]
})
export class AppAuthModule {}
18 changes: 18 additions & 0 deletions src/app-auth/controllers/app-auth/app-auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppAuthController } from './app-auth.controller';

describe('AppAuthController', () => {
let controller: AppAuthController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AppAuthController],
}).compile();

controller = module.get<AppAuthController>(AppAuthController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
26 changes: 26 additions & 0 deletions src/app-auth/controllers/app-auth/app-auth.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller, Get, ValidationPipe, Post, UsePipes, Body, Req, Res, HttpStatus } from '@nestjs/common';
import { CreateAppDto } from 'src/app-auth/dtos/CreateApp.dto';
import { AppAuthService } from 'src/app-auth/services/app-auth/app-auth.service';
import { Request, Response } from 'express'
@Controller('app-auth')
export class AppAuthController {
constructor(private readonly appAuthService: AppAuthService){}

@Get()
getAppAuth() {
return this.appAuthService.getAllApps();
}


@Post('/register')
register(@Req() req: Request,@Res() res: Response): any {

console.log(req.body)
const b = new CreateAppDto()
b.userId = req.body['userId'];
b.appName = req.body['appName'];
const napp = this.appAuthService.createAnApp(b)
return res.status(HttpStatus.CREATED).send(napp)
}

}
5 changes: 5 additions & 0 deletions src/app-auth/dtos/CreateApp.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

export class CreateAppDto {
userId: string;
appName: string;
}
18 changes: 18 additions & 0 deletions src/app-auth/services/app-auth/app-auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppAuthService } from './app-auth.service';

describe('AppAuthService', () => {
let service: AppAuthService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [AppAuthService],
}).compile();

service = module.get<AppAuthService>(AppAuthService);
});

it('should be defined', () => {
expect(service).toBeDefined();
});
});
32 changes: 32 additions & 0 deletions src/app-auth/services/app-auth/app-auth.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Injectable } from '@nestjs/common';
import { IApp } from '../../types/App.types';
import { CreateAppDto } from '../../dtos/CreateApp.dto';
@Injectable()
export class AppAuthService {
private apps = [
{
userId: "user123",
appName: "app1",
appId: "app-1",
appSecret: "app-secret-1",
edvId: "edv-1",
kmsId: "kms-1",
}
]

createAnApp(createAppDto: CreateAppDto){
const newApp = {
...createAppDto,
appId: 'app-1',
appSecret: "app-secret-1",
edvId: "edv-1",
kmsId: "kms-1",
}
this.apps.push(newApp);
return newApp
}

getAllApps () {
return this.apps
}
}
8 changes: 8 additions & 0 deletions src/app-auth/types/App.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface IApp {
userId: string;
appName: string;
appId: string;
appSecret: string;
edvId: string;
kmsId: string;
}

0 comments on commit 0c27814

Please sign in to comment.