feat: agregar endpoints atómicos, auth de descuentos y limpiar deuda técnica
This commit is contained in:
1 parent
2d6c29a1f3
commit
1aa64e4bd0
50 files changed
+726
-303
No files matched your search
@@ -1,6 +1,12 @@
|
||||
import type { IRepository } from "../../../common/repository.interface.js";
|
||||
import type { OperatingDay, OperatingDayKey } from "../../../entities/operating-day.entity.js";
|
||||
import type { CreateOperatingDayInput, UpdateOperatingDayInput } from "../../../dtos/operating-day.dto.js";
|
||||
import type {
|
||||
OperatingDay,
|
||||
OperatingDayKey,
|
||||
} from "../../../entities/operating-day.entity.js";
|
||||
import type {
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
} from "../../../dtos/operating-day.dto.js";
|
||||
|
||||
export const OPERATING_DAY_REPOSITORY = Symbol("OPERATING_DAY_REPOSITORY");
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import type { IService } from "../../../common/service.interface.js";
|
||||
import type { OperatingDay, OperatingDayKey } from "../../../entities/operating-day.entity.js";
|
||||
import type { CreateOperatingDayInput, UpdateOperatingDayInput } from "../../../dtos/operating-day.dto.js";
|
||||
import type {
|
||||
OperatingDay,
|
||||
OperatingDayKey,
|
||||
} from "../../../entities/operating-day.entity.js";
|
||||
import type {
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
} from "../../../dtos/operating-day.dto.js";
|
||||
|
||||
export const OPERATING_DAY_SERVICE = Symbol("OPERATING_DAY_SERVICE");
|
||||
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
import { Body, Controller, Delete, Get, Inject, Param, ParseIntPipe, Patch, Post } from "@nestjs/common";
|
||||
import type { CreateOperatingDayInput, UpdateOperatingDayInput } from "../../dtos/operating-day.dto.js";
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
} from "@nestjs/common";
|
||||
import type {
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
} from "../../dtos/operating-day.dto.js";
|
||||
import { OPERATING_DAY_SERVICE } from "./interfaces/operating-day-service.interface.js";
|
||||
import type { IOperatingDayService } from "./interfaces/operating-day-service.interface.js";
|
||||
|
||||
@@ -26,7 +39,10 @@ export class OperatingDayController {
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
update(@Param("id", ParseIntPipe) id: number, @Body() body: UpdateOperatingDayInput) {
|
||||
update(
|
||||
@Param("id", ParseIntPipe) id: number,
|
||||
@Body() body: UpdateOperatingDayInput,
|
||||
) {
|
||||
return this.operatingDayService.update({ id }, body);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,34 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { BaseRepository } from "../../common/base.repository.js";
|
||||
import type { CreateOperatingDayInput, UpdateOperatingDayInput } from "../../dtos/operating-day.dto.js";
|
||||
import type { OperatingDay, OperatingDayKey } from "../../entities/operating-day.entity.js";
|
||||
import type {
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
} from "../../dtos/operating-day.dto.js";
|
||||
import type {
|
||||
OperatingDay,
|
||||
OperatingDayKey,
|
||||
} from "../../entities/operating-day.entity.js";
|
||||
import type { IOperatingDayRepository } from "./interfaces/operating-day-repository.interface.js";
|
||||
|
||||
@Injectable()
|
||||
export class OperatingDayRepository
|
||||
extends BaseRepository<OperatingDay, CreateOperatingDayInput, UpdateOperatingDayInput, OperatingDayKey>
|
||||
extends BaseRepository<
|
||||
OperatingDay,
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
OperatingDayKey
|
||||
>
|
||||
implements IOperatingDayRepository
|
||||
{
|
||||
protected readonly columns = ["id", "date", "status", "openedById", "closedById", "openedAt", "closedAt"] as const;
|
||||
protected readonly columns = [
|
||||
"id",
|
||||
"date",
|
||||
"status",
|
||||
"openedById",
|
||||
"closedById",
|
||||
"openedAt",
|
||||
"closedAt",
|
||||
] as const;
|
||||
|
||||
protected get model() {
|
||||
return this.db.orm.public.OperatingDay;
|
||||
|
||||
@@ -1,17 +1,31 @@
|
||||
import { BadRequestException, Inject, Injectable } from "@nestjs/common";
|
||||
import { BaseService } from "../../common/base.service.js";
|
||||
import type { CreateOperatingDayInput, UpdateOperatingDayInput } from "../../dtos/operating-day.dto.js";
|
||||
import type { OperatingDay, OperatingDayKey } from "../../entities/operating-day.entity.js";
|
||||
import type {
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
} from "../../dtos/operating-day.dto.js";
|
||||
import type {
|
||||
OperatingDay,
|
||||
OperatingDayKey,
|
||||
} from "../../entities/operating-day.entity.js";
|
||||
import {
|
||||
CASH_REGISTER_SESSION_SERVICE,
|
||||
type ICashRegisterSessionService,
|
||||
} from "../cash-register-session/interfaces/cash-register-session-service.interface.js";
|
||||
import { OPERATING_DAY_REPOSITORY, type IOperatingDayRepository } from "./interfaces/operating-day-repository.interface.js";
|
||||
import {
|
||||
OPERATING_DAY_REPOSITORY,
|
||||
type IOperatingDayRepository,
|
||||
} from "./interfaces/operating-day-repository.interface.js";
|
||||
import type { IOperatingDayService } from "./interfaces/operating-day-service.interface.js";
|
||||
|
||||
@Injectable()
|
||||
export class OperatingDayService
|
||||
extends BaseService<OperatingDay, CreateOperatingDayInput, UpdateOperatingDayInput, OperatingDayKey>
|
||||
extends BaseService<
|
||||
OperatingDay,
|
||||
CreateOperatingDayInput,
|
||||
UpdateOperatingDayInput,
|
||||
OperatingDayKey
|
||||
>
|
||||
implements IOperatingDayService
|
||||
{
|
||||
constructor(
|
||||
@@ -32,20 +46,29 @@ export class OperatingDayService
|
||||
return this.operatingDayRepository.create(data);
|
||||
}
|
||||
|
||||
override async update(where: OperatingDayKey, data: UpdateOperatingDayInput): Promise<OperatingDay> {
|
||||
override async update(
|
||||
where: OperatingDayKey,
|
||||
data: UpdateOperatingDayInput,
|
||||
): Promise<OperatingDay> {
|
||||
const current = await this.findById(where);
|
||||
|
||||
if (data.status === "closed") {
|
||||
if (current.status === "closed") {
|
||||
throw new BadRequestException("Esta fecha de operación ya está cerrada");
|
||||
throw new BadRequestException(
|
||||
"Esta fecha de operación ya está cerrada",
|
||||
);
|
||||
}
|
||||
const sessions = await this.sessionService.findAll();
|
||||
const hasOpenSession = sessions.some((s) => s.status === "open");
|
||||
if (hasOpenSession) {
|
||||
throw new BadRequestException("No se puede cerrar el día de operación con cajas abiertas");
|
||||
throw new BadRequestException(
|
||||
"No se puede cerrar el día de operación con cajas abiertas",
|
||||
);
|
||||
}
|
||||
if (!data.closedById) {
|
||||
throw new BadRequestException("Falta indicar quién cierra la fecha de operación");
|
||||
throw new BadRequestException(
|
||||
"Falta indicar quién cierra la fecha de operación",
|
||||
);
|
||||
}
|
||||
|
||||
const closed = await this.operatingDayRepository.update(where, {
|
||||
|
||||
Reference in new issue
Block a user