Merge branch 'master' into develop
This commit is contained in:
@@ -21,3 +21,13 @@ export class CreatePeriodoDto {
|
|||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
activo?: boolean;
|
activo?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ModifiedDateDto {
|
||||||
|
|
||||||
|
@IsDateString()
|
||||||
|
fecha_inicio_servicio: string;
|
||||||
|
|
||||||
|
@IsDateString()
|
||||||
|
fecha_fin_servicio: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common';
|
||||||
import { PeriodoService } from './periodo.service';
|
import { PeriodoService } from './periodo.service';
|
||||||
|
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||||
|
|
||||||
@Controller('periodo')
|
@Controller('periodo')
|
||||||
@@ -11,4 +12,19 @@ export class PeriodoController {
|
|||||||
findAll() {
|
findAll() {
|
||||||
return this.periodoService.findAll();
|
return this.periodoService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
create(@Body() data: CreatePeriodoDto) {
|
||||||
|
return this.periodoService.create(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete("/:id_periodo")
|
||||||
|
delete(@Param("id_periodo") id_periodo: number) {
|
||||||
|
return this.periodoService.delete(id_periodo)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch("/date/:id_periodo")
|
||||||
|
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||||
|
return this.periodoService.modifiedDate(data, id_periodo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Periodo } from './entities/periodo.entity';
|
import { Periodo } from './entities/periodo.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
|
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PeriodoService {
|
export class PeriodoService {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(Periodo)
|
@InjectRepository(Periodo)
|
||||||
private readonly periodoRepository: Repository<Periodo>,
|
private readonly periodoRepository: Repository<Periodo>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
async findOne() {
|
async findOne(semestre: string) {
|
||||||
return this.periodoRepository.findOne({ where: {} });
|
return this.periodoRepository.findOne({ where: { semestre } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
@@ -30,4 +31,31 @@ export class PeriodoService {
|
|||||||
|
|
||||||
return periodo;
|
return periodo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async delete(id_periodo: number) {
|
||||||
|
this.periodoRepository.delete(id_periodo)
|
||||||
|
}
|
||||||
|
|
||||||
|
async periodoDisable(id_periodo:number) {
|
||||||
|
this.periodoRepository.update(id_periodo, { activo: false })
|
||||||
|
}
|
||||||
|
|
||||||
|
async create(data: CreatePeriodoDto) {
|
||||||
|
const periodo = await this.findOne(data.semestre)
|
||||||
|
|
||||||
|
if (periodo) {
|
||||||
|
throw new BadRequestException("El periodo ya existe")
|
||||||
|
}
|
||||||
|
|
||||||
|
const periodoActive = await this.getPeriodoActivo();
|
||||||
|
|
||||||
|
this.periodoDisable(periodoActive.id_periodo)
|
||||||
|
|
||||||
|
const create = this.periodoRepository.create(data)
|
||||||
|
return this.periodoRepository.save(create)
|
||||||
|
}
|
||||||
|
|
||||||
|
async modifiedDate(data:ModifiedDateDto,id_periodo){
|
||||||
|
return this.periodoRepository.update(id_periodo,data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user