se agregó implementacion de Api para ampliación
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Almacenamiento } from '../entities/almacenamiento.entity';
|
||||
import { Almacenamiento } from './entity/almacenamiento.entity';
|
||||
import { AlmacenamientoService } from './almacenamiento.service';
|
||||
import { AlmacenamientoController } from './almacenamiento.controller';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Almacenamiento } from '../entities/almacenamiento.entity';
|
||||
import { Almacenamiento } from './entity/almacenamiento.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AlmacenamientoService {
|
||||
@@ -11,13 +11,36 @@ export class AlmacenamientoService {
|
||||
) {}
|
||||
|
||||
// Example method to create a new record
|
||||
async create(correo: string): Promise<Almacenamiento> {
|
||||
async create(correo: string): Promise<void> {
|
||||
const existente = await this.almacenamientoRepository.findOneBy({ correo });
|
||||
if (existente) {
|
||||
return existente; // o lanzar un error si prefieres
|
||||
if (!existente) {
|
||||
throw new Error("Este usuario no tiene acceso")
|
||||
}
|
||||
const nuevo = this.almacenamientoRepository.create({ correo });
|
||||
return this.almacenamientoRepository.save(nuevo);
|
||||
const apiUrl = process.env.API_URL;
|
||||
|
||||
const entrada = {
|
||||
user_name: "acatlan",
|
||||
email: correo
|
||||
};
|
||||
|
||||
try{
|
||||
let resonse= fetch(apiUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${process.env.TOKEN}`
|
||||
|
||||
},
|
||||
body: JSON.stringify(entrada)
|
||||
})
|
||||
|
||||
return
|
||||
|
||||
}catch(error){
|
||||
throw new Error(error)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Example method to get all records
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
@Entity('almacenamiento')
|
||||
export class Almacenamiento {
|
||||
@PrimaryGeneratedColumn({ type: 'int', name: 'id_almacenamiento' })
|
||||
idAlmacenamiento: number;
|
||||
|
||||
@Column('varchar', { name: 'correo', length: 100 })
|
||||
correo: string;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user