motivo listo
This commit is contained in:
parent
923afe2f5c
commit
33a95690e8
6
src/motivo/dto/motivo.dto.ts
Normal file
6
src/motivo/dto/motivo.dto.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { IsNumberString } from 'class-validator';
|
||||||
|
|
||||||
|
export class MotivoDto {
|
||||||
|
@IsNumberString()
|
||||||
|
id_equipo: string;
|
||||||
|
}
|
@ -1,12 +1,14 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get, Query } from '@nestjs/common';
|
||||||
import { MotivoService } from './motivo.service';
|
import { MotivoService } from './motivo.service';
|
||||||
|
import { MotivoDto } from './dto/motivo.dto';
|
||||||
@Controller('motivo')
|
@Controller('motivo')
|
||||||
export class MotivoController {
|
export class MotivoController {
|
||||||
constructor(private motivoService: MotivoService) {}
|
constructor(private motivoService: MotivoService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
get() {}
|
get(@Query() query: MotivoDto) {
|
||||||
|
return this.motivoService.findAllIdEquipo(Number(query.id_equipo));
|
||||||
|
}
|
||||||
|
|
||||||
@Get('reporte')
|
@Get('reporte')
|
||||||
reporte() {}
|
reporte() {}
|
||||||
|
@ -3,9 +3,17 @@ import { TypeOrmModule } from '@nestjs/typeorm';
|
|||||||
import { MotivoController } from './motivo.controller';
|
import { MotivoController } from './motivo.controller';
|
||||||
import { MotivoService } from './motivo.service';
|
import { MotivoService } from './motivo.service';
|
||||||
import { Motivo } from './entity/motivo.entity';
|
import { Motivo } from './entity/motivo.entity';
|
||||||
|
import { EquipoModule } from 'src/equipo/equipo.module';
|
||||||
|
import { OperadorModule } from 'src/operador/operador.module';
|
||||||
|
import { StatusModule } from 'src/status/status.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [TypeOrmModule.forFeature([Motivo])],
|
imports: [
|
||||||
|
TypeOrmModule.forFeature([Motivo]),
|
||||||
|
EquipoModule,
|
||||||
|
OperadorModule,
|
||||||
|
StatusModule,
|
||||||
|
],
|
||||||
controllers: [MotivoController],
|
controllers: [MotivoController],
|
||||||
providers: [MotivoService],
|
providers: [MotivoService],
|
||||||
})
|
})
|
||||||
|
@ -2,10 +2,43 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Motivo } from './entity/motivo.entity';
|
import { Motivo } from './entity/motivo.entity';
|
||||||
|
import { EquipoService } from 'src/equipo/equipo.service';
|
||||||
|
import { OperadorService } from 'src/operador/operador.service';
|
||||||
|
import { StatusService } from 'src/status/status.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MotivoService {
|
export class MotivoService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Motivo) private repository: Repository<Motivo>,
|
@InjectRepository(Motivo) private repository: Repository<Motivo>,
|
||||||
|
private equipoService: EquipoService,
|
||||||
|
private operadorService: OperadorService,
|
||||||
|
private statusService: StatusService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async create(
|
||||||
|
id_equipo: number,
|
||||||
|
id_operador: number,
|
||||||
|
id_status: number,
|
||||||
|
motivo: string,
|
||||||
|
) {
|
||||||
|
const equipo = await this.equipoService.findById(id_equipo);
|
||||||
|
const operador = await this.operadorService.findById(id_operador);
|
||||||
|
const status = await this.statusService.findById(id_status);
|
||||||
|
|
||||||
|
return this.repository.save(
|
||||||
|
this.repository.create({
|
||||||
|
equipo,
|
||||||
|
fecha_creacion: new Date(),
|
||||||
|
motivo,
|
||||||
|
operador,
|
||||||
|
status,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
findAllIdEquipo(id_equipo: number) {
|
||||||
|
return this.equipoService
|
||||||
|
.findById(id_equipo)
|
||||||
|
.then((equipo) => this.repository.find({ equipo }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { ConflictException, Injectable } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Status } from './entity/status.entity';
|
import { Status } from './entity/status.entity';
|
||||||
@ -10,6 +10,13 @@ export class StatusService {
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
findAll() {
|
findAll() {
|
||||||
return this.repository.find()
|
return this.repository.find();
|
||||||
|
}
|
||||||
|
|
||||||
|
findById(id_status: number) {
|
||||||
|
return this.repository.findOne({ id_status }).then((status) => {
|
||||||
|
if (!status) throw new NotFoundException('No existe este status.');
|
||||||
|
return status;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user