diff --git a/.example.txt b/.example.txt deleted file mode 100644 index b71fadf..0000000 --- a/.example.txt +++ /dev/null @@ -1,8 +0,0 @@ -PORT= -JWT_SECRET= -DB_HOST= -DB_PORT= -DB_USER= -DB_PASSWORD= -DB_NAME= -Front_URL= \ No newline at end of file diff --git a/src/ticket/dto/create-ticket.dto.ts b/src/ticket/dto/create-ticket.dto.ts new file mode 100644 index 0000000..921b819 --- /dev/null +++ b/src/ticket/dto/create-ticket.dto.ts @@ -0,0 +1 @@ +export class CreateTicketDto {} diff --git a/src/ticket/dto/update-ticket.dto.ts b/src/ticket/dto/update-ticket.dto.ts new file mode 100644 index 0000000..efaf3aa --- /dev/null +++ b/src/ticket/dto/update-ticket.dto.ts @@ -0,0 +1,4 @@ +import { PartialType } from '@nestjs/mapped-types'; +import { CreateTicketDto } from './create-ticket.dto'; + +export class UpdateTicketDto extends PartialType(CreateTicketDto) {} diff --git a/src/ticket/entities/ticket.entity.ts b/src/ticket/entities/ticket.entity.ts new file mode 100644 index 0000000..7e41380 --- /dev/null +++ b/src/ticket/entities/ticket.entity.ts @@ -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; +} diff --git a/src/ticket/ticket.controller.ts b/src/ticket/ticket.controller.ts new file mode 100644 index 0000000..92f458b --- /dev/null +++ b/src/ticket/ticket.controller.ts @@ -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); + } +} diff --git a/src/ticket/ticket.module.ts b/src/ticket/ticket.module.ts new file mode 100644 index 0000000..2790566 --- /dev/null +++ b/src/ticket/ticket.module.ts @@ -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 {} diff --git a/src/ticket/ticket.service.ts b/src/ticket/ticket.service.ts new file mode 100644 index 0000000..e4d322a --- /dev/null +++ b/src/ticket/ticket.service.ts @@ -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`; + } +} diff --git a/src/user/dto/create-user.dto.ts b/src/user/dto/create-user.dto.ts index 64c7d6c..172f9f9 100644 --- a/src/user/dto/create-user.dto.ts +++ b/src/user/dto/create-user.dto.ts @@ -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; } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 55883b0..c65627c 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -10,42 +10,25 @@ import { JwtService } from '@nestjs/jwt'; export class UserService { constructor( @InjectRepository(User) - private readonly userRepository: Repository, - - private jwtService: JwtService - ) { } + private userRepository: Repository, + ) {} async findOneByNameandPassword(data: CreateUserDto): Promise { - - 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; } - }