ticket
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
PORT=
|
||||
JWT_SECRET=
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
+6
-2
@@ -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<string>('DB_USER'),
|
||||
password: configService.get<string>('DB_PASSWORD'),
|
||||
database: configService.get<string>('DB_NAME'),
|
||||
entities: [User],
|
||||
entities: [User, Student],
|
||||
synchronize: false,
|
||||
}),
|
||||
}),
|
||||
UserModule,
|
||||
StudentModule,
|
||||
TicketModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class studentDto {
|
||||
@IsNumber()
|
||||
id_cuenta: number;
|
||||
}
|
||||
@@ -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({
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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<Student>,
|
||||
) {}
|
||||
findOne(data: studentDto) {
|
||||
const { id_cuenta } = data;
|
||||
return this.studenRepository.findOne({ where: { id_cuenta } });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 @@
|
||||
export class Ticket {}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+13
-14
@@ -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<User>,
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data:CreateUserDto): Promise<User> {
|
||||
|
||||
const { usuario, password } = data
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user