Accept customerId when admin creates an order from the customers list.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-11 18:17:58 +02:00
co-authored by Cursor
parent 63646b9f01
commit 507fc99065
2 changed files with 15 additions and 3 deletions
+5
View File
@@ -138,6 +138,11 @@ export class ChooseSettlementDto {
}
export class AdminCreateOrderDto {
/** Customer / user id — preferred when picking from customers list */
@IsOptional()
@IsString()
customerId?: string;
@IsOptional()
@IsString()
userId?: string;
+10 -3
View File
@@ -302,8 +302,15 @@ export class OrdersService {
});
if (!company) throw new NotFoundException('شرکت یافت نشد');
let userId = dto.userId;
if (!userId && dto.customerPhone) {
let userId = dto.customerId || dto.userId;
if (userId) {
const existing = await this.prisma.customer.findUnique({
where: { id: userId },
});
if (!existing) {
throw new BadRequestException('مشتری انتخاب‌شده یافت نشد');
}
} else if (dto.customerPhone) {
const phone = normalizePhone(toEnglishDigits(dto.customerPhone));
if (!isValidPhone(phone)) {
throw new BadRequestException('شماره موبایل نامعتبر است');
@@ -324,7 +331,7 @@ export class OrdersService {
userId = customer.id;
}
if (!userId) {
throw new BadRequestException('شناسه یا شماره مشتری الزامی است');
throw new BadRequestException('انتخاب مشتری الزامی است');
}
const totalMeterage = dto.meterage ?? 0;