Merge branch 'Lino' into Dev
This commit is contained in:
@@ -1,12 +1,23 @@
|
||||
import { Body, Controller, Post } from "@nestjs/common";
|
||||
import { OperationsService } from "./operations.services";
|
||||
import { Body, Controller, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.services';
|
||||
import { chargePrintDto } from './dto/operations.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController{
|
||||
constructor(private readonly operationsService:OperationsService){}
|
||||
export class OperationsController {
|
||||
constructor(private readonly operationsService: OperationsService) {}
|
||||
|
||||
@Post()
|
||||
async Login(@Body() data) {
|
||||
return this.operationsService.chargePrint(data,data.userid);
|
||||
}
|
||||
}
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('impressions')
|
||||
async chargePrint(@Body() data: chargePrintDto, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.chargePrint(data, id_usuario);
|
||||
}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('receipt')
|
||||
async addCredit(@Body() data, @Req() req: any) {
|
||||
const id_usuario = req.user.id;
|
||||
return this.operationsService.addCredit(data, id_usuario);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,18 @@ import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.services';
|
||||
import { DetalleServicioModule } from 'src/detalle_servicio/detalle_servicio.module';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
import { ReciboModule } from 'src/recibo/recibo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([Alumno, DetalleServicio]),
|
||||
DetalleServicioModule,
|
||||
AlumnoModule,
|
||||
UserModule,
|
||||
ReciboModule,
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { AlumnoService } from 'src/alumno/student.service';
|
||||
import { DetalleServicioService } from 'src/detalle_servicio/detalle_servicio.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { chargePrintDto } from './dto/operations.dto';
|
||||
import { CreateDetalleServicioDto } from 'src/detalle_servicio/dto/create-detalle_servicio.dto';
|
||||
import { UserService } from 'src/user/user.service';
|
||||
import { ReciboService } from 'src/recibo/recibo.service';
|
||||
import { CreateReciboDto } from 'src/recibo/dto/create-recibo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OperationsService {
|
||||
@@ -11,9 +19,11 @@ export class OperationsService {
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly alumnoService: AlumnoService,
|
||||
private readonly detalleServicioService: DetalleServicioService,
|
||||
private readonly userService: UserService,
|
||||
private readonly reciboService: ReciboService,
|
||||
) {}
|
||||
|
||||
async chargePrint(data: chargePrintDto, userId: number) {
|
||||
async chargePrint(data: chargePrintDto, id_usuario: number) {
|
||||
const { monto, id_cuenta } = data;
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
@@ -27,10 +37,14 @@ export class OperationsService {
|
||||
throw new BadRequestException('Crédito insuficiente');
|
||||
}
|
||||
|
||||
const detalleData: CreateDetalleServicioDto = {
|
||||
...data,
|
||||
id_servicio: 1,
|
||||
id_usuario: userId,
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta)
|
||||
|
||||
const detalleData = {
|
||||
servicio: 1,
|
||||
user,
|
||||
alum,
|
||||
monto,
|
||||
fecha_operacion: new Date(),
|
||||
};
|
||||
|
||||
@@ -39,7 +53,7 @@ export class OperationsService {
|
||||
queryRunner.manager,
|
||||
);
|
||||
|
||||
await this.alumnoService.UpdateCredit(
|
||||
await this.alumnoService.collectCredit(
|
||||
id_cuenta,
|
||||
monto,
|
||||
queryRunner.manager,
|
||||
@@ -54,4 +68,37 @@ export class OperationsService {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async addCredit(data, id_usuario: number) {
|
||||
const { id_cuenta, monto, fecha_recibo, folio_recibo } = data;
|
||||
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
const user = await this.userService.findOne(id_usuario);
|
||||
const alum = await this.alumnoService.findOne(id_cuenta);
|
||||
|
||||
try {
|
||||
const detalleData = {
|
||||
folio_recibo,
|
||||
user,
|
||||
alum,
|
||||
fecha_recibo,
|
||||
monto,
|
||||
};
|
||||
|
||||
await this.reciboService.create(detalleData, queryRunner.manager);
|
||||
|
||||
await this.alumnoService.addCredit(id_cuenta, monto, queryRunner.manager);
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return { message: 'correct' };
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
return { message: 'error', error: error.message };
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { AlumnoSancion } from 'src/alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Recibo } from 'src/recibo/entities/recibo.entity';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -83,7 +84,7 @@ export class Alumno {
|
||||
@Column({ name: 'generacion', type: 'int', width: 4, nullable: true })
|
||||
generacion: number | null;
|
||||
|
||||
@OneToMany(() => DetalleServicio, (detalle) => detalle.id_cuenta)
|
||||
@OneToMany(() => DetalleServicio, (detalle) => detalle.alum)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@ManyToOne(() => Carrera, (carrera) => carrera.estudiantes, {
|
||||
@@ -95,4 +96,7 @@ export class Alumno {
|
||||
|
||||
@OneToMany(() => AlumnoSancion, (alusancion) => alusancion.sancion)
|
||||
sanciones: AlumnoSancion[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.alum)
|
||||
recibo: Recibo[];
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class AlumnoService {
|
||||
return student.credito;
|
||||
}
|
||||
|
||||
async UpdateCredit(
|
||||
async collectCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
@@ -49,5 +49,19 @@ export class AlumnoService {
|
||||
.where({ id_cuenta })
|
||||
.execute();
|
||||
}
|
||||
|
||||
async addCredit(
|
||||
id_cuenta: number,
|
||||
credit: number,
|
||||
manager: EntityManager,
|
||||
) {
|
||||
const repo = manager.getRepository(Alumno);
|
||||
return await repo
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({ credito: () => `credito + ${credit}` })
|
||||
.where({ id_cuenta })
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -11,7 +11,6 @@ export class AlumnoSancionService {
|
||||
constructor(
|
||||
@InjectRepository(AlumnoSancion)
|
||||
private readonly alumnosancionRepository: Repository<AlumnoSancion>,
|
||||
|
||||
private readonly alumnoService: AlumnoService,
|
||||
private readonly sancionService: SancionService,
|
||||
) {}
|
||||
|
||||
@@ -17,6 +17,9 @@ import { SancionModule } from './sancion/sancion.module';
|
||||
import { AlumnoSancionModule } from './alumno_sancion/alumno_sancion.module';
|
||||
import { AlumnoSancion } from './alumno_sancion/entities/alumno_sancion.entity';
|
||||
import { Sancion } from './sancion/entities/sancion.entity';
|
||||
import { OperationsModule } from './Operations/operations.module';
|
||||
import { Recibo } from './recibo/entities/recibo.entity';
|
||||
import { ReciboModule } from './recibo/recibo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -43,6 +46,7 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
AlumnoSancion,
|
||||
Sancion,
|
||||
Carrera,
|
||||
Recibo,
|
||||
],
|
||||
synchronize: false, //Never change to true in production!
|
||||
}),
|
||||
@@ -54,6 +58,8 @@ import { Sancion } from './sancion/entities/sancion.entity';
|
||||
ServicioModule,
|
||||
SancionModule,
|
||||
AlumnoSancionModule,
|
||||
OperationsModule,
|
||||
ReciboModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@@ -5,5 +5,6 @@ import { DetalleServicioController } from './detalle_servicio.controller';
|
||||
@Module({
|
||||
controllers: [DetalleServicioController],
|
||||
providers: [DetalleServicioService],
|
||||
exports:[DetalleServicioService]
|
||||
})
|
||||
export class DetalleServicioModule {}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CreateDetalleServicioDto } from './dto/create-detalle_servicio.dto';
|
||||
|
||||
@Injectable()
|
||||
export class DetalleServicioService {
|
||||
async Create(data: CreateDetalleServicioDto, manager: EntityManager) {
|
||||
async Create(data, manager: EntityManager) {
|
||||
const repo = manager.getRepository(DetalleServicio);
|
||||
const details = repo.create(data);
|
||||
return await repo.save(details);
|
||||
|
||||
@@ -38,18 +38,11 @@ export class DetalleServicio {
|
||||
})
|
||||
fecha_operacion: Date;
|
||||
|
||||
@Column()
|
||||
id_cuenta:number
|
||||
|
||||
@Column()
|
||||
id_servicio:number
|
||||
|
||||
|
||||
@ManyToOne(() => Alumno, (id_cuenta) => id_cuenta.detalles_servicio, {
|
||||
@ManyToOne(() => Alumno, (alum) => alum.detalles_servicio, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
cuenta: Alumno;
|
||||
alum: Alumno;
|
||||
|
||||
@ManyToOne(() => Servicio, (id_servicio) => id_servicio.detalles_servicio, {
|
||||
eager: true,
|
||||
@@ -57,16 +50,16 @@ export class DetalleServicio {
|
||||
@JoinColumn({ name: 'id_servicio' })
|
||||
servicio: Servicio;
|
||||
|
||||
@ManyToOne(() => User, (id_perfil) => id_perfil.detalles_servicio, {
|
||||
@ManyToOne(() => User, (user) => user.detalles_servicio, {
|
||||
eager: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
id_perfil: User;
|
||||
user: User;
|
||||
|
||||
@ManyToOne(() => Periodo, (id_periodo) => id_periodo.detalles_servicio, {
|
||||
@ManyToOne(() => Periodo, (periodo) => periodo.detalles_servicio, {
|
||||
eager: true,
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'id_periodo' })
|
||||
id_periodo: Periodo;
|
||||
periodo: Periodo;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export class Periodo {
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.id_periodo,
|
||||
(id_detalle_servicio) => id_detalle_servicio.periodo,
|
||||
)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
}
|
||||
|
||||
@@ -1,34 +1,6 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto } from './dto/create-periodo.dto';
|
||||
import { UpdatePeriodoDto } from './dto/update-periodo.dto';
|
||||
|
||||
@Controller('periodo')
|
||||
export class PeriodoController {
|
||||
constructor(private readonly periodoService: PeriodoService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createPeriodoDto: CreatePeriodoDto) {
|
||||
return this.periodoService.create(createPeriodoDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.periodoService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.periodoService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updatePeriodoDto: UpdatePeriodoDto) {
|
||||
return this.periodoService.update(+id, updatePeriodoDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.periodoService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,4 @@ import { UpdatePeriodoDto } from './dto/update-periodo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class PeriodoService {
|
||||
create(createPeriodoDto: CreatePeriodoDto) {
|
||||
return 'This action adds a new periodo';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all periodo`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} periodo`;
|
||||
}
|
||||
|
||||
update(id: number, updatePeriodoDto: UpdatePeriodoDto) {
|
||||
return `This action updates a #${id} periodo`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} periodo`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsDate, IsNumber, IsString } from 'class-validator';
|
||||
|
||||
export class CreateReciboDto {
|
||||
|
||||
@IsNumber()
|
||||
monto: number;
|
||||
|
||||
@IsString()
|
||||
folio_recibo: string;
|
||||
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
fecha_recibo: Date;
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
export class Ticket {}
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -7,6 +6,7 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { Alumno } from 'src/alumno/entities/student.entity';
|
||||
|
||||
@Entity({ name: 'recibo' })
|
||||
export class Recibo {
|
||||
@@ -29,20 +29,11 @@ export class Recibo {
|
||||
monto: number;
|
||||
|
||||
@Column({ name: 'fecha_recibo', type: 'date', nullable: false })
|
||||
fecha_recibo: Date | null;
|
||||
fecha_recibo: Date ;
|
||||
|
||||
@Column({
|
||||
name: 'id_cuenta',
|
||||
type: 'int',
|
||||
})
|
||||
id_cuenta: number;
|
||||
|
||||
@Column({
|
||||
name: 'id_usuario',
|
||||
type: 'int',
|
||||
nullable: false,
|
||||
})
|
||||
id_usuario: number;
|
||||
@ManyToOne(() => Alumno, (alum) => alum.id_cuenta, {})
|
||||
@JoinColumn({ name: 'id_cuenta' })
|
||||
alum: Alumno;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.id_usuario, {})
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
@@ -0,0 +1,15 @@
|
||||
import {
|
||||
Controller,
|
||||
Post,
|
||||
Body,
|
||||
UseGuards,
|
||||
Req,
|
||||
} from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
|
||||
@Controller('recibo')
|
||||
export class ReciboController {
|
||||
constructor(private readonly reciboService: ReciboService) {}
|
||||
|
||||
}
|
||||
//IO
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ReciboService } from './recibo.service';
|
||||
import { ReciboController } from './recibo.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Recibo } from './entities/recibo.entity';
|
||||
import { AlumnoModule } from 'src/alumno/student.module';
|
||||
import { UserModule } from 'src/user/user.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Recibo]), AlumnoModule, UserModule],
|
||||
controllers: [ReciboController],
|
||||
providers: [ReciboService],
|
||||
exports:[ReciboService]
|
||||
})
|
||||
export class ReciboModule {}
|
||||
//IO
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Recibo } from './entities/recibo.entity';
|
||||
import { EntityManager, Repository } from 'typeorm';
|
||||
import { CreateReciboDto } from './dto/create-recibo.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ReciboService {
|
||||
constructor(
|
||||
@InjectRepository(Recibo)
|
||||
private readonly reciboRepository: Repository<Recibo>,
|
||||
) {}
|
||||
|
||||
async findOne(folio_recibo: string) {
|
||||
const recibo = await this.reciboRepository.findOne({
|
||||
where: { folio_recibo },
|
||||
});
|
||||
return recibo;
|
||||
}
|
||||
|
||||
async create(data: CreateReciboDto, manager: EntityManager) {
|
||||
const repo = manager.getRepository(Recibo);
|
||||
const details = repo.create(data);
|
||||
return await repo.save(details);
|
||||
}
|
||||
}
|
||||
//IO
|
||||
@@ -11,7 +11,7 @@ export class Servicio {
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.id_servicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.servicio,
|
||||
)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export class CreateTicketDto {}
|
||||
@@ -1,4 +0,0 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateTicketDto } from './create-ticket.dto';
|
||||
|
||||
export class UpdateTicketDto extends PartialType(CreateTicketDto) {}
|
||||
@@ -1,34 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TicketService } from './ticket.service';
|
||||
import { TicketController } from './ticket.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [TicketController],
|
||||
providers: [TicketService],
|
||||
})
|
||||
export class TicketModule {}
|
||||
@@ -1,26 +0,0 @@
|
||||
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,4 +1,5 @@
|
||||
import { DetalleServicio } from 'src/detalle_servicio/entities/detalle_servicio.entity';
|
||||
import { Recibo } from 'src/recibo/entities/recibo.entity';
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
@@ -55,7 +56,10 @@ export class User {
|
||||
|
||||
@OneToMany(
|
||||
() => DetalleServicio,
|
||||
(id_detalle_servicio) => id_detalle_servicio.id_perfil,
|
||||
(id_detalle_servicio) => id_detalle_servicio.user,
|
||||
)
|
||||
detalles_servicio: DetalleServicio[];
|
||||
|
||||
@OneToMany(() => Recibo, (recibo) => recibo.user)
|
||||
recibo: Recibo[];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
|
||||
@Injectable()
|
||||
export class JwtAuthGuard extends AuthGuard('jwt') {}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { UserService } from './user.service';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
@@ -15,6 +14,6 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
}
|
||||
|
||||
async validate(payload: any) {
|
||||
return { userId: payload.id, username: payload.usuario };
|
||||
return { id: payload.id, usuario: payload.usuario };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,10 @@ import { JwtStrategy } from './jwt.strategy';
|
||||
signOptions: { expiresIn: '1h' },
|
||||
};
|
||||
},
|
||||
|
||||
}),
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService,JwtStrategy],
|
||||
exports: [UserService],
|
||||
providers: [UserService, JwtStrategy],
|
||||
exports: [UserService,PassportModule,JwtModule],
|
||||
})
|
||||
export class UserModule { }
|
||||
export class UserModule {}
|
||||
|
||||
@@ -41,7 +41,20 @@ export class UserService {
|
||||
path: '/',
|
||||
});
|
||||
|
||||
return res.json({ message: 'Inicio de sesión exitoso' });
|
||||
return res.json({
|
||||
message: 'Inicio de sesión exitoso',
|
||||
access_token: token,
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id_usuario: number): Promise<User> {
|
||||
const student = await this.userRepository.findOne({
|
||||
where: { id_usuario },
|
||||
});
|
||||
if (!student) {
|
||||
throw new NotFoundException(`Student not found`);
|
||||
}
|
||||
return student;
|
||||
}
|
||||
}
|
||||
//IO
|
||||
//IO
|
||||
|
||||
Reference in New Issue
Block a user