cambiar nombre carrito
This commit is contained in:
@@ -151,6 +151,7 @@ export class CarritoController {
|
||||
this.validarUsuarioService.validarAdmin(admin);
|
||||
return this.carritoService.create(
|
||||
admin,
|
||||
body.carrito,
|
||||
body.id_modulo,
|
||||
body.id_tipo_carrito,
|
||||
body.id_marca,
|
||||
|
||||
@@ -39,6 +39,7 @@ export class CarritoService {
|
||||
|
||||
async create(
|
||||
admin: Operador,
|
||||
carrito: string,
|
||||
id_modulo: number,
|
||||
id_tipo_carrito: number,
|
||||
id_marca: number,
|
||||
@@ -57,25 +58,17 @@ export class CarritoService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes crear carritos para este módulo porque no pertenece a tu institución.',
|
||||
);
|
||||
// Cuento cuantos carritos tiene ese modulo de ese tipo de carrito
|
||||
return this.informacionCarritoView
|
||||
.count({
|
||||
where: {
|
||||
id_modulo: modulo.id_modulo,
|
||||
id_tipo_carrito: tipoCarrito.id_tipo_carrito,
|
||||
},
|
||||
})
|
||||
.then((n) =>
|
||||
// Creo y cuardo el registro
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
carrito: `C${n >= 9 ? '' : '0'}${n + 1}`,
|
||||
marca,
|
||||
modelo,
|
||||
modulo,
|
||||
tipoCarrito,
|
||||
}),
|
||||
),
|
||||
|
||||
// Creo y guardo el registro
|
||||
return this.repository
|
||||
.save(
|
||||
this.repository.create({
|
||||
carrito,
|
||||
marca,
|
||||
modelo,
|
||||
modulo,
|
||||
tipoCarrito,
|
||||
}),
|
||||
)
|
||||
.then((_) => ({
|
||||
message: 'Se creó correctamente un nuevo carrito para este módulo.',
|
||||
@@ -225,8 +218,8 @@ export class CarritoService {
|
||||
async update(
|
||||
operador: Operador,
|
||||
attrs: Partial<Carrito>,
|
||||
motivo: string,
|
||||
laboratorioMovil: boolean,
|
||||
motivo?: string,
|
||||
laboratorioMovil?: boolean,
|
||||
) {
|
||||
return this.findById(attrs.id_carrito)
|
||||
.then(async (carrito) => {
|
||||
@@ -238,22 +231,28 @@ export class CarritoService {
|
||||
throw new ForbiddenException(
|
||||
'No puedes modificar la información este carrito porque no pertenece a tu institución.',
|
||||
);
|
||||
// Valido que se mande el motivo de desactivación
|
||||
if (attrs.activo === false && !motivo)
|
||||
throw new ForbiddenException(
|
||||
'No se mandó el motivo de desactivación',
|
||||
);
|
||||
// Actualizo el objeto con los valores enviados del front
|
||||
Object.assign(carrito, attrs);
|
||||
// Guardo cambios
|
||||
return this.repository.save(carrito);
|
||||
})
|
||||
.then((carrito) =>
|
||||
.then((carrito) => {
|
||||
// Creo reporte de cambio de status del carrito
|
||||
this.caritoMotivoService.create(
|
||||
carrito,
|
||||
operador,
|
||||
attrs.activo,
|
||||
motivo,
|
||||
laboratorioMovil,
|
||||
),
|
||||
)
|
||||
.then((_) => ({ message: 'Se guardaron los cambios correctamente.' }));
|
||||
if (attrs.activo === false)
|
||||
this.caritoMotivoService.create(
|
||||
carrito,
|
||||
operador,
|
||||
attrs.activo,
|
||||
motivo,
|
||||
laboratorioMovil,
|
||||
);
|
||||
return { message: 'Se guardaron los cambios correctamente.' };
|
||||
});
|
||||
}
|
||||
|
||||
private viewToCarrito(infoCarrito: InformacionCarritoView) {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { IsInt } from 'class-validator';
|
||||
import { IsInt, IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class CreateCarritoDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(3)
|
||||
carrito: string;
|
||||
|
||||
@IsInt()
|
||||
id_marca: number;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
IsBoolean,
|
||||
IsInt,
|
||||
IsNotEmpty,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
} from 'class-validator';
|
||||
@@ -11,13 +12,22 @@ export class UpdateCarritoDto {
|
||||
id_carrito: number;
|
||||
|
||||
@IsBoolean()
|
||||
activo: boolean;
|
||||
@IsOptional()
|
||||
activo?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(3)
|
||||
@IsOptional()
|
||||
carrito?: string;
|
||||
|
||||
@IsBoolean()
|
||||
laboratorioMovil: boolean;
|
||||
@IsOptional()
|
||||
laboratorioMovil?: boolean;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(250)
|
||||
motivo;
|
||||
@IsOptional()
|
||||
motivo?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user