create alumno
This commit is contained in:
@@ -12,14 +12,9 @@ export class AlumnoController {
|
||||
return this.alumnoService.create(createStudentDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
async findAll(): Promise<Alumno[]> {
|
||||
return this.alumnoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.alumnoService.findOne(+id);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -17,17 +17,15 @@ export class AlumnoService {
|
||||
return await this.studentRepository.save(student);
|
||||
}
|
||||
|
||||
findAll(): Promise<Alumno[]> {
|
||||
return this.studentRepository.find({ skip: 5000, take: 50 });
|
||||
}
|
||||
|
||||
async findOne(id_cuenta: number): Promise<Alumno> {
|
||||
const student = await this.studentRepository.findOne({
|
||||
where: { id_cuenta },
|
||||
where: { id_cuenta: id_cuenta },
|
||||
});
|
||||
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student not found`);
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
|
||||
@@ -50,11 +48,7 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
|
||||
async addCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
) {
|
||||
async addCredit(id_cuenta: number, credit: number, manager: EntityManager) {
|
||||
const repo = manager.getRepository(Alumno);
|
||||
return await repo
|
||||
.createQueryBuilder()
|
||||
@@ -64,4 +58,4 @@ export class AlumnoService {
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -1,34 +1,11 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Param } from '@nestjs/common';
|
||||
import { SancionService } from './sancion.service';
|
||||
import { CreateSancionDto } from './dto/create-sancion.dto';
|
||||
import { UpdateSancionDto } from './dto/update-sancion.dto';
|
||||
|
||||
@Controller('sancion')
|
||||
export class SancionController {
|
||||
constructor(private readonly sancionService: SancionService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createSancionDto: CreateSancionDto) {
|
||||
return this.sancionService.create(createSancionDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.sancionService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
findOne(@Param('id') id: number) {
|
||||
return this.sancionService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateSancionDto: UpdateSancionDto) {
|
||||
return this.sancionService.update(+id, updateSancionDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.sancionService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateSancionDto } from './dto/create-sancion.dto';
|
||||
import { UpdateSancionDto } from './dto/update-sancion.dto';
|
||||
import { Sancion } from './entities/sancion.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
@@ -9,15 +7,8 @@ import { Repository } from 'typeorm';
|
||||
export class SancionService {
|
||||
constructor(
|
||||
@InjectRepository(Sancion)
|
||||
private readonly sancionRepository: Repository<Sancion>
|
||||
){}
|
||||
create(createSancionDto: CreateSancionDto) {
|
||||
return 'This action adds a new sancion';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all sancion`;
|
||||
}
|
||||
private readonly sancionRepository: Repository<Sancion>,
|
||||
) {}
|
||||
|
||||
async findOne(id_sancion: number): Promise<Sancion> {
|
||||
const sancion = await this.sancionRepository.findOne({
|
||||
@@ -28,13 +19,5 @@ export class SancionService {
|
||||
}
|
||||
return sancion;
|
||||
}
|
||||
|
||||
update(id: number, updateSancionDto: UpdateSancionDto) {
|
||||
return `This action updates a #${id} sancion`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} sancion`;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
@@ -1,9 +1,57 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import {
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
export class Login {
|
||||
@IsString()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
password: string;
|
||||
}
|
||||
|
||||
export class CreateUserDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
nombre: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
apellido_paterno: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
apellido_materno?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
usuario: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MinLength(6)
|
||||
@MaxLength(45)
|
||||
password: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
activo?: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@MaxLength(50)
|
||||
descripcion?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
fecha_registro?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsNotEmpty()
|
||||
id_perfil: number;
|
||||
}
|
||||
|
||||
@@ -26,38 +26,54 @@ export class User {
|
||||
@PrimaryGeneratedColumn({ name: 'id_usuario', type: 'int' })
|
||||
id_usuario: number;
|
||||
|
||||
@Column({ name: 'nombre', type: 'varchar' })
|
||||
@Column({ name: 'nombre', type: 'varchar', length: 45, nullable: false })
|
||||
nombre: string;
|
||||
|
||||
@Column({ name: 'apellido_paterno', type: 'varchar' })
|
||||
@Column({
|
||||
name: 'apellido_paterno',
|
||||
type: 'varchar',
|
||||
length: 45,
|
||||
nullable: true,
|
||||
})
|
||||
apellido_paterno: string;
|
||||
|
||||
@Column({ name: 'apellido_materno', type: 'varchar' })
|
||||
@Column({
|
||||
name: 'apellido_materno',
|
||||
type: 'varchar',
|
||||
length: 45,
|
||||
nullable: true,
|
||||
})
|
||||
apellido_materno: string;
|
||||
|
||||
@Column({ name: 'usuario', type: 'varchar' })
|
||||
@Column({ name: 'usuario', type: 'varchar', length: 45, nullable: false })
|
||||
usuario: string;
|
||||
|
||||
@Column({ name: 'password', type: 'varchar', length: 45, nullable: false })
|
||||
password: string;
|
||||
|
||||
@Column({ name: 'activo', type: 'tinyint', nullable: false, default: 1 })
|
||||
@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, nullable: true })
|
||||
descripcion: string;
|
||||
|
||||
@Column({ name: 'fecha_registro', type: 'varchar' })
|
||||
fecha_registro: string;
|
||||
@Column({
|
||||
name: 'fecha_registro',
|
||||
type: 'timestamp',
|
||||
default: () => 'CURRENT_TIMESTAMP',
|
||||
})
|
||||
fecha_registro: Date;
|
||||
|
||||
@ManyToOne(() => Perfil, (perfil) => perfil.usuarios, { eager: true })
|
||||
@JoinColumn({ name: 'id_perfil' })
|
||||
perfil: Perfil;
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.user,
|
||||
)
|
||||
@OneToMany(() => DetalleServicio, (detalleServicio) => detalleServicio.user)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.user)
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { UserService } from './user.service';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Controller('user')
|
||||
@@ -17,7 +17,7 @@ export class UserController {
|
||||
constructor(private readonly userService: UserService) {}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data: CreateUserDto, @Res() res: Response) {
|
||||
async Login(@Body() data: Login, @Res() res: Response) {
|
||||
return this.userService.Login(data, res);
|
||||
}
|
||||
|
||||
@@ -26,5 +26,10 @@ export class UserController {
|
||||
getProfile(@Request() req) {
|
||||
return req.user;
|
||||
}
|
||||
|
||||
@Post('/create')
|
||||
async createUser(@Body() data: CreateUserDto) {
|
||||
return this.userService.create(data);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Module } from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { UserController } from './user.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Perfil, User } from './entities/user.entity';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
@@ -10,7 +10,7 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User]),
|
||||
TypeOrmModule.forFeature([User, Perfil]),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
JwtModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
@@ -25,6 +25,6 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService, JwtStrategy],
|
||||
exports: [UserService,PassportModule,JwtModule],
|
||||
exports: [UserService, PassportModule, JwtModule],
|
||||
})
|
||||
export class UserModule {}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { Response } from 'express';
|
||||
import { CreateUserDto } from './dto/create-user.dto';
|
||||
import { CreateUserDto, Login } from './dto/create-user.dto';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { Perfil, User } from './entities/user.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
|
||||
@@ -11,10 +11,13 @@ export class UserService {
|
||||
constructor(
|
||||
@InjectRepository(User)
|
||||
private userRepository: Repository<User>,
|
||||
|
||||
@InjectRepository(Perfil)
|
||||
private perfilRepository: Repository<Perfil>,
|
||||
private jwtService: JwtService,
|
||||
) {}
|
||||
|
||||
async findOneByNameandPassword(data: CreateUserDto): Promise<User> {
|
||||
async findOneByNameandPassword(data: Login): Promise<User> {
|
||||
const { usuario, password } = data;
|
||||
|
||||
const user = await this.userRepository.findOne({
|
||||
@@ -28,7 +31,7 @@ export class UserService {
|
||||
return user;
|
||||
}
|
||||
|
||||
async Login(data: CreateUserDto, res: Response) {
|
||||
async Login(data: Login, res: Response) {
|
||||
const user = await this.findOneByNameandPassword(data);
|
||||
|
||||
const payload = { id: user.id_usuario, usuario: user.usuario };
|
||||
@@ -56,5 +59,22 @@ export class UserService {
|
||||
}
|
||||
return student;
|
||||
}
|
||||
|
||||
async create(data: CreateUserDto) {
|
||||
const { id_perfil, ...rest } = data;
|
||||
|
||||
const perfil = await this.perfilRepository.findOne({
|
||||
where: { id_perfil },
|
||||
});
|
||||
|
||||
if (!perfil) {
|
||||
throw new NotFoundException('Perfil not found');
|
||||
}
|
||||
|
||||
const datauser = { ...rest, perfil };
|
||||
|
||||
const user = this.userRepository.create(datauser);
|
||||
return this.userRepository.save(user);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user