84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { createConnection } from 'mysql2/promise';
|
|
|
|
@Injectable()
|
|
export class InscripcionDscService {
|
|
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,
|
|
});
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
async userConfirmation(accountNumber: string): Promise<any> {
|
|
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,
|
|
});
|
|
|
|
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(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 { 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)`;
|
|
|
|
try {
|
|
const responseUserConfirmation = await connection.query(
|
|
userConfirmationQuery,
|
|
);
|
|
return responseUserConfirmation;
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
} */
|
|
}
|
|
|
|
validarNumeroCuenta = (numeroCuenta) => {
|
|
if (typeof numeroCuenta !== 'string' || numeroCuenta.length > 9)
|
|
return numeroCuenta;
|
|
};
|
|
}
|