From 70478f3fc32e0e8b20a7e678d718bb2c73315f78 Mon Sep 17 00:00:00 2001 From: CarlosssFlores <307100636@pcpuma.acatlan.unam.mx> Date: Wed, 10 Sep 2025 16:15:36 -0600 Subject: [PATCH] ticket --- .example | 7 ---- src/app.module.ts | 8 +++-- src/student/dto/student.dto.ts | 6 ++++ src/student/entities/student.entity.ts | 20 +++++++++--- src/student/student.controller.ts | 35 +++++++------------- src/student/student.module.ts | 4 +++ src/student/student.service.ts | 31 +++++++----------- src/ticket/dto/create-ticket.dto.ts | 1 + src/ticket/dto/update-ticket.dto.ts | 4 +++ src/ticket/entities/ticket.entity.ts | 1 + src/ticket/ticket.controller.ts | 34 +++++++++++++++++++ src/ticket/ticket.module.ts | 9 ++++++ src/ticket/ticket.service.ts | 26 +++++++++++++++ src/user/dto/create-user.dto.ts | 11 +++---- src/user/entities/user.entity.ts | 45 +++++++++++++------------- src/user/user.service.ts | 27 ++++++++-------- 16 files changed, 170 insertions(+), 99 deletions(-) delete mode 100644 .example create mode 100644 src/student/dto/student.dto.ts create mode 100644 src/ticket/dto/create-ticket.dto.ts create mode 100644 src/ticket/dto/update-ticket.dto.ts create mode 100644 src/ticket/entities/ticket.entity.ts create mode 100644 src/ticket/ticket.controller.ts create mode 100644 src/ticket/ticket.module.ts create mode 100644 src/ticket/ticket.service.ts diff --git a/.example b/.example deleted file mode 100644 index 34af4b9..0000000 --- a/.example +++ /dev/null @@ -1,7 +0,0 @@ -PORT= -JWT_SECRET= -DB_HOST= -DB_PORT= -DB_USER= -DB_PASSWORD= -DB_NAME= \ No newline at end of file diff --git a/src/app.module.ts b/src/app.module.ts index cba0638..facbc4a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,11 +6,13 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { StudentModule } from './student/student.module'; import { UserModule } from './user/user.module'; import { User } from './user/entities/user.entity'; +import { Student } from './student/entities/student.entity'; +import { TicketModule } from './ticket/ticket.module'; @Module({ imports: [ ConfigModule.forRoot({ - isGlobal: true, + isGlobal: true, envFilePath: '.env', }), TypeOrmModule.forRootAsync({ @@ -22,11 +24,13 @@ import { User } from './user/entities/user.entity'; username: configService.get('DB_USER'), password: configService.get('DB_PASSWORD'), database: configService.get('DB_NAME'), - entities: [User], + entities: [User, Student], synchronize: false, }), }), UserModule, + StudentModule, + TicketModule, ], controllers: [AppController], providers: [AppService], diff --git a/src/student/dto/student.dto.ts b/src/student/dto/student.dto.ts new file mode 100644 index 0000000..0abde95 --- /dev/null +++ b/src/student/dto/student.dto.ts @@ -0,0 +1,6 @@ +import { IsNumber, IsString } from 'class-validator'; + +export class studentDto { + @IsNumber() + id_cuenta: number; +} diff --git a/src/student/entities/student.entity.ts b/src/student/entities/student.entity.ts index cf56a28..a375e94 100644 --- a/src/student/entities/student.entity.ts +++ b/src/student/entities/student.entity.ts @@ -1,21 +1,31 @@ -import { Column, Entity, PrimaryColumn } from "typeorm"; +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; @Entity({ name: 'alumno' }) export class Student { - - @PrimaryColumn({ name: 'id_cuenta', type: 'int', unsigned: true }) + @PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true }) id_cuenta: number; @Column({ name: 'nombre', type: 'varchar', length: 300, nullable: false }) nombre: string; - @Column({ name: 'fecha_nacimiento', type: 'varchar', length: 8, nullable: true }) + @Column({ + name: 'fecha_nacimiento', + type: 'varchar', + length: 8, + nullable: true, + }) fecha_nacimiento: string | null; @Column({ name: 'correo', type: 'varchar', length: 100, nullable: true }) correo: string | null; - @Column({ name: 'credito', type: 'decimal', precision: 10, scale: 2, default: 0.00 }) + @Column({ + name: 'credito', + type: 'decimal', + precision: 10, + scale: 2, + default: 0.0, + }) credito: string; @Column({ diff --git a/src/student/student.controller.ts b/src/student/student.controller.ts index 8f8e5b6..4e2d1e9 100644 --- a/src/student/student.controller.ts +++ b/src/student/student.controller.ts @@ -1,34 +1,23 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; +import { + Controller, + Get, + Post, + Body, + Patch, + Param, + Delete, +} from '@nestjs/common'; import { StudentService } from './student.service'; import { CreateStudentDto } from './dto/create-student.dto'; import { UpdateStudentDto } from './dto/update-student.dto'; +import { studentDto } from './dto/student.dto'; @Controller('student') export class StudentController { constructor(private readonly studentService: StudentService) {} @Post() - create(@Body() createStudentDto: CreateStudentDto) { - return this.studentService.create(createStudentDto); - } - - @Get() - findAll() { - return this.studentService.findAll(); - } - - @Get(':id') - findOne(@Param('id') id: string) { - return this.studentService.findOne(+id); - } - - @Patch(':id') - update(@Param('id') id: string, @Body() updateStudentDto: UpdateStudentDto) { - return this.studentService.update(+id, updateStudentDto); - } - - @Delete(':id') - remove(@Param('id') id: string) { - return this.studentService.remove(+id); + create(@Body() data: studentDto) { + return this.studentService.findOne(data); } } diff --git a/src/student/student.module.ts b/src/student/student.module.ts index 1c61ccb..f6dcbf7 100644 --- a/src/student/student.module.ts +++ b/src/student/student.module.ts @@ -1,9 +1,13 @@ import { Module } from '@nestjs/common'; import { StudentService } from './student.service'; import { StudentController } from './student.controller'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { Student } from './entities/student.entity'; @Module({ + imports: [TypeOrmModule.forFeature([Student])], controllers: [StudentController], providers: [StudentService], + exports: [StudentService], }) export class StudentModule {} diff --git a/src/student/student.service.ts b/src/student/student.service.ts index 9e81073..1c862f9 100644 --- a/src/student/student.service.ts +++ b/src/student/student.service.ts @@ -1,26 +1,19 @@ -import { Injectable } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { CreateStudentDto } from './dto/create-student.dto'; import { UpdateStudentDto } from './dto/update-student.dto'; +import { studentDto } from './dto/student.dto'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Student } from './entities/student.entity'; +import { Repository } from 'typeorm'; @Injectable() export class StudentService { - create(createStudentDto: CreateStudentDto) { - return 'This action adds a new student'; - } - - findAll() { - return `This action returns all student`; - } - - findOne(id: number) { - return `This action returns a #${id} student`; - } - - update(id: number, updateStudentDto: UpdateStudentDto) { - return `This action updates a #${id} student`; - } - - remove(id: number) { - return `This action removes a #${id} student`; + constructor( + @InjectRepository(Student) + private studenRepository: Repository, + ) {} + findOne(data: studentDto) { + const { id_cuenta } = data; + return this.studenRepository.findOne({ where: { id_cuenta } }); } } 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..947e603 --- /dev/null +++ b/src/ticket/entities/ticket.entity.ts @@ -0,0 +1 @@ +export class Ticket {} 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/entities/user.entity.ts b/src/user/entities/user.entity.ts index f3bbb28..c07aa4e 100644 --- a/src/user/entities/user.entity.ts +++ b/src/user/entities/user.entity.ts @@ -1,35 +1,34 @@ -import { Column, Entity, PrimaryGeneratedColumn } from "typeorm"; +import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'; -@Entity({name:'usuario'}) +@Entity({ name: 'usuario' }) export class User { + @PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' }) + id_usuario: number; - @PrimaryGeneratedColumn({name:'id_usuario',type: 'int'}) - id_usuario:number; + @Column({ name: 'nombre', type: 'varchar' }) + nombre: string; - @Column({name:'nombre',type:'varchar'}) - nombre:string + @Column({ name: 'apellido_paterno', type: 'varchar' }) + apellido_paterno: string; - @Column({name:'apellido_paterno',type:'varchar'}) - apellido_paterno:string + @Column({ name: 'apellido_materno', type: 'varchar' }) + apellido_materno: string; - @Column({name:'apellido_materno',type:'varchar'}) - apellido_materno:string + @Column({ name: 'usuario', type: 'varchar' }) + usuario: string; - @Column({name:'usuario',type:'varchar'}) - usuario:string + @Column({ name: 'password', type: 'varchar', length: 45, nullable: false }) + password: string; - @Column({name:'password',type:'varchar',length:45, nullable:false}) - password:string + @Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 }) + activo: number; - @Column({name:'activo',type:'tinyint',nullable:false, default:1}) - activo: number + @Column({ name: 'descripcion', type: 'varchar', length: 50, default: null }) + description: boolean; - @Column({name:'descripcion',type:'varchar',length:50,default:null}) - description:boolean + @Column({ name: 'fecha_registro', type: 'varchar' }) + fecha_registro: string; - @Column({name:'fecha_registro',type:'varchar'}) - fecha_registro:string - - @Column({name:'id_perfil',}) - id_perfil:number + @Column({ name: 'id_perfil' }) + id_perfil: number; } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 83c581b..0c22671 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -1,4 +1,9 @@ -import { Injectable, Logger, NotFoundException, UnauthorizedException } from '@nestjs/common'; +import { + Injectable, + Logger, + NotFoundException, + UnauthorizedException, +} from '@nestjs/common'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; import { InjectRepository } from '@nestjs/typeorm'; @@ -10,29 +15,23 @@ export class UserService { constructor( @InjectRepository(User) private userRepository: Repository, - ) { } + ) {} - async findOneByNameandPassword(data:CreateUserDto): Promise { - - const { usuario, password } = data + async findOneByNameandPassword(data: CreateUserDto): Promise { + const { usuario, password } = data; const user = await this.userRepository.findOne({ - where: { usuario,password } - }) + where: { usuario, password }, + }); if (!user) { - throw new NotFoundException( - `El usuario ${usuario} no fue encontrado`, - ); + throw new NotFoundException(`El usuario ${usuario} no fue encontrado`); } return user; } async Login(data: CreateUserDto) { - - const user = await this.findOneByNameandPassword(data); - return user + return await this.findOneByNameandPassword(data); } - }