merge all
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
PORT=
|
||||
JWT_SECRET=
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
Front_URL=
|
||||
@@ -0,0 +1 @@
|
||||
export class CreateTicketDto {}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateTicketDto } from './create-ticket.dto';
|
||||
|
||||
export class UpdateTicketDto extends PartialType(CreateTicketDto) {}
|
||||
@@ -0,0 +1,50 @@
|
||||
export class Ticket {}
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
|
||||
@Entity({ name: 'recibo' })
|
||||
export class Recibo {
|
||||
@PrimaryGeneratedColumn({ name: 'id_recibo', type: 'int' })
|
||||
id_recibo: number;
|
||||
|
||||
@Column({
|
||||
name: 'folio_recibo',
|
||||
type: 'varchar',
|
||||
length: 45,
|
||||
nullable: false,
|
||||
})
|
||||
folio_recibo: string;
|
||||
|
||||
@Column({
|
||||
name: 'monto',
|
||||
type: 'decimal',
|
||||
nullable: false,
|
||||
})
|
||||
monto: number;
|
||||
|
||||
@Column({ name: 'fecha_recibo', type: 'date', nullable: false })
|
||||
fecha_recibo: Date | null;
|
||||
|
||||
@Column({
|
||||
name: 'id_cuenta',
|
||||
type: 'int',
|
||||
})
|
||||
id_cuenta: number;
|
||||
|
||||
@Column({
|
||||
name: 'id_usuario',
|
||||
type: 'int',
|
||||
nullable: false,
|
||||
})
|
||||
id_usuario: number;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.id_usuario, {})
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
user: User;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { UpdateTicketDto } from './dto/update-ticket.dto';
|
||||
|
||||
@Controller('ticket')
|
||||
export class TicketController {
|
||||
constructor(private readonly ticketService: TicketService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createTicketDto: CreateTicketDto) {
|
||||
return this.ticketService.create(createTicketDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.ticketService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.ticketService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateTicketDto: UpdateTicketDto) {
|
||||
return this.ticketService.update(+id, updateTicketDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.ticketService.remove(+id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { TicketController } from './ticket.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [TicketController],
|
||||
providers: [TicketService],
|
||||
})
|
||||
export class TicketModule {}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CreateTicketDto } from './dto/create-ticket.dto';
|
||||
import { UpdateTicketDto } from './dto/update-ticket.dto';
|
||||
|
||||
@Injectable()
|
||||
export class TicketService {
|
||||
create(createTicketDto: CreateTicketDto) {
|
||||
return 'This action adds a new ticket';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all ticket`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} ticket`;
|
||||
}
|
||||
|
||||
update(id: number, updateTicketDto: UpdateTicketDto) {
|
||||
return `This action updates a #${id} ticket`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} ticket`;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { IsString } from "class-validator";
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
usuario:string
|
||||
|
||||
@IsString()
|
||||
password:string
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -10,42 +10,25 @@ import { JwtService } from '@nestjs/jwt';
|
||||
export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
|
||||
private jwtService: JwtService
|
||||
) { }
|
||||
private userRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
|
||||
const { usuario, password } = data
|
||||
const { usuario, password } = data;
|
||||
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { usuario, password }
|
||||
})
|
||||
where: { usuario, password },
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException(
|
||||
`El usuario o la contraseña es incorrecta`,
|
||||
);
|
||||
throw new NotFoundException(`El usuario ${usuario} no fue encontrado`);
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto, res: Response) {
|
||||
async Login(data: CreateUserDto) {
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
|
||||
const payload = { id: user.id_usuario, usuario: user.usuario };
|
||||
const token = await this.jwtService.signAsync(payload);
|
||||
|
||||
res.cookie('token', token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production', // en dev desactívalo
|
||||
sameSite: 'strict',
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return res.json({ message: 'Inicio de sesión exitoso' });
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user