api modified for auth and holder template
This commit is contained in:
parent
7b8e595a92
commit
72ffa77ba6
@ -10,17 +10,17 @@ import { Roles } from 'src/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from 'src/guards/jwt-auth.guard';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@Controller("1")
|
||||
@Controller()
|
||||
export class AuthController {
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
) { }
|
||||
|
||||
@Post('login')
|
||||
@Post('1/login')
|
||||
@HttpCode(200)
|
||||
async loginClient(@Body() body: AuthLoginOnlyDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) {
|
||||
|
||||
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req);
|
||||
let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, body.P_APPLICATIONNAME, req, 1);
|
||||
|
||||
if (k.access_token) {
|
||||
res.cookie('access_token', k.access_token, {
|
||||
@ -42,9 +42,15 @@ export class AuthController {
|
||||
}
|
||||
|
||||
// @UseGuards(RegisterGuard)
|
||||
@Post('register')
|
||||
@Post('1/register')
|
||||
async register(@Body() body: AuthLoginDTO) {
|
||||
return this.authService.registerUser(body);
|
||||
return this.authService.registerUser(body, 1);
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('1/forgot-password')
|
||||
async forgotPassword(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@UseInterceptors(LogoutInterceptor)
|
||||
@ -68,12 +74,6 @@ export class AuthController {
|
||||
res.json({ ...rst })
|
||||
}
|
||||
|
||||
@UseGuards(RegisterGuard)
|
||||
@Put('forgot-password')
|
||||
async forgotPassword(@Body() body: AuthLoginDTO, @Req() req: Request) {
|
||||
return this.authService.forgotPassword(body, req);
|
||||
}
|
||||
|
||||
@Get('refresh-tokens')
|
||||
async getTokenFromRefreshToken(@Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
let k: any = await this.authService.getTokenFromRefreshToken(req)
|
||||
|
||||
@ -6,9 +6,10 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { OracleModule } from 'src/oracle/oracle.module';
|
||||
import { MailModule } from 'src/mail/mail.module';
|
||||
import { PgModule } from 'src/pg/pg.module';
|
||||
|
||||
@Module({
|
||||
imports: [DbModule,MailModule, forwardRef(() => OracleModule)],
|
||||
imports: [DbModule,MailModule, forwardRef(() => OracleModule), forwardRef(() => PgModule)],
|
||||
providers: [
|
||||
AuthService,
|
||||
{
|
||||
|
||||
@ -11,9 +11,10 @@ import { UnauthorizedException } from 'src/exceptions/unauthorized.exception';
|
||||
import { ConflictException } from 'src/exceptions/conflict.exception';
|
||||
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { UserMaintenanceService } from 'src/oracle/user-maintenance/user-maintenance.service';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { MailService } from 'src/mail/mail.service';
|
||||
import { UserMaintenanceService as OracleUserMaintenanceService } from 'src/oracle/user-maintenance/user-maintenance.service';
|
||||
import { UserMaintenanceService as PgUserMaintenanceService } from 'src/pg/user-maintenance/user-maintenance.service';
|
||||
|
||||
|
||||
interface DecodedToken {
|
||||
@ -44,7 +45,8 @@ export class AuthService {
|
||||
private readonly oracleDBService: OracleDBService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly mailService: MailService,
|
||||
private readonly userMaintenanceService: UserMaintenanceService,
|
||||
private readonly oracleUserMaintenanceService: OracleUserMaintenanceService,
|
||||
private readonly pgUserMaintenanceService: PgUserMaintenanceService,
|
||||
@Inject("REGISTER_SIGN_JWT") readonly REGISTER_SIGN_JWT: JwtService,
|
||||
@Inject("REGISTER_VERIFY_JWT") readonly REGISTER_VERIFY_JWT: JwtService
|
||||
) {
|
||||
@ -245,7 +247,7 @@ export class AuthService {
|
||||
return verified;
|
||||
}
|
||||
|
||||
async loginUser(username: string, password: string, applicationName: string, req: Request): Promise<any> {
|
||||
async loginUser(username: string, password: string, applicationName: string, req: Request, dbtype: number): Promise<any> {
|
||||
|
||||
const access_token = req.cookies?.access_token;
|
||||
const refresh_token = req.cookies?.refresh_token;
|
||||
@ -260,7 +262,14 @@ export class AuthService {
|
||||
try {
|
||||
const userSession = await this.getUserSession(username)
|
||||
|
||||
const emailVerifyResponse: any = await this.userMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
let emailVerifyResponse: any;
|
||||
|
||||
if (dbtype === 1) {
|
||||
emailVerifyResponse = await this.oracleUserMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
}
|
||||
else if (dbtype === 2) {
|
||||
emailVerifyResponse = await this.pgUserMaintenanceService.ValidateEmail({ P_EMAILADDR: username })
|
||||
}
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && emailVerifyResponse[0].ERRORMESG) {
|
||||
throw new BadRequestException();
|
||||
@ -270,9 +279,9 @@ export class AuthService {
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
case "USCIB": ROLE = 'ua'; break;
|
||||
case "SP": ROLE = 'sa'; break;
|
||||
case "CLIENT": ROLE = 'ca'; break;
|
||||
case "USCIB": ROLE = dbtype === 1 ? 'ua' : dbtype === 2 ? 'pua' : ''; break;
|
||||
case "SP": ROLE = dbtype === 1 ? 'sa' : dbtype === 2 ? 'psa' : ''; break;
|
||||
case "CLIENT": ROLE = dbtype === 1 ? 'ca' : dbtype === 2 ? 'pca' : ''; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -438,7 +447,6 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async forgotPassword(body: AuthLoginDTO, req: Request) {
|
||||
|
||||
let det = await req['user'];
|
||||
@ -512,13 +520,21 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
async registerUser(body: AuthLoginDTO) {
|
||||
async registerUser(body: AuthLoginDTO, dbtype: number) {
|
||||
// let det = await req['user'];
|
||||
// if (det?.email !== body.P_EMAILADDR) {
|
||||
// throw new BadRequestException();
|
||||
// }
|
||||
|
||||
const emailVerifyResponse: any = await this.userMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
let emailVerifyResponse: any;
|
||||
|
||||
if (dbtype === 1) {
|
||||
emailVerifyResponse = await this.oracleUserMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
}
|
||||
else if (dbtype === 2) {
|
||||
emailVerifyResponse = await this.pgUserMaintenanceService.ValidateEmail({ P_EMAILADDR: body.P_EMAILADDR })
|
||||
}
|
||||
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && emailVerifyResponse[0].ERRORMESG) {
|
||||
throw new BadRequestException();
|
||||
@ -569,9 +585,9 @@ export class AuthService {
|
||||
|
||||
if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) {
|
||||
switch (emailVerifyResponse[0].SOURCE) {
|
||||
case "USCIB": ROLE = 'ua'; break;
|
||||
case "SP": ROLE = 'sa'; break;
|
||||
case "CLIENT": ROLE = 'ca'; break;
|
||||
case "USCIB": ROLE = dbtype === 1 ? 'ua' : dbtype === 2 ? 'pua' : ''; break;
|
||||
case "SP": ROLE = dbtype === 1 ? 'sa' : dbtype === 2 ? 'psa' : ''; break;
|
||||
case "CLIENT": ROLE = dbtype === 1 ? 'ca' : dbtype === 2 ? 'pca' : ''; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,8 +734,6 @@ export class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
async getTokenFromRefreshToken(req: Request) {
|
||||
|
||||
const refreshToken = req.cookies['refresh_token'];
|
||||
|
||||
20
src/main.ts
20
src/main.ts
@ -81,6 +81,26 @@ async function bootstrap() {
|
||||
.setTitle('API')
|
||||
.setDescription('API description')
|
||||
.setVersion('1.0')
|
||||
.addTag('Auth')
|
||||
.addTag('Param Table - PG')
|
||||
.addTag('Regions - PG')
|
||||
.addTag('SP - PG')
|
||||
.addTag('Carnet Sequence - PG')
|
||||
.addTag('SPContacts - PG')
|
||||
.addTag('User Maintenance - PG')
|
||||
.addTag('Manage Fee - PG')
|
||||
// .addTag('Manage Holders - PG')
|
||||
.addTag('User Maintenance - Oracle')
|
||||
.addTag('Carnet Application - Oracle')
|
||||
.addTag('HomePage - Oracle')
|
||||
.addTag('Regions - Oracle')
|
||||
.addTag('SP - Oracle')
|
||||
.addTag('SPContacts - Oracle')
|
||||
.addTag('Carnet Sequence - Oracle')
|
||||
.addTag('Param Table - Oracle')
|
||||
.addTag('Manage Fee - Oracle')
|
||||
.addTag('Manage Holders - Oracle')
|
||||
.addTag('Manage Clients - Oracle')
|
||||
.addServer(
|
||||
'https://dev.alphaomegainfosys.com/test-api',
|
||||
'Development Server 2',
|
||||
|
||||
@ -7,6 +7,6 @@ import { AuthModule } from 'src/auth/auth.module';
|
||||
imports: [forwardRef(() => AuthModule)],
|
||||
controllers: [UserMaintenanceController],
|
||||
providers: [UserMaintenanceService],
|
||||
exports: [UserMaintenanceService, AuthModule]
|
||||
exports: [UserMaintenanceService]
|
||||
})
|
||||
export class UserMaintenanceModule { }
|
||||
|
||||
103
src/pg/manage-holder/manage-holder.controller.ts
Normal file
103
src/pg/manage-holder/manage-holder.controller.ts
Normal file
@ -0,0 +1,103 @@
|
||||
import { Body, Controller, Get, Param, Patch, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiQuery } from '@nestjs/swagger';
|
||||
import { CreateHolderContactsDTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO } from 'src/dto/property.dto';
|
||||
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||
import { ManageHolderService } from './manage-holder.service';
|
||||
|
||||
@Controller('manage-holder')
|
||||
export class ManageHolderController {
|
||||
|
||||
constructor(private readonly manageHoldersService: ManageHolderService) { }
|
||||
|
||||
// @Get('SearchHolder/:P_SPID/:P_USERID')
|
||||
@ApiQuery({ name: "P_HOLDERNAME", type: String, required: false, description: "Optional" })
|
||||
@ApiQuery({ name: "P_HOLDERID", type: Number, required: false, description: "Optional" })
|
||||
SearchHolder(
|
||||
@Param('P_SPID') P_SPID: number,
|
||||
@Param('P_USERID') P_USERID: string,
|
||||
@Query('P_HOLDERID') P_HOLDERID?: number,
|
||||
@Query('P_HOLDERNAME') P_HOLDERNAME?: string | null | undefined,
|
||||
) {
|
||||
if (!P_USERID) {
|
||||
throw new BadRequestException('User ID is required');
|
||||
}
|
||||
|
||||
// Sanitize holder name
|
||||
let rawHolderName: string | null = null;
|
||||
|
||||
if (typeof P_HOLDERNAME === 'string') {
|
||||
const trimmed = P_HOLDERNAME.trim().replace(/^['"]|['"]$/g, '');
|
||||
rawHolderName = trimmed === '' || trimmed.toLowerCase() === 'null' ? null : trimmed;
|
||||
}
|
||||
|
||||
// Validate and coerce P_HOLDERID
|
||||
let holderId: number | null = null;
|
||||
|
||||
if (P_HOLDERID !== undefined && P_HOLDERID !== null) {
|
||||
const parsed = Number(P_HOLDERID);
|
||||
if (isNaN(parsed)) {
|
||||
throw new BadRequestException('Invalid holder ID');
|
||||
}
|
||||
holderId = parsed;
|
||||
}
|
||||
|
||||
const body = {
|
||||
P_SPID,
|
||||
P_USERID,
|
||||
P_HOLDERID: holderId,
|
||||
P_HOLDERNAME: rawHolderName,
|
||||
};
|
||||
|
||||
return this.manageHoldersService.SearchHolder(body)
|
||||
}
|
||||
|
||||
// @Post('/CreateHolderData')
|
||||
CreateHolders(@Body() body: CreateHoldersDTO) {
|
||||
return this.manageHoldersService.CreateHolders(body);
|
||||
}
|
||||
|
||||
// @Post('CreateHoldercontact')
|
||||
CreateHoldercontact(@Body() body: CreateHolderContactsDTO) {
|
||||
return this.manageHoldersService.CreateHoldercontact(body);
|
||||
}
|
||||
|
||||
// @Put('/UpdateHolder')
|
||||
UpdateHolder(@Body() body: UpdateHolderDTO) {
|
||||
return this.manageHoldersService.UpdateHolder(body);
|
||||
}
|
||||
|
||||
// @Put('/UpdateHolderContact')
|
||||
UpdateHolderContact(@Body() body: UpdateHolderContactDTO) {
|
||||
return this.manageHoldersService.UpdateHolderContact(body);
|
||||
}
|
||||
|
||||
// @Get('/GetHolderRecord/:P_SPID/:P_HOLDERID')
|
||||
GetHolderMaster(@Param() body: GetHolderDTO) {
|
||||
return this.manageHoldersService.GetHolderRecord(body);
|
||||
}
|
||||
|
||||
// @Get('/GetHolderContacts/:P_SPID/:P_HOLDERID')
|
||||
GetHolderContacts(@Param() body: GetHolderDTO) {
|
||||
return this.manageHoldersService.GetHolderContacts(body);
|
||||
}
|
||||
|
||||
// @Patch('/InactivateHolder/:P_SPID/:P_HOLDERID/:P_USERID')
|
||||
InactivateHolder(@Param() body: HolderActivateOrInactivateDTO) {
|
||||
return this.manageHoldersService.InactivateHolder(body);
|
||||
}
|
||||
|
||||
// @Patch('/ReactivateHolder/:P_SPID/:P_HOLDERID/:P_USERID')
|
||||
ReactivateHolder(@Param() body: HolderActivateOrInactivateDTO) {
|
||||
return this.manageHoldersService.ReactivateHolder(body);
|
||||
}
|
||||
|
||||
// @Patch('/InactivateHolderContact/:P_SPID/:P_HOLDERCONTACTID/:P_USERID')
|
||||
InactivateHolderContact(@Param() body: HolderContactActivateOrInactivateDTO) {
|
||||
return this.manageHoldersService.InactivateHolderContact(body);
|
||||
}
|
||||
|
||||
// @Patch('/ReactivateHolderContact/:P_SPID/:P_HOLDERCONTACTID/:P_USERID')
|
||||
ReactivateHolderContact(@Param() body: HolderContactActivateOrInactivateDTO) {
|
||||
return this.manageHoldersService.ReactivateHolderContact(body);
|
||||
}
|
||||
}
|
||||
9
src/pg/manage-holder/manage-holder.module.ts
Normal file
9
src/pg/manage-holder/manage-holder.module.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ManageHolderController } from './manage-holder.controller';
|
||||
import { ManageHolderService } from './manage-holder.service';
|
||||
|
||||
@Module({
|
||||
controllers: [ManageHolderController],
|
||||
providers: [ManageHolderService]
|
||||
})
|
||||
export class ManageHolderModule {}
|
||||
33
src/pg/manage-holder/manage-holder.service.ts
Normal file
33
src/pg/manage-holder/manage-holder.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PgDBService } from 'src/db/db.service';
|
||||
import { CreateHolderContactsDTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO } from 'src/dto/property.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ManageHolderService {
|
||||
|
||||
constructor(private readonly pgDBService: PgDBService) { }
|
||||
|
||||
async CreateHolders(body: CreateHoldersDTO) { }
|
||||
|
||||
async CreateHoldercontact(body: CreateHolderContactsDTO) {
|
||||
|
||||
}
|
||||
|
||||
UpdateHolder = async (body: UpdateHolderDTO) => { };
|
||||
|
||||
GetHolderRecord = async (body: GetHolderDTO) => { };
|
||||
|
||||
UpdateHolderContact = async (body: UpdateHolderContactDTO) => { };
|
||||
|
||||
GetHolderContacts = async (body: GetHolderDTO) => { };
|
||||
|
||||
InactivateHolder = async (body: HolderActivateOrInactivateDTO) => { };
|
||||
|
||||
ReactivateHolder = async (body: HolderActivateOrInactivateDTO) => { };
|
||||
|
||||
InactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => { };
|
||||
|
||||
ReactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => { };
|
||||
|
||||
SearchHolder = async (body: { P_SPID: number, P_USERID: string, P_HOLDERID: number | null, P_HOLDERNAME: string | null }) => { }
|
||||
}
|
||||
@ -1,11 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ParamTableModule } from './param-table/param-table.module';
|
||||
import { DbModule } from 'src/db/db.module';
|
||||
import { UscibManagedSpModule } from './uscib-managed-sp/uscib-managed-sp.module';
|
||||
import { UserMaintenanceModule } from './user-maintenance/user-maintenance.module';
|
||||
import { ManageFeeModule } from './manage-fee/manage-fee.module';
|
||||
import { ManageHolderModule } from './manage-holder/manage-holder.module';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [DbModule, ParamTableModule, UscibManagedSpModule, UserMaintenanceModule, ManageFeeModule],
|
||||
imports: [DbModule, ParamTableModule, UscibManagedSpModule, UserMaintenanceModule, ManageFeeModule, ManageHolderModule],
|
||||
providers: [],
|
||||
exports: [UserMaintenanceModule]
|
||||
})
|
||||
export class PgModule { }
|
||||
|
||||
@ -1,9 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { UserMaintenanceController } from './user-maintenance.controller';
|
||||
import { UserMaintenanceService } from './user-maintenance.service';
|
||||
import { AuthModule } from 'src/auth/auth.module';
|
||||
|
||||
@Module({
|
||||
imports: [forwardRef(() => AuthModule)],
|
||||
controllers: [UserMaintenanceController],
|
||||
providers: [UserMaintenanceService]
|
||||
providers: [UserMaintenanceService],
|
||||
exports: [UserMaintenanceService]
|
||||
})
|
||||
export class UserMaintenanceModule { }
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { CreateClientLoginsDTO, CreateSPLoginsDTO, CreateUSCIBLoginsDTO, EMAIL_DTO, SPID_CLIENTID_DTO, SPID_DTO, SPID_EMAIL_DTO, USERID_DTO } from 'src/dto/property.dto';
|
||||
import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper';
|
||||
|
||||
@ -15,7 +15,7 @@ export class UserMaintenanceService {
|
||||
|
||||
constructor(
|
||||
private readonly pgDBService: PgDBService,
|
||||
// @Inject(forwardRef(() => AuthService))
|
||||
@Inject(forwardRef(() => AuthService))
|
||||
private readonly authService: AuthService
|
||||
) { }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user