Accept customerId when admin creates an order from the customers list.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -138,6 +138,11 @@ export class ChooseSettlementDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class AdminCreateOrderDto {
|
export class AdminCreateOrderDto {
|
||||||
|
/** Customer / user id — preferred when picking from customers list */
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
customerId?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
userId?: string;
|
userId?: string;
|
||||||
|
|||||||
@@ -302,8 +302,15 @@ export class OrdersService {
|
|||||||
});
|
});
|
||||||
if (!company) throw new NotFoundException('شرکت یافت نشد');
|
if (!company) throw new NotFoundException('شرکت یافت نشد');
|
||||||
|
|
||||||
let userId = dto.userId;
|
let userId = dto.customerId || dto.userId;
|
||||||
if (!userId && dto.customerPhone) {
|
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));
|
const phone = normalizePhone(toEnglishDigits(dto.customerPhone));
|
||||||
if (!isValidPhone(phone)) {
|
if (!isValidPhone(phone)) {
|
||||||
throw new BadRequestException('شماره موبایل نامعتبر است');
|
throw new BadRequestException('شماره موبایل نامعتبر است');
|
||||||
@@ -324,7 +331,7 @@ export class OrdersService {
|
|||||||
userId = customer.id;
|
userId = customer.id;
|
||||||
}
|
}
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
throw new BadRequestException('شناسه یا شماره مشتری الزامی است');
|
throw new BadRequestException('انتخاب مشتری الزامی است');
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalMeterage = dto.meterage ?? 0;
|
const totalMeterage = dto.meterage ?? 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user