implmentação swagger no modulo orders-payment

This commit is contained in:
JurTI-BR
2025-04-02 18:13:47 -03:00
parent 28a1cee876
commit 4719279ab7
36 changed files with 944 additions and 820 deletions

View File

@@ -1,208 +0,0 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
exports.__esModule = true;
exports.OrdersService = void 0;
var common_1 = require("@nestjs/common");
var redis_client_adapter_provider_1 = require("src/core/configs/cache/redis-client.adapter.provider");
var cache_util_1 = require("src/shared/cache.util");
var crypto_1 = require("crypto");
var OrdersService = /** @class */ (function () {
function OrdersService(ordersRepository, redisClient) {
this.ordersRepository = ordersRepository;
this.redisClient = redisClient;
this.TTL_ORDERS = 60 * 10; // 10 minutos
this.TTL_INVOICE = 60 * 60; // 1 hora
this.TTL_ITENS = 60 * 10; // 10 minutos
}
/**
* Buscar pedidos com cache baseado nos filtros
*/
OrdersService.prototype.findOrders = function (query) {
return __awaiter(this, void 0, void 0, function () {
var key;
var _this = this;
return __generator(this, function (_a) {
key = "orders:query:" + this.hashObject(query);
return [2 /*return*/, cache_util_1.getOrSetCache(this.redisClient, key, this.TTL_ORDERS, function () { return _this.ordersRepository.findOrders(query); })];
});
});
};
/**
* Buscar nota fiscal por chave NFe com cache
*/
OrdersService.prototype.findInvoice = function (chavenfe) {
return __awaiter(this, void 0, Promise, function () {
var key;
var _this = this;
return __generator(this, function (_a) {
key = "orders:invoice:" + chavenfe;
return [2 /*return*/, cache_util_1.getOrSetCache(this.redisClient, key, this.TTL_INVOICE, function () { return __awaiter(_this, void 0, void 0, function () {
var invoiceData, invoice;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.ordersRepository.findInvoice(chavenfe)];
case 1:
invoiceData = _a.sent();
invoice = {
storeId: invoiceData.storeId,
invoiceDate: new Date(invoiceData.invoiceDate),
orderId: invoiceData.orderId,
invoiceId: invoiceData.invoiceId,
transactionId: invoiceData.transactionId,
customerId: invoiceData.customerId,
customer: invoiceData.customer,
sellerId: invoiceData.sellerId,
sellerName: invoiceData.sellerName,
itensQt: invoiceData.itensQt,
itens: invoiceData.itens
};
return [2 /*return*/, invoice];
}
});
}); })];
});
});
};
/**
* Buscar itens de pedido com cache
*/
OrdersService.prototype.getItens = function (orderId) {
return __awaiter(this, void 0, Promise, function () {
var key;
var _this = this;
return __generator(this, function (_a) {
key = "orders:itens:" + orderId;
return [2 /*return*/, cache_util_1.getOrSetCache(this.redisClient, key, this.TTL_ITENS, function () { return __awaiter(_this, void 0, void 0, function () {
var itens;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.ordersRepository.getItens(orderId)];
case 1:
itens = _a.sent();
return [2 /*return*/, itens.map(function (item) { return ({
productId: Number(item.productId),
description: item.description,
pacth: item.pacth,
color: item.color,
stockId: Number(item.stockId),
quantity: Number(item.quantity),
salePrice: Number(item.salePrice),
deliveryType: item.deliveryType,
total: Number(item.total),
weight: Number(item.weight),
department: item.department,
brand: item.brand
}); })];
}
});
}); })];
});
});
};
OrdersService.prototype.getCutItens = function (orderId) {
return __awaiter(this, void 0, Promise, function () {
var itens;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.ordersRepository.getCutItens(orderId)];
case 1:
itens = _a.sent();
return [2 /*return*/, itens.map(function (item) { return ({
productId: Number(item.productId),
description: item.description,
pacth: item.pacth,
stockId: Number(item.stockId),
saleQuantity: Number(item.saleQuantity),
cutQuantity: Number(item.cutQuantity),
separedQuantity: Number(item.separedQuantity)
}); })];
}
});
});
};
OrdersService.prototype.getOrderDelivery = function (orderId) {
return __awaiter(this, void 0, Promise, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ordersRepository.getOrderDelivery(orderId)];
});
});
};
OrdersService.prototype.getTransfer = function (orderId) {
return __awaiter(this, void 0, Promise, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ordersRepository.getTransfer(orderId)];
});
});
};
OrdersService.prototype.getStatusOrder = function (orderId) {
return __awaiter(this, void 0, Promise, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ordersRepository.getStatusOrder(orderId)];
});
});
};
/**
* Utilitário para gerar hash MD5 de objetos
*/
OrdersService.prototype.hashObject = function (obj) {
var str = JSON.stringify(obj, Object.keys(obj).sort());
return crypto_1.createHash('md5').update(str).digest('hex');
};
OrdersService.prototype.createInvoiceCheck = function (invoice) {
return __awaiter(this, void 0, Promise, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this.ordersRepository.createInvoiceCheck(invoice)];
});
});
};
OrdersService = __decorate([
common_1.Injectable(),
__param(1, common_1.Inject(redis_client_adapter_provider_1.RedisClientToken))
], OrdersService);
return OrdersService;
}());
exports.OrdersService = OrdersService;

View File

@@ -0,0 +1,32 @@
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
exports.__esModule = true;
exports.OrdersModule = void 0;
var common_1 = require("@nestjs/common");
var orders_controller_1 = require("../controllers/orders.controller");
var orders_service_1 = require("../application/orders.service");
var orders_repository_1 = require("../repositories/orders.repository");
var database_module_1 = require("../../core/database/database.module");
var config_1 = require("@nestjs/config");
var OrdersModule = /** @class */ (function () {
function OrdersModule() {
}
OrdersModule = __decorate([
common_1.Module({
imports: [
config_1.ConfigModule,
database_module_1.DatabaseModule,
],
controllers: [orders_controller_1.OrdersController],
providers: [orders_service_1.OrdersService, orders_repository_1.OrdersRepository],
exports: [orders_service_1.OrdersService]
})
], OrdersModule);
return OrdersModule;
}());
exports.OrdersModule = OrdersModule;

View File

@@ -1,12 +1,17 @@
import { Module } from '@nestjs/common';
import { OrdersController } from '../controllers/orders.controller';
import { OrdersService } from '../application/orders.service';
import { OrdersRepository } from '../repositories/orders.repository';
import { OrdersRepository } from '../repositories/orders.repository';
import { DatabaseModule } from '../../core/database/database.module';
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [],
imports: [
ConfigModule,
DatabaseModule,
],
controllers: [OrdersController],
providers: [OrdersService, OrdersRepository],
exports: [OrdersService],
})
export class OrdersModule {}