This commit is contained in:
2025-09-10 16:15:36 -06:00
parent d9afbcd1e9
commit 70478f3fc3
16 changed files with 170 additions and 99 deletions
-7
View File
@@ -1,7 +0,0 @@
PORT=
JWT_SECRET=
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=
DB_NAME=
+6 -2
View File
@@ -6,11 +6,13 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { StudentModule } from './student/student.module'; import { StudentModule } from './student/student.module';
import { UserModule } from './user/user.module'; import { UserModule } from './user/user.module';
import { User } from './user/entities/user.entity'; import { User } from './user/entities/user.entity';
import { Student } from './student/entities/student.entity';
import { TicketModule } from './ticket/ticket.module';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot({ ConfigModule.forRoot({
isGlobal: true, isGlobal: true,
envFilePath: '.env', envFilePath: '.env',
}), }),
TypeOrmModule.forRootAsync({ TypeOrmModule.forRootAsync({
@@ -22,11 +24,13 @@ import { User } from './user/entities/user.entity';
username: configService.get<string>('DB_USER'), username: configService.get<string>('DB_USER'),
password: configService.get<string>('DB_PASSWORD'), password: configService.get<string>('DB_PASSWORD'),
database: configService.get<string>('DB_NAME'), database: configService.get<string>('DB_NAME'),
entities: [User], entities: [User, Student],
synchronize: false, synchronize: false,
}), }),
}), }),
UserModule, UserModule,
StudentModule,
TicketModule,
], ],
controllers: [AppController], controllers: [AppController],
providers: [AppService], providers: [AppService],
+6
View File
@@ -0,0 +1,6 @@
import { IsNumber, IsString } from 'class-validator';
export class studentDto {
@IsNumber()
id_cuenta: number;
}
+15 -5
View File
@@ -1,21 +1,31 @@
import { Column, Entity, PrimaryColumn } from "typeorm"; import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
@Entity({ name: 'alumno' }) @Entity({ name: 'alumno' })
export class Student { export class Student {
@PrimaryGeneratedColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
@PrimaryColumn({ name: 'id_cuenta', type: 'int', unsigned: true })
id_cuenta: number; id_cuenta: number;
@Column({ name: 'nombre', type: 'varchar', length: 300, nullable: false }) @Column({ name: 'nombre', type: 'varchar', length: 300, nullable: false })
nombre: string; 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; fecha_nacimiento: string | null;
@Column({ name: 'correo', type: 'varchar', length: 100, nullable: true }) @Column({ name: 'correo', type: 'varchar', length: 100, nullable: true })
correo: string | null; 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; credito: string;
@Column({ @Column({
+12 -23
View File
@@ -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 { StudentService } from './student.service';
import { CreateStudentDto } from './dto/create-student.dto'; import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto'; import { UpdateStudentDto } from './dto/update-student.dto';
import { studentDto } from './dto/student.dto';
@Controller('student') @Controller('student')
export class StudentController { export class StudentController {
constructor(private readonly studentService: StudentService) {} constructor(private readonly studentService: StudentService) {}
@Post() @Post()
create(@Body() createStudentDto: CreateStudentDto) { create(@Body() data: studentDto) {
return this.studentService.create(createStudentDto); return this.studentService.findOne(data);
}
@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);
} }
} }
+4
View File
@@ -1,9 +1,13 @@
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { StudentService } from './student.service'; import { StudentService } from './student.service';
import { StudentController } from './student.controller'; import { StudentController } from './student.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Student } from './entities/student.entity';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([Student])],
controllers: [StudentController], controllers: [StudentController],
providers: [StudentService], providers: [StudentService],
exports: [StudentService],
}) })
export class StudentModule {} export class StudentModule {}
+12 -19
View File
@@ -1,26 +1,19 @@
import { Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { CreateStudentDto } from './dto/create-student.dto'; import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-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() @Injectable()
export class StudentService { export class StudentService {
create(createStudentDto: CreateStudentDto) { constructor(
return 'This action adds a new student'; @InjectRepository(Student)
} private studenRepository: Repository<Student>,
) {}
findAll() { findOne(data: studentDto) {
return `This action returns all student`; const { id_cuenta } = data;
} return this.studenRepository.findOne({ where: { id_cuenta } });
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`;
} }
} }
+1
View File
@@ -0,0 +1 @@
export class CreateTicketDto {}
+4
View File
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateTicketDto } from './create-ticket.dto';
export class UpdateTicketDto extends PartialType(CreateTicketDto) {}
+1
View File
@@ -0,0 +1 @@
export class Ticket {}
+34
View File
@@ -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);
}
}
+9
View File
@@ -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 {}
+26
View File
@@ -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`;
}
}
+5 -6
View File
@@ -1,10 +1,9 @@
import { IsString } from "class-validator"; import { IsString } from 'class-validator';
export class CreateUserDto { export class CreateUserDto {
@IsString()
usuario: string;
@IsString() @IsString()
usuario:string password: string;
@IsString()
password:string
} }
+22 -23
View File
@@ -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 { export class User {
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
id_usuario: number;
@PrimaryGeneratedColumn({name:'id_usuario',type: 'int'}) @Column({ name: 'nombre', type: 'varchar' })
id_usuario:number; nombre: string;
@Column({name:'nombre',type:'varchar'}) @Column({ name: 'apellido_paterno', type: 'varchar' })
nombre:string apellido_paterno: string;
@Column({name:'apellido_paterno',type:'varchar'}) @Column({ name: 'apellido_materno', type: 'varchar' })
apellido_paterno:string apellido_materno: string;
@Column({name:'apellido_materno',type:'varchar'}) @Column({ name: 'usuario', type: 'varchar' })
apellido_materno:string usuario: string;
@Column({name:'usuario',type:'varchar'}) @Column({ name: 'password', type: 'varchar', length: 45, nullable: false })
usuario:string password: string;
@Column({name:'password',type:'varchar',length:45, nullable:false}) @Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 })
password:string activo: number;
@Column({name:'activo',type:'tinyint',nullable:false, default:1}) @Column({ name: 'descripcion', type: 'varchar', length: 50, default: null })
activo: number description: boolean;
@Column({name:'descripcion',type:'varchar',length:50,default:null}) @Column({ name: 'fecha_registro', type: 'varchar' })
description:boolean fecha_registro: string;
@Column({name:'fecha_registro',type:'varchar'}) @Column({ name: 'id_perfil' })
fecha_registro:string id_perfil: number;
@Column({name:'id_perfil',})
id_perfil:number
} }
+13 -14
View File
@@ -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 { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto'; import { UpdateUserDto } from './dto/update-user.dto';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
@@ -10,29 +15,23 @@ export class UserService {
constructor( constructor(
@InjectRepository(User) @InjectRepository(User)
private userRepository: Repository<User>, private userRepository: Repository<User>,
) { } ) {}
async findOneByNameandPassword(data:CreateUserDto): Promise<User> { async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
const { usuario, password } = data;
const { usuario, password } = data
const user = await this.userRepository.findOne({ const user = await this.userRepository.findOne({
where: { usuario,password } where: { usuario, password },
}) });
if (!user) { if (!user) {
throw new NotFoundException( throw new NotFoundException(`El usuario ${usuario} no fue encontrado`);
`El usuario ${usuario} no fue encontrado`,
);
} }
return user; return user;
} }
async Login(data: CreateUserDto) { async Login(data: CreateUserDto) {
return await this.findOneByNameandPassword(data);
const user = await this.findOneByNameandPassword(data);
return user
} }
} }