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:
Vendored
+109
@@ -0,0 +1,109 @@
|
||||
"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.ChecksService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let ChecksService = class ChecksService {
|
||||
prisma;
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
async findByOrder(orderId) {
|
||||
const order = await this.prisma.order.findUnique({ where: { id: orderId } });
|
||||
if (!order)
|
||||
throw new common_1.NotFoundException('سفارش یافت نشد');
|
||||
const checks = await this.prisma.check.findMany({
|
||||
where: { orderId },
|
||||
orderBy: { row: 'asc' },
|
||||
});
|
||||
return checks.map((c) => this.map(c));
|
||||
}
|
||||
async updateStatus(id, adminId, dto) {
|
||||
const check = await this.prisma.check.findUnique({
|
||||
where: { id },
|
||||
include: { order: { include: { checks: true } } },
|
||||
});
|
||||
if (!check)
|
||||
throw new common_1.NotFoundException('چک یافت نشد');
|
||||
const updated = await this.prisma.$transaction(async (tx) => {
|
||||
const result = await tx.check.update({
|
||||
where: { id },
|
||||
data: {
|
||||
status: dto.status,
|
||||
notes: dto.note
|
||||
? [check.notes, dto.note].filter(Boolean).join('\n')
|
||||
: check.notes,
|
||||
},
|
||||
});
|
||||
const siblings = await tx.check.findMany({ where: { orderId: check.orderId } });
|
||||
const allApproved = siblings.every((c) => c.status === client_1.CheckStatus.approved);
|
||||
const anyRejected = siblings.some((c) => c.status === client_1.CheckStatus.rejected);
|
||||
let nextStatus = null;
|
||||
if (anyRejected) {
|
||||
nextStatus = client_1.OrderStatus.check_rejected;
|
||||
}
|
||||
else if (allApproved) {
|
||||
nextStatus = client_1.OrderStatus.checks_approved;
|
||||
}
|
||||
else if (dto.status === client_1.CheckStatus.rejected) {
|
||||
nextStatus = client_1.OrderStatus.check_needs_fix;
|
||||
}
|
||||
if (nextStatus && nextStatus !== check.order.status) {
|
||||
await tx.order.update({
|
||||
where: { id: check.orderId },
|
||||
data: { status: nextStatus },
|
||||
});
|
||||
await tx.orderStatusHistory.create({
|
||||
data: {
|
||||
orderId: check.orderId,
|
||||
fromStatus: check.order.status,
|
||||
toStatus: nextStatus,
|
||||
changedBy: `admin:${adminId}`,
|
||||
note: dto.note || `وضعیت چک به ${dto.status} تغییر کرد`,
|
||||
},
|
||||
});
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return this.map(updated);
|
||||
}
|
||||
map(c) {
|
||||
return {
|
||||
id: c.id,
|
||||
orderId: c.orderId,
|
||||
row: c.row,
|
||||
amount: c.amount,
|
||||
dueDate: c.dueDate.toISOString(),
|
||||
sayadId: c.sayadId ?? '',
|
||||
checkNumber: c.checkNumber ?? undefined,
|
||||
ownerNationalId: c.ownerNationalId ?? undefined,
|
||||
ownerFirstName: c.ownerFirstName ?? undefined,
|
||||
ownerLastName: c.ownerLastName ?? undefined,
|
||||
bankName: c.bankName ?? '',
|
||||
branchName: c.branchName ?? undefined,
|
||||
frontImage: c.frontImage ?? undefined,
|
||||
backImage: c.backImage ?? undefined,
|
||||
notes: c.notes ?? undefined,
|
||||
mode: c.mode,
|
||||
status: c.status,
|
||||
createdAt: c.createdAt.toISOString(),
|
||||
updatedAt: c.updatedAt.toISOString(),
|
||||
};
|
||||
}
|
||||
};
|
||||
exports.ChecksService = ChecksService;
|
||||
exports.ChecksService = ChecksService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], ChecksService);
|
||||
//# sourceMappingURL=checks.service.js.map
|
||||
Reference in New Issue
Block a user