46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
InternalServerErrorException,
|
|
Post,
|
|
} from '@nestjs/common';
|
|
|
|
@Controller('tyl')
|
|
export class TylController {
|
|
@Post('')
|
|
async enviarTyl(@Body() body: { email: string }) {
|
|
try {
|
|
const user = 'acatlan';
|
|
const api = 'LW2rtatYP8o2PhCkIqeJV94d6a60cSvTmJXPbRpP';
|
|
const params = new URLSearchParams();
|
|
params.append('user_name', user!);
|
|
params.append('email', body.email);
|
|
params.append('api_key', process.env.API_KEY!);
|
|
|
|
const response = await fetch(
|
|
'https://accede.estudio.app/ventas-acatlan',
|
|
{
|
|
method: 'POST',
|
|
// headers: {
|
|
// 'Content-Type': 'application/x-www-form-urlencoded',
|
|
// },
|
|
body: params,
|
|
redirect: 'manual',
|
|
},
|
|
);
|
|
|
|
console.log('respuesta', response);
|
|
|
|
const redirectUrl = response.headers.get('location');
|
|
|
|
console.log('redirect', redirectUrl);
|
|
|
|
return { redirectUrl };
|
|
} catch (error) {
|
|
throw new InternalServerErrorException(
|
|
'Error al conectar con API externa',
|
|
);
|
|
}
|
|
}
|
|
}
|