Deploy via committed dist: local Nest build, server runs with .env

Build on the developer machine without Docker, commit dist/, and run on the server with Dockerfile.dist plus compose env_file.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-05 21:35:22 +03:30
co-authored by Cursor
parent 67cfc17079
commit cbcea58e94
199 changed files with 10895 additions and 4 deletions
+155
View File
@@ -0,0 +1,155 @@
import { DashboardService } from './dashboard.service';
export declare class DashboardController {
private readonly dashboardService;
constructor(dashboardService: DashboardService);
getDashboard(): Promise<{
stats: {
newOrders: number;
pendingReview: number;
pendingCheck: number;
finalApproval: number;
todaySales: number;
todaySalesGrowth: number;
monthSales: number;
};
recentOrders: {
id: string;
orderNumber: string;
userId: string;
companyId: string;
companyName: string;
settlementType: import("@prisma/client").$Enums.SettlementType;
settlementMethod: import("@prisma/client").$Enums.SettlementType;
checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined;
status: import("@prisma/client").$Enums.OrderStatus;
adminStatus: string;
totalMeterage: number;
meterage: number;
totalAmount: number | null;
shippingCost: number | null;
totalDiscount: number | null;
finalAmount: number | null;
notes: string | undefined;
checkRassDays: number | undefined;
checkRassDate: string | undefined;
cashInvoiceExpiresAt: string | undefined;
createdAt: string;
updatedAt: string;
customerName: string;
customerPhone: string;
customerNationalId: string | undefined;
customerType: import("@prisma/client").$Enums.CustomerType;
items: {
id: string;
productId: string | undefined;
catalogCode: string;
productName: string;
productCode: string | undefined;
color: string;
requestedMeterage: number;
confirmedMeterage: number | null;
unitPrice: number | null;
supplyPrice: number | null;
unitDiscount: number;
discount: number;
lineTotal: number | null;
totalAmount: number | null;
notes: string | undefined;
}[];
checks: {
id: string;
orderId: string;
row: number;
amount: number;
dueDate: string;
sayadId: string | undefined;
checkNumber: string | undefined;
ownerNationalId: string | undefined;
ownerFirstName: string | undefined;
ownerLastName: string | undefined;
bankName: string;
branchName: string | undefined;
frontImage: string | undefined;
backImage: string | undefined;
notes: string | undefined;
mode: import("@prisma/client").$Enums.CheckRegistrationMode;
status: import("@prisma/client").$Enums.CheckStatus;
createdAt: string;
updatedAt: string;
}[];
cashReceipt: {
id: string;
amount: number;
paidAmount: number | null;
transferDate: string | null;
transferTime: string | undefined;
trackingNumber: string | undefined;
trackingCode: string | undefined;
destinationAccountId: string | undefined;
receiptImage: string | undefined;
notes: string | undefined;
expiresAt: string | undefined;
status: import("@prisma/client").$Enums.CashPaymentStatus;
submittedAt: string | undefined;
createdAt: string;
} | undefined;
shipment: {
id: string;
orderId: string;
carrier: string;
trackingNumber: string;
meterage: number;
status: import("@prisma/client").$Enums.ShipmentStatus;
shippedAt: string | null;
deliveredAt: string | null;
} | undefined;
statusHistory: {
id: string;
fromStatus: import("@prisma/client").$Enums.OrderStatus | null;
toStatus: import("@prisma/client").$Enums.OrderStatus;
changedBy: string;
note: string | undefined;
reason: string | undefined;
changedAt: string;
}[];
}[];
salesChartData: number[];
chartAxisLabels: string[];
checkDeadlines: {
id: string;
label: string;
tone: "warning" | "danger" | "neutral";
count: number;
amount: number;
}[];
notifications: {
id: string;
title: string;
body: string;
tone: import("@prisma/client").$Enums.NotificationTone | null;
link: string | null;
isRead: boolean;
sentAt: string;
}[];
messages: {
id: string;
senderName: string;
subject: string;
preview: string;
isRead: boolean;
sentAt: string;
}[];
}>;
getReports(): Promise<{
reportSalesByCompany: {
companyName: string;
orderCount: number;
totalAmount: number;
meterage: number;
}[];
reportOrdersByStatus: {
status: string;
count: number;
}[];
}>;
}
+46
View File
@@ -0,0 +1,46 @@
"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 __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardController = void 0;
const common_1 = require("@nestjs/common");
const dashboard_service_1 = require("./dashboard.service");
const auth_decorators_1 = require("../common/decorators/auth.decorators");
let DashboardController = class DashboardController {
dashboardService;
constructor(dashboardService) {
this.dashboardService = dashboardService;
}
getDashboard() {
return this.dashboardService.getDashboard();
}
getReports() {
return this.dashboardService.getReports();
}
};
exports.DashboardController = DashboardController;
__decorate([
(0, common_1.Get)('dashboard'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], DashboardController.prototype, "getDashboard", null);
__decorate([
(0, common_1.Get)('reports'),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], DashboardController.prototype, "getReports", null);
exports.DashboardController = DashboardController = __decorate([
(0, common_1.Controller)('admin'),
(0, auth_decorators_1.AuthType)('admin'),
__metadata("design:paramtypes", [dashboard_service_1.DashboardService])
], DashboardController);
//# sourceMappingURL=dashboard.controller.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"dashboard.controller.js","sourceRoot":"","sources":["../../src/dashboard/dashboard.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAiD;AACjD,2DAAuD;AACvD,0EAAgE;AAIzD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACD;IAA7B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAGnE,YAAY;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC9C,CAAC;IAGD,UAAU;QACR,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,CAAC;IAC5C,CAAC;CACF,CAAA;AAZY,kDAAmB;AAI9B;IADC,IAAA,YAAG,EAAC,WAAW,CAAC;;;;uDAGhB;AAGD;IADC,IAAA,YAAG,EAAC,SAAS,CAAC;;;;qDAGd;8BAXU,mBAAmB;IAF/B,IAAA,mBAAU,EAAC,OAAO,CAAC;IACnB,IAAA,0BAAQ,EAAC,OAAO,CAAC;qCAE+B,oCAAgB;GADpD,mBAAmB,CAY/B"}
+2
View File
@@ -0,0 +1,2 @@
export declare class DashboardModule {
}
+24
View File
@@ -0,0 +1,24 @@
"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardModule = void 0;
const common_1 = require("@nestjs/common");
const dashboard_controller_1 = require("./dashboard.controller");
const dashboard_service_1 = require("./dashboard.service");
const orders_module_1 = require("../orders/orders.module");
let DashboardModule = class DashboardModule {
};
exports.DashboardModule = DashboardModule;
exports.DashboardModule = DashboardModule = __decorate([
(0, common_1.Module)({
imports: [orders_module_1.OrdersModule],
controllers: [dashboard_controller_1.DashboardController],
providers: [dashboard_service_1.DashboardService],
})
], DashboardModule);
//# sourceMappingURL=dashboard.module.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"dashboard.module.js","sourceRoot":"","sources":["../../src/dashboard/dashboard.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAA6D;AAC7D,2DAAuD;AACvD,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,CAAC;KAC9B,CAAC;GACW,eAAe,CAAG"}
+158
View File
@@ -0,0 +1,158 @@
import { PrismaService } from '../prisma/prisma.service';
import { OrdersService } from '../orders/orders.service';
export declare class DashboardService {
private readonly prisma;
private readonly ordersService;
constructor(prisma: PrismaService, ordersService: OrdersService);
getDashboard(): Promise<{
stats: {
newOrders: number;
pendingReview: number;
pendingCheck: number;
finalApproval: number;
todaySales: number;
todaySalesGrowth: number;
monthSales: number;
};
recentOrders: {
id: string;
orderNumber: string;
userId: string;
companyId: string;
companyName: string;
settlementType: import("@prisma/client").$Enums.SettlementType;
settlementMethod: import("@prisma/client").$Enums.SettlementType;
checkMode: import("@prisma/client").$Enums.CheckRegistrationMode | undefined;
status: import("@prisma/client").$Enums.OrderStatus;
adminStatus: string;
totalMeterage: number;
meterage: number;
totalAmount: number | null;
shippingCost: number | null;
totalDiscount: number | null;
finalAmount: number | null;
notes: string | undefined;
checkRassDays: number | undefined;
checkRassDate: string | undefined;
cashInvoiceExpiresAt: string | undefined;
createdAt: string;
updatedAt: string;
customerName: string;
customerPhone: string;
customerNationalId: string | undefined;
customerType: import("@prisma/client").$Enums.CustomerType;
items: {
id: string;
productId: string | undefined;
catalogCode: string;
productName: string;
productCode: string | undefined;
color: string;
requestedMeterage: number;
confirmedMeterage: number | null;
unitPrice: number | null;
supplyPrice: number | null;
unitDiscount: number;
discount: number;
lineTotal: number | null;
totalAmount: number | null;
notes: string | undefined;
}[];
checks: {
id: string;
orderId: string;
row: number;
amount: number;
dueDate: string;
sayadId: string | undefined;
checkNumber: string | undefined;
ownerNationalId: string | undefined;
ownerFirstName: string | undefined;
ownerLastName: string | undefined;
bankName: string;
branchName: string | undefined;
frontImage: string | undefined;
backImage: string | undefined;
notes: string | undefined;
mode: import("@prisma/client").$Enums.CheckRegistrationMode;
status: import("@prisma/client").$Enums.CheckStatus;
createdAt: string;
updatedAt: string;
}[];
cashReceipt: {
id: string;
amount: number;
paidAmount: number | null;
transferDate: string | null;
transferTime: string | undefined;
trackingNumber: string | undefined;
trackingCode: string | undefined;
destinationAccountId: string | undefined;
receiptImage: string | undefined;
notes: string | undefined;
expiresAt: string | undefined;
status: import("@prisma/client").$Enums.CashPaymentStatus;
submittedAt: string | undefined;
createdAt: string;
} | undefined;
shipment: {
id: string;
orderId: string;
carrier: string;
trackingNumber: string;
meterage: number;
status: import("@prisma/client").$Enums.ShipmentStatus;
shippedAt: string | null;
deliveredAt: string | null;
} | undefined;
statusHistory: {
id: string;
fromStatus: import("@prisma/client").$Enums.OrderStatus | null;
toStatus: import("@prisma/client").$Enums.OrderStatus;
changedBy: string;
note: string | undefined;
reason: string | undefined;
changedAt: string;
}[];
}[];
salesChartData: number[];
chartAxisLabels: string[];
checkDeadlines: {
id: string;
label: string;
tone: "warning" | "danger" | "neutral";
count: number;
amount: number;
}[];
notifications: {
id: string;
title: string;
body: string;
tone: import("@prisma/client").$Enums.NotificationTone | null;
link: string | null;
isRead: boolean;
sentAt: string;
}[];
messages: {
id: string;
senderName: string;
subject: string;
preview: string;
isRead: boolean;
sentAt: string;
}[];
}>;
getReports(): Promise<{
reportSalesByCompany: {
companyName: string;
orderCount: number;
totalAmount: number;
meterage: number;
}[];
reportOrdersByStatus: {
status: string;
count: number;
}[];
}>;
private buildCheckDeadlines;
}
+219
View File
@@ -0,0 +1,219 @@
"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 __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
const order_status_1 = require("../common/utils/order-status");
const orders_service_1 = require("../orders/orders.service");
let DashboardService = class DashboardService {
prisma;
ordersService;
constructor(prisma, ordersService) {
this.prisma = prisma;
this.ordersService = ordersService;
}
async getDashboard() {
const now = new Date();
const startOfToday = new Date(now);
startOfToday.setHours(0, 0, 0, 0);
const startOfYesterday = new Date(startOfToday);
startOfYesterday.setDate(startOfYesterday.getDate() - 1);
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const startOfChart = new Date(startOfToday);
startOfChart.setDate(startOfChart.getDate() - 27);
const [newOrders, pendingReview, pendingCheck, finalApproval, todayOrders, yesterdayOrders, monthOrders, chartOrders, recentOrders, checks, notifications, messages,] = await Promise.all([
this.prisma.order.count({
where: { createdAt: { gte: startOfToday } },
}),
this.prisma.order.count({
where: { status: { in: order_status_1.ADMIN_STATUS_MAP.pending_review } },
}),
this.prisma.order.count({
where: { status: { in: order_status_1.ADMIN_STATUS_MAP.pending_check } },
}),
this.prisma.order.count({
where: { status: { in: order_status_1.ADMIN_STATUS_MAP.final_approval } },
}),
this.prisma.order.findMany({
where: { createdAt: { gte: startOfToday } },
select: { finalAmount: true, totalAmount: true },
}),
this.prisma.order.findMany({
where: {
createdAt: { gte: startOfYesterday, lt: startOfToday },
},
select: { finalAmount: true, totalAmount: true },
}),
this.prisma.order.findMany({
where: { createdAt: { gte: startOfMonth } },
select: { finalAmount: true, totalAmount: true },
}),
this.prisma.order.findMany({
where: { createdAt: { gte: startOfChart } },
select: {
createdAt: true,
finalAmount: true,
totalAmount: true,
},
}),
this.prisma.order.findMany({
orderBy: { createdAt: 'desc' },
take: 5,
include: {
items: true,
checks: { orderBy: { row: 'asc' } },
cashReceipt: true,
statusHistory: { orderBy: { changedAt: 'asc' } },
shipment: true,
user: true,
company: true,
},
}),
this.prisma.check.findMany({
where: {
status: { not: 'rejected' },
dueDate: {
gte: startOfToday,
lte: new Date(startOfToday.getTime() + 30 * 24 * 60 * 60 * 1000),
},
},
select: { dueDate: true, amount: true },
}),
this.prisma.adminNotification.findMany({
orderBy: { sentAt: 'desc' },
take: 20,
}),
this.prisma.internalMessage.findMany({
orderBy: { sentAt: 'desc' },
take: 20,
}),
]);
const sumAmounts = (rows) => rows.reduce((s, o) => s + (o.finalAmount ?? o.totalAmount ?? 0), 0);
const todaySales = sumAmounts(todayOrders);
const yesterdaySales = sumAmounts(yesterdayOrders);
const monthSales = sumAmounts(monthOrders);
const todaySalesGrowth = yesterdaySales > 0
? Math.round(((todaySales - yesterdaySales) / yesterdaySales) * 100)
: todaySales > 0
? 100
: 0;
const salesByDay = Array.from({ length: 28 }, () => 0);
for (const order of chartOrders) {
const dayIndex = Math.floor((order.createdAt.getTime() - startOfChart.getTime()) /
(24 * 60 * 60 * 1000));
if (dayIndex >= 0 && dayIndex < 28) {
salesByDay[dayIndex] += order.finalAmount ?? order.totalAmount ?? 0;
}
}
const maxSale = Math.max(...salesByDay, 1);
const salesChartData = salesByDay.map((v) => Number((v / maxSale).toFixed(3)));
const checkDeadlines = this.buildCheckDeadlines(checks, startOfToday);
return {
stats: {
newOrders,
pendingReview,
pendingCheck,
finalApproval,
todaySales,
todaySalesGrowth,
monthSales,
},
recentOrders: recentOrders.map((o) => this.ordersService.mapOrder(o, true)),
salesChartData,
chartAxisLabels: ['۱', '۷', '۱۴', '۲۱', '۲۸'],
checkDeadlines,
notifications: notifications.map((n) => ({
id: n.id,
title: n.title,
body: n.body,
tone: n.tone,
link: n.link,
isRead: n.isRead,
sentAt: n.sentAt.toISOString(),
})),
messages: messages.map((m) => ({
id: m.id,
senderName: m.senderName,
subject: m.subject,
preview: m.preview,
isRead: m.isRead,
sentAt: m.sentAt.toISOString(),
})),
};
}
async getReports() {
const orders = await this.prisma.order.findMany({
select: {
companyName: true,
status: true,
totalMeterage: true,
finalAmount: true,
totalAmount: true,
},
});
const byCompany = new Map();
const byStatus = new Map();
for (const order of orders) {
const company = byCompany.get(order.companyName) ?? {
companyName: order.companyName,
orderCount: 0,
totalAmount: 0,
meterage: 0,
};
company.orderCount += 1;
company.totalAmount += order.finalAmount ?? order.totalAmount ?? 0;
company.meterage += order.totalMeterage;
byCompany.set(order.companyName, company);
const label = order_status_1.ORDER_STATUS_LABELS[order.status] ?? (0, order_status_1.toAdminStatus)(order.status);
byStatus.set(label, (byStatus.get(label) ?? 0) + 1);
}
return {
reportSalesByCompany: Array.from(byCompany.values()).sort((a, b) => b.totalAmount - a.totalAmount),
reportOrdersByStatus: Array.from(byStatus.entries()).map(([status, count]) => ({ status, count })),
};
}
buildCheckDeadlines(checks, startOfToday) {
const buckets = [
{ id: 'cd-today', label: 'امروز', tone: 'danger', days: 0 },
{ id: 'cd-3', label: '۳ روز آینده', tone: 'warning', days: 3 },
{ id: 'cd-7', label: '۷ روز آینده', tone: 'warning', days: 7 },
{ id: 'cd-30', label: '۳۰ روز آینده', tone: 'neutral', days: 30 },
];
return buckets.map((bucket) => {
const end = new Date(startOfToday);
end.setDate(end.getDate() + bucket.days);
end.setHours(23, 59, 59, 999);
const matched = checks.filter((c) => {
const d = new Date(c.dueDate);
d.setHours(0, 0, 0, 0);
if (bucket.days === 0) {
return d.getTime() === startOfToday.getTime();
}
return d >= startOfToday && d <= end;
});
return {
id: bucket.id,
label: bucket.label,
tone: bucket.tone,
count: matched.length,
amount: matched.reduce((s, c) => s + c.amount, 0),
};
});
}
};
exports.DashboardService = DashboardService;
exports.DashboardService = DashboardService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService,
orders_service_1.OrdersService])
], DashboardService);
//# sourceMappingURL=dashboard.service.js.map
File diff suppressed because one or more lines are too long