Files
cedetec_api_nest/src/tyl/tyl.controller.ts
T

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-08-08 23:00:46 -06:00
import {
Body,
Controller,
InternalServerErrorException,
Post,
} from '@nestjs/common';
2026-08-03 11:14:41 -06:00
@Controller('tyl')
export class TylController {
2026-08-08 23:00:46 -06:00
@Post('')
async enviarTyl(@Body() body: { email: string }) {
2026-08-03 11:14:41 -06:00
try {
2026-08-08 23:00:46 -06:00
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(
2026-08-03 11:14:41 -06:00
'https://accede.estudio.app/ventas-acatlan',
{
2026-08-08 23:00:46 -06:00
method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// },
body: params,
redirect: 'manual',
},
);
2026-08-03 11:14:41 -06:00
2026-08-08 23:00:46 -06:00
console.log('respuesta', response);
2026-08-03 11:14:41 -06:00
2026-08-08 23:00:46 -06:00
const redirectUrl = response.headers.get('location');
2026-08-03 11:14:41 -06:00
2026-08-08 23:00:46 -06:00
console.log('redirect', redirectUrl);
2026-08-03 11:14:41 -06:00
2026-08-08 23:00:46 -06:00
return { redirectUrl };
2026-08-03 11:14:41 -06:00
} catch (error) {
2026-08-08 23:00:46 -06:00
throw new InternalServerErrorException(
'Error al conectar con API externa',
);
2026-08-03 11:14:41 -06:00
}
2026-08-08 23:00:46 -06:00
}
2026-08-03 11:14:41 -06:00
}