Se completo la confirmacion =) yupi

This commit is contained in:
2023-03-07 17:39:55 -06:00
parent fdd2dc679c
commit 6618e79a86
3 changed files with 76 additions and 84 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ PORT=5089
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=Dosmiluno2001
DB_PASSWORD=password
DB_NAME=cedetec_proyectos
DB_PORT=3306
@@ -1,9 +1,6 @@
import {
Body,
Controller,
Get,
Param,
ParseIntPipe,
Post,
} from '@nestjs/common';
import { InscripcionDscService } from './inscripcion-dsc.service';
@@ -16,22 +13,23 @@ export class InscripcionDscController {
async confirmacionDsc(@Body() body: any) {
const { accountNumber } = body;
this.inscripcionService.userVerification(accountNumber)
const userVerification = await this.inscripcionService.userVerification(accountNumber);
/* console.log(userVerification) */
if(!userVerification){
return {
error: true,
msj: 'El usuario no se encuentra inscrito',
desc: '',
};
}
/* try {
const userVerificationResponse =
await this.inscripcionService.userVerification(accountNumber);
console.log(userVerificationResponse);
if (userVerificationResponse.length === 0) {
return {
error: true,
msj: 'El usuario no se encuentra inscrito',
desc: '',
};
}
const [userInformation] = userVerificationResponse;
console.log(userInformation);
if (userInformation.confirmacion) {
const userInformation = userVerification;
/* console.log(userInformation[0].confirmacion) */
try{
/* console.log("verificando confirmacion:", userInformation);
*/ if (userInformation[0].confirmacion) {
return {
error: true,
msj: 'El usuario ya hizo la confirmación anteriormente',
@@ -41,9 +39,10 @@ export class InscripcionDscController {
} catch (err) {
return console.log(err);
}
try {
const confirmationResponse =
await this.inscripcionService.userConfirmation({ accountNumber });
await this.inscripcionService.userConfirmation(accountNumber);
return {
error: false,
msj: 'Usuario confirmado exitosamente',
@@ -55,6 +54,6 @@ export class InscripcionDscController {
msj: `No se pudo realizar la confirmación del usuario`,
desc: `${err}`,
};
} */
}
}
}
+56 -63
View File
@@ -1,90 +1,83 @@
import { Injectable } from '@nestjs/common';
import { createConnection } from 'mysql2/promise';
@Injectable()
export class InscripcionDscService {
async userVerification(accountNumber: string): Promise<any> {
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: process.env.DB_HOST_DSC,
user: process.env.DB_USER_DSC,
password: process.env.DB_PASS_DSC,
database: process.env.DB_NAME_DSC,
});
const userInformationQuery = `SELECT A.id_cuenta, nombre, if(AI.platica=true,1,0) as confirmacion FROM alumno A
JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta)
JOIN periodo P ON (P.id_periodo = AI.id_periodo)
WHERE A.id_cuenta = "${accountNumber}" and P.activo=true`;
connection.connect();
connection.query('SELECT * FROM alumno;', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results);
});
connection.end();
/*
async userVerification(accountNumber: string) {
try {
const connection = await createConnection({
host: process.env.DB_HOST_DSC,
user: process.env.DB_USER_DSC,
password: process.env.DB_PASS_DSC,
database: process.env.DB_NAME_DSC,
});
this.validarNumeroCuenta(accountNumber); //valida que el numero de cuenta sea string y menor a 9 digitos
const userInformationQuery = `SELECT A.id_cuenta, nombre, if(AI.platica=true,1,0) as confirmacion FROM alumno A
JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta)
JOIN periodo P ON (P.id_periodo = AI.id_periodo)
WHERE A.id_cuenta = "${accountNumber}" and P.activo=true`;
const qryEjemplo = `SELECT * FROM alumno WHERE id_cuenta="${accountNumber}";`;
const [results] = await connection.query(userInformationQuery);
const resultsArray = JSON.parse(JSON.stringify(results));
if (resultsArray.length === 0) return null;
/* console.log('The solution is: ', resultsArray); */
return results;
} catch (error) {
throw error;
}
const userInformationQuery = `SELECT A.id_cuenta, nombre, if(AI.platica=true,1,0) as confirmacion FROM alumno A
JOIN alumno_inscrito AI ON (A.id_cuenta = AI.id_cuenta)
JOIN periodo P ON (P.id_periodo = AI.id_periodo)
WHERE A.id_cuenta = "${accountNumber}" and P.activo=true`;
}
async userConfirmation(accountNumber: string): Promise<any> {
try {
const responseUserInformation = await this.sybaseService.queryDsc(
userInformationQuery,
);
console.log(responseUserInformation)
return responseUserInformation;
const connection = await createConnection({
host: process.env.DB_HOST_DSC,
user: process.env.DB_USER_DSC,
password: process.env.DB_PASS_DSC,
database: process.env.DB_NAME_DSC,
});
const userInformationQuery = `UPDATE alumno_inscrito SET platica=true
WHERE id_cuenta="${accountNumber}" and id_periodo=(SELECT id_periodo FROM periodo WHERE activo=true)`;
const qryEjemplo = `select platica from alumno_inscrito WHERE id_cuenta="${accountNumber}"`;
const [results] = await connection.query(qryEjemplo);
const resultsArray = JSON.parse(JSON.stringify(results));
if (resultsArray.length === 0) return null;
/* console.log('The solution is: ', resultsArray); */
return results;
} catch (error) {
throw error;
} */
}
validarNumeroCuenta = (numeroCuenta) => {
if (typeof numeroCuenta !== 'string' || numeroCuenta.length > 9)
return numeroCuenta;
};
async userConfirmation(data: { accountNumber: string }): Promise<any> {
const mysql = require('mysql2');
const connection = mysql.createConnection({
host: process.env.DB_HOST_DSC,
user: process.env.DB_USER_DSC,
password: process.env.DB_PASS_DSC,
database: process.env.DB_NAME_DSC,
});
const { accountNumber } = data;
}
/* const { accountNumber } = data;
try {
this.validarNumeroCuenta(accountNumber);
} catch (error) {
throw error;
}
let userConfirmationQuery = `UPDATE alumno_inscrito SET platica=true
WHERE id_cuenta="${accountNumber}" and id_periodo=(SELECT id_periodo FROM periodo WHERE activo=true)`;
WHERE id_cuenta="${accountNumber}" and id_periodo=(SELECT id_periodo FROM periodo WHERE activo=true)`;
try {
const responseUserConfirmation = await connection.query(
userConfirmationQuery,
);
return responseUserConfirmation;
} catch (error) {
throw error;
}
);
return responseUserConfirmation;
} catch (error) {
throw error;
}
} */
}
validarNumeroCuenta = (numeroCuenta) => {
if (typeof numeroCuenta !== 'string' || numeroCuenta.length > 9)
return numeroCuenta;
};
}