From 31b755e90483cb2f2cf5fddecc498b187c43cd9a Mon Sep 17 00:00:00 2001 From: josh Date: Sat, 29 Jul 2023 12:10:30 +0530 Subject: [PATCH] modifications --- config/default.yml | 8 +- src/auth/auth.controller.ts | 31 +- src/auth/auth.service.ts | 424 +++++++++++++----- src/email/email.service.ts | 6 +- src/file-upload/file-upload.controller.ts | 29 +- .../payment-master/payment-master.entity.ts | 2 +- .../payment-master/payment-master.service.ts | 4 +- src/transactions/tender/tender.controller.ts | 7 + src/transactions/tender/tender.service.ts | 4 + 9 files changed, 355 insertions(+), 160 deletions(-) diff --git a/config/default.yml b/config/default.yml index 36dd6aa..8b346ce 100644 --- a/config/default.yml +++ b/config/default.yml @@ -31,9 +31,9 @@ facebook: callbackURL: 'https://myfin.api.teorainfotech.com/api/v1/auth/facebook/redirect' mail: - fromMail: 'website.tscb@gmail.com' - user: 'website.tscb@gmail.com' - pass: 'zubhybaneozurlvy' + fromMail: 'tender.tscb178@gmail.com' + user: 'tender.tscb178@gmail.com' + pass: 'gsccukdorvjyfrxr' cron: scheduler: false @@ -50,7 +50,7 @@ smsPhoneNumberArgName: message: 'text' url: - url: "http://localhost:4200/#" + url: "https://tender.accuratesoftware.online/#" bodyWay2SMS: apikey: "CKDG9HL5KYFLLILRMX3QX1CPKOIP8QF1" diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 0e1568b..8c4c82a 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -1,7 +1,7 @@ import { Controller, Get, UseGuards, Res, Req, Body, ValidationPipe, Post, HttpCode, Ip, HostParam, HttpStatus, Put, Param, Patch } from '@nestjs/common'; import { TokenDto } from './dto/token.dto'; -//import { AuthGuard } from '@nestjs/passport'; + import * as config from 'config'; import { AuthCreadentialsDto } from './dto/auth-credentials.dto'; import { AuthService } from './auth.service'; @@ -21,16 +21,15 @@ export class AuthController { ) { } @Post('/user-info') - async userInfo(@Body() authCredentialDto:AuthCreadentialsDto){ + async userInfo(@Body() authCredentialDto: AuthCreadentialsDto) { return this.authService.userInfo(authCredentialDto) } - @Post('/signin') - async signIn(@Body(ValidationPipe) + async signIn(@Body(ValidationPipe) authCredentialDto: AuthCreadentialsDto, - @Req() req): Promise { + @Req() req): Promise { return this.authService.signIn(authCredentialDto, req.ip); } @@ -46,29 +45,29 @@ export class AuthController { } - + @Post('/signup') async signUp(@Body() pcdUserDto: PcduserDto): Promise { // request.connection.remoteAddress console.log("hello"); - + return this.authService.tempSignUp(pcdUserDto); } - + @Post('/forgot-password') async forgotPassword( - @Body() body: { pass: string, email: string ,otp:string }, + @Body() body: { pass: string, email: string, otp: string }, ): Promise { return await this.authService.forgotPassword(body); } @Post('/otp/:flag') async sendOtp( - @Body() body: { email: string}, + @Body() body: { email: string, custName: string, tenderName: string, bidOpenDate: string }, @Param('flag') flag: string ): Promise { - return await this.authService.sendOtp(body, flag ); + return await this.authService.sendOtp(body, flag); } // @Post('/resend-otp/:flag') @@ -87,7 +86,7 @@ export class AuthController { return await this.authService.verifyOtp(body, flag); } - + // @Get('/encrypt/:bc') // async encryptBankCode(@GetUser() user: Pcduser, @@ -106,7 +105,7 @@ export class AuthUserController { private authService: AuthService ) { } - + // @Put('/:id') // async updateUser( @@ -129,10 +128,10 @@ export class AuthUserController { // @Body(ValidationPipe) passwords: ChangePasswordDto, // @GetUser() user: PcduserDto // ): Promise<{ msg: string }> { - + // return await this.authService.changeTransactionPinCurrentUser(passwords, user.userId, user); // } - - + + } \ No newline at end of file diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index bf60027..c3240f6 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -43,7 +43,7 @@ export class AuthService { private jwtService: JwtService, private crypto: CryptoService, private pcdotpRepository: PcdotpRepository, - private mailService : EmailService + private mailService: EmailService ) { @@ -52,21 +52,21 @@ export class AuthService { async getAll() { return await this.pcduserRepository.find(); } - - async userInfo(authCredentialsDto: AuthCreadentialsDto){ - const { username ,secuLevel } = authCredentialsDto; + + async userInfo(authCredentialsDto: AuthCreadentialsDto) { + const { username, secuLevel } = authCredentialsDto; let user = await this.pcduserRepository.findOne({ email: (username.trim()).toLocaleLowerCase() }); - if(!user){ + if (!user) { throw new BadRequestException('User Details not found') } - if(user){ - // authCredentialsDto.secuLevel = user.secuLevel - return {username:user.userName ,secuLevel:user.secuLevel , userId:user.userId , mobile:user.mobileNumber , email:user.email} + if (user) { + // authCredentialsDto.secuLevel = user.secuLevel + return { username: user.userName, secuLevel: user.secuLevel, userId: user.userId, mobile: user.mobileNumber, email: user.email } } - + } - + async signIn(authCredentialsDto: AuthCreadentialsDto, ip?: string): Promise { @@ -77,151 +77,337 @@ export class AuthService { } return await this.generateTokens(user, user.userName, ip, authCredentialsDto.module, user['changePassword']); } - + async validateUserPassword(authCredentialsDto: AuthCreadentialsDto): Promise { - const { username, password} = authCredentialsDto; + const { username, password } = authCredentialsDto; let user = await this.pcduserRepository.findOne({ email: (username.trim()).toLocaleLowerCase() }); console.log("user=============", user); if (!user) { throw new UnauthorizedException('User not Registered') } - + if (user && await user.validatePassword(password, user)) { return user; } else { throw new BadRequestException("Wrong Password"); - + } } - async forgotPassword(body: { pass: string, email: string, otp:string }): Promise { + async forgotPassword(body: { pass: string, email: string, otp: string }): Promise { let iuserData: PcduserDto = await this.pcduserRepository.findOne({ where: { email: body.email } }); - console.log("iuserdata",iuserData); - + console.log("iuserdata", iuserData); + const filter: FindManyOptions = { where: { "refCode": body.email, "status": "I" }, order: { code: "DESC" } }; - const newOtp = await this.pcdotpRepository.find(filter); + const newOtp = await this.pcdotpRepository.find(filter); - if(body.otp != newOtp[0].otp){ - throw new UnauthorizedException('Unauthorized Access') - } - console.log("salt1234"); - const salt = await bcrypt.genSalt(); - iuserData.salt = salt; - iuserData.pass = await bcrypt.hash(body.pass, salt); - console.log("salt",iuserData.salt); - console.log("pass",iuserData.pass); - - try { - await this.pcduserRepository.save(iuserData); - } - catch (err) { - throw new BadRequestException("Error in Password Reset"); - } + if (body.otp != newOtp[0].otp) { + throw new UnauthorizedException('Unauthorized Access') + } + console.log("salt1234"); + const salt = await bcrypt.genSalt(); + iuserData.salt = salt; + iuserData.pass = await bcrypt.hash(body.pass, salt); + console.log("salt", iuserData.salt); + console.log("pass", iuserData.pass); + + try { + await this.pcduserRepository.save(iuserData); + } + catch (err) { + throw new BadRequestException("Error in Password Reset"); } + } + + async sendMail(email: string, custName: string, tenderName: string, bidOpenDate: string, data: string, flag: string) { - async sendMail(email: string, data: string, flag: string) { - - let content: string; - let subject: string = "Login Credentials"; - if (flag == 'otp') { - content = `Your one time password(OTP) for Tender Registration is, ${data} `; - subject = 'OTP' + let content: string; + let subject: string = "Login Credentials"; + if (flag == 'otp') { + content = ` + + + + + + OTP + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
 
+ + logo + +

THRICKODITHANAM SCB

+
 
+ + + + + + + + + + +
 
+

OTP +

+

+ Please Register immediately after getting OTP ,
+ Your one time password(OTP) for register in tenders is.

+ +

+ + OTP + +

${data}

+

- } - - if (flag == 'fpwd') { - content = `Your one time password(OTP) for Password reset is, ${data}`; - subject = 'OTP' - } - - await this.mailService.sendMail(email, subject, content, content); - + +
 
+
 
+

© www.thrickodithanamscb.in

+
 
+
+ + + + `; + subject = 'OTP' + } + if (flag == 'uDocSub') { + content = `Dear ${custName},

+ We hope this email finds you well. We would like to express our sincere gratitude for your participation in the tender process for ${tenderName}. We are pleased to inform you that your tender documents have been successfully submitted. Thank you for your meticulous efforts in preparing and submitting all the necessary documents within the specified timeframe.

+ The bid opening for the tender you have participated in is scheduled for ${bidOpenDate}. During this process, all submitted tenders will be carefully reviewed and assessed. We will diligently consider each proposal and evaluate it against the criteria outlined in the tender documentation.
+ Should any additional information or documents be required, we will promptly reach out to you via the contact details provided during the submission process.

+ Should you have any queries or require any clarification regarding the tender process or your submission, please contact our dedicated tender support team. You can reach us via email at tscb178@gmail.com or by calling our helpline at tel:04812441062 or tel:04812443452.

+ Once again, we extend our heartfelt appreciation for your participation in this tender. Your interest and contribution are highly valued, and we look forward to the possibility of working together in the future.

+ Best regards,
+ Thrickodithanam Service Co-operative Bank LTD No 178,
+ Kunnumpuram, Thrickodithanam,
Kottayam, Kerala, 686105.`; + subject = 'Tender Submission Successful - Thank you for your participation!' + } + + if (flag == 'fpwd') { + content = ` + + + + + OTP + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + +
 
+ + logo + +

THRICKODITHANAM SCB

+
 
+ + + + + + + + + + +
 
+

OTP +

+

+ Please Register immediately after getting OTP ,
+ Your one time password(OTP) for Reset Password is.

+ +

+ + OTP +

${data}

+

+ + +
 
+
 
+

© + www.thrickodithanamscb.in

+
 
+
+ + + + `; + subject = 'OTP' + } + + await this.mailService.sendMail(email, subject, content, content); + + } + - - async sendOtp(body: { email: string}, flag: string): Promise { + async sendOtp(body: { email: string, custName: string, tenderName: string, bidOpenDate: string }, flag: string): Promise { if (body.email) { - if (flag == 'F' || flag == 'R'){ + if (flag == 'F' || flag == 'R' || flag == 'UD') { let isUserExist = await this.pcduserRepository.findOne({ where: { email: body.email } }); - - console.log("isUserExist",isUserExist); - if(!isUserExist && flag == "F"){ + console.log("isUserExist", isUserExist); + + if (!isUserExist && flag == "F") { throw new BadRequestException("User not found"); } if (flag == 'R' && isUserExist) { throw new BadRequestException("Already registered with this email Id."); - }else{ - let newOtp = await this.generateOtp(body.email, flag); - if (body.email && flag == 'R') { - await this.sendMail(body.email, newOtp, 'otp'); - } - if (body.email && flag == 'F') { - await this.sendMail(body.email, newOtp, 'fpwd'); + } else { + let newOtp = await this.generateOtp(body.email, flag); + if (body.email && flag == 'R') { + await this.sendMail(body.email, body.custName, body.tenderName, body.bidOpenDate, newOtp, 'otp'); + } + if (body.email && flag == 'F') { + await this.sendMail(body.email, body.custName, body.tenderName, body.bidOpenDate, newOtp, 'fpwd'); + } + if (body.email && flag == 'UD') { + await this.sendMail(body.email, body.custName, body.tenderName, body.bidOpenDate, newOtp, 'uDocSub'); + } + } - - } - } err => { - console.log(err,"hello12345"); - - }; + } err => { + console.log(err, "hello12345"); + }; - } - } - - - async tempSignUp(pcdUserDto: PcduserDto): Promise { - const filter: FindManyOptions = { where: { "refCode": pcdUserDto.email, "status": "I" }, order: { code: "DESC" } }; - const newOtp = await this.pcdotpRepository.find(filter); - const existingUser = await this.pcduserRepository.findOne({ where: { email: pcdUserDto.email } }); - if (existingUser) { - throw new BadRequestException('User Already Exists'); - } - if (pcdUserDto.otp != newOtp[0].otp) { - throw new UnauthorizedException('Unauthorized Access'); - } - - - //Creating Random User_Id for every user registered - const lastUser: PcduserDto = await this.pcduserRepository.findOne({ - where: {}, - order: { userId: 'DESC' }, - }); - let maxCode = 10000; - if (lastUser && lastUser.userId) { - const lastUserId = parseInt(lastUser.userId); - maxCode = Math.max(maxCode, lastUserId); - } - const newUserId = String(maxCode + 1).padStart(5, '0'); - ///////////////////////////////////////////////////////////// - pcdUserDto.userId = newUserId; - const salt = await bcrypt.genSalt(); - pcdUserDto.salt = salt; - pcdUserDto.pass = await bcrypt.hash(pcdUserDto.pass, salt); - pcdUserDto.secuLevel = 'U'; - delete pcdUserDto['otp']; - await this.pcduserRepository.save(pcdUserDto); - this.logger.verbose("User created with email:", pcdUserDto.email); - return { data: "Successfully Registered" }; - } + } + } + + async tempSignUp(pcdUserDto: PcduserDto): Promise { + const filter: FindManyOptions = { where: { "refCode": pcdUserDto.email, "status": "I" }, order: { code: "DESC" } }; + const newOtp = await this.pcdotpRepository.find(filter); + const existingUser = await this.pcduserRepository.findOne({ where: { email: pcdUserDto.email } }); + if (existingUser) { + throw new BadRequestException('User Already Exists'); + } + if (pcdUserDto.otp != newOtp[0].otp) { + throw new UnauthorizedException('Unauthorized Access'); + } + + //Creating Random User_Id for every user registered + const lastUser: PcduserDto = await this.pcduserRepository.findOne({ + where: {}, + order: { userId: 'DESC' }, + }); + let maxCode = 10000; + if (lastUser && lastUser.userId) { + const lastUserId = parseInt(lastUser.userId); + maxCode = Math.max(maxCode, lastUserId); + } + const newUserId = String(maxCode + 1).padStart(5, '0'); + ///////////////////////////////////////////////////////////// + + pcdUserDto.userId = newUserId; + const salt = await bcrypt.genSalt(); + pcdUserDto.salt = salt; + pcdUserDto.pass = await bcrypt.hash(pcdUserDto.pass, salt); + pcdUserDto.secuLevel = 'U'; + delete pcdUserDto['otp']; + await this.pcduserRepository.save(pcdUserDto); + this.logger.verbose("User created with email:", pcdUserDto.email); + return { data: "Successfully Registered" }; + } async verifyOtp(body: { otp: string, email: string }, flag: string): Promise { console.log('body===', body, flag); - + const filter: FindManyOptions = { where: { "refCode": body.email, "status": "I" }, order: { code: "DESC" } }; - + const newOtp = await this.pcdotpRepository.find(filter); if (!newOtp) @@ -229,14 +415,14 @@ export class AuthService { let currentDateTime = new Date().valueOf(); let otpTime = newOtp[0].createdDate.valueOf(); let diffMs = (currentDateTime - otpTime); - let otpExpiry = 600000; //otp expire in 10 minutes + let otpExpiry = 600000; //otp expire in 10 minutes let diffMins = Math.round(((diffMs % 86400000) % 3600000) / 60000); if (diffMins > config.get('otp').expiresIn) throw new RequestTimeoutException('*OTP Expired'); - + if (diffMs > otpExpiry) throw new RequestTimeoutException('*OTP Expired'); @@ -246,29 +432,29 @@ export class AuthService { return { data: 'success' }; } - } + } // async resendOtp(body: { code?: string | number, email?: string, mobile: string }, flag: string): Promise { // // const newOtp = await this.generateOtp(body.code.toString(), 'RR'); // // await this.smsService.sendSms(body.mobile, ` Your one time password(OTP) for Accurate Application Registration is,${newOtp}`); // const isUserExist = await this.pcduserRepository.findOne({ where: { mobileNumber: body.mobile } }); // const newOtp = await this.generateOtp(isUserExist.userId.toString(), flag); - + // if (body.mobile) // await this.smsService.sendSms(body.mobile, newOtp); // } - + async generateOtp(refCode: string, flag: string): Promise { var otpGenerator = require('otp-generator') const newOtp = await otpGenerator.generate(6, { upperCase: false, specialChars: false, alphabets: false }); console.log("===newOtp====", newOtp); - + let usedFor: string = ''; - + switch (flag) { case "R": @@ -286,7 +472,7 @@ export class AuthService { } try { - + let igotp: PcdotpDto = new PcdotpDto(); igotp.otp = newOtp; igotp.createdBy = 'SYSTEM'; @@ -322,10 +508,10 @@ export class AuthService { return result; } - + private async hashPassword(password: string, salt: string): Promise { return await bcrypt.hash(password, salt); } - + } \ No newline at end of file diff --git a/src/email/email.service.ts b/src/email/email.service.ts index e07c236..835b68f 100644 --- a/src/email/email.service.ts +++ b/src/email/email.service.ts @@ -13,14 +13,12 @@ export class EmailService { async sendMail(toMail:string,subject:string,bodyText: string,htmlText:string){ this.mailerService.sendMail({ - to: toMail, // sender address - from: mail.fromMail, // list of receivers - subject: subject, // Subject line + to: toMail, // sender addressject: subject, // Subject line text: bodyText, // plaintext body html: htmlText, // HTML body content }) .then((res) => { - console.log("==== here==res==", res) + console.log("==== here==res==", res) }) .catch((err) => { console.log("=====err====", err); diff --git a/src/file-upload/file-upload.controller.ts b/src/file-upload/file-upload.controller.ts index 54448bc..da78207 100644 --- a/src/file-upload/file-upload.controller.ts +++ b/src/file-upload/file-upload.controller.ts @@ -13,6 +13,7 @@ import { join, extname } from 'path'; import { tenderDocRepository } from 'src/tables/tender-documents/tender-doc.repository'; import { TenderDocumentDto } from 'src/dto/tender-document.dto'; import { InjectRepository } from '@nestjs/typeorm'; +import { log } from 'console'; export function createFolders(filePath: string) { @@ -58,9 +59,8 @@ export class FileUploadController { return cb(null, childFolder); }, filename: (req, file, cb) => { - console.log('===here===file upload=='); - const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join(''); - return cb(null, `${randomName}${extname(file.originalname)}`); + // Use the original filename instead of generating a random name + return cb(null, `${file.originalname}`); } }) })) @@ -68,7 +68,7 @@ export class FileUploadController { if (!file) { return { error: 'No file uploaded.' }; } - //To return the size of the document in kb + // To return the size of the document in kb const fileSizeKB = Math.ceil(file.size / 1024); return { fileName: file.filename, filePath: file.path, fileSizeKB }; } @@ -88,9 +88,8 @@ export class FileUploadController { return cb(null, filePath); }, filename: (req, file, cb) => { - console.log('===here===file upload=='); - const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join(''); - return cb(null, `${randomName}${extname(file.originalname)}`); + // Use the original filename instead of generating a random name + return cb(null, `${file.originalname}`); } }) })) @@ -116,9 +115,8 @@ export class FileUploadController { return cb(null, filePath); }, filename: (req, file, cb) => { - console.log('===here===file upload=='); - const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join(''); - return cb(null, `${randomName}${extname(file.originalname)}`); + // Use the original filename instead of generating a random name + return cb(null, `${file.originalname}`); } }) })) @@ -243,9 +241,8 @@ async deleteNotice( return cb(null, filePath); }, filename: (req, file, cb) => { - console.log('===here===file upload=='); - const randomName = Array(32).fill(null).map(() => (Math.round(Math.random() * 16)).toString(16)).join(''); - return cb(null, `${randomName}${extname(file.originalname)}`); + // Use the original filename instead of generating a random name + return cb(null, `${file.originalname}`); } }) })) @@ -380,7 +377,13 @@ async deleteNotice( @Req() req, ) { const folderPath = path.join('./uploads/Drawings', id); + console.log(folderPath); + if (!fs.existsSync(folderPath)) { + console.log( + "helloo" + ); + res.status(404).send({ error: 'File not found' }); return; } diff --git a/src/tables/payment-master/payment-master.entity.ts b/src/tables/payment-master/payment-master.entity.ts index 6bcbda1..d1c05e7 100644 --- a/src/tables/payment-master/payment-master.entity.ts +++ b/src/tables/payment-master/payment-master.entity.ts @@ -29,7 +29,7 @@ export class PaymentMaster extends PcdBaseEntity{ type:"numeric", nullable:true, }) - transId:number + transId:number @Column({ name:"status", diff --git a/src/tables/payment-master/payment-master.service.ts b/src/tables/payment-master/payment-master.service.ts index f941224..a182ed2 100644 --- a/src/tables/payment-master/payment-master.service.ts +++ b/src/tables/payment-master/payment-master.service.ts @@ -3,7 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { PaymentMasterDto } from 'src/dto/payment-master.dto'; import { PcdFormGridService } from 'src/framework/beans/pcd-form-grid.service'; import { PaymentMasterRepository } from './payment-master.repository'; -import { log } from 'console'; + @Injectable() export class PaymentMasterService extends PcdFormGridService{ @@ -58,8 +58,6 @@ async finalBidAmt(tenderId ,userId,body){ }else{ throw new BadRequestException('Bid Amount Already Exist') } - - } } diff --git a/src/transactions/tender/tender.controller.ts b/src/transactions/tender/tender.controller.ts index a6af89c..faadaaf 100644 --- a/src/transactions/tender/tender.controller.ts +++ b/src/transactions/tender/tender.controller.ts @@ -15,7 +15,14 @@ export class TenderController extends PcdTransactionController @Get('admin') async getTender() { + return this.tenderService.GetAdminTenderD() } + @Get('admin/dashboard') + async getDashboard() { + + return this.tenderService.GetAdminDashboard() + } + } diff --git a/src/transactions/tender/tender.service.ts b/src/transactions/tender/tender.service.ts index 62f2f52..8e696c8 100644 --- a/src/transactions/tender/tender.service.ts +++ b/src/transactions/tender/tender.service.ts @@ -54,4 +54,8 @@ export class TenderService extends PcdTransactionService{ return this.tenderMasterRepository.find() } + async GetAdminDashboard(){ + let query = `select id, title , bid_open_date as bidOpenDate, publish_date as publishDate from tender_master tm ` + return this.tenderMasterRepository.query(query) + } }