update order
deploy to danak / build_and_deploy (push) Has been cancelled

This commit is contained in:
2026-07-21 12:18:16 +03:30
parent a69b75ccdd
commit 79952c117f
5 changed files with 79 additions and 37 deletions
+14
View File
@@ -0,0 +1,14 @@
{
"folders": [
{
"path": "."
},
{
"path": "../negareh-admin"
},
{
"path": "../negareh-console"
}
],
"settings": {}
}
@@ -115,6 +115,28 @@ export class ChattService {
return data return data
} }
createChatInTransaction(
em: EntityManager,
refId: string,
dto: Pick<CreateChatDto, 'content' | 'attachments'>,
user: User,
): Chat | null {
const { content = '', attachments } = dto;
if (!content.trim() && (!attachments || attachments.length === 0)) {
return null;
}
const chat = em.create(Chat, {
content,
attachments,
user,
refId,
});
em.persist(chat);
return chat;
}
async createChat(refId: string, dto: CreateChatDto, user?: User, admin?: Admin) { async createChat(refId: string, dto: CreateChatDto, user?: User, admin?: Admin) {
const { content = '', attachments, parentId } = dto const { content = '', attachments, parentId } = dto
+18 -20
View File
@@ -40,6 +40,24 @@ export class CreateRequestItemDto {
@ValidateNested({ each: true }) @ValidateNested({ each: true })
@Type(() => RequestItemDto) @Type(() => RequestItemDto)
attributes?: RequestItemDto[]; attributes?: RequestItemDto[];
}
export class CreateRequestDto {
@IsArray()
@ApiProperty({
isArray: true,
type: [CreateRequestItemDto],
example: [
{
productId: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
attributes: [{ fieldId: 'field_01', value: 'blue' }],
},
],
})
@IsNotEmpty()
@ArrayMinSize(1, { message: 'At least one item is required' })
@Type(() => CreateRequestItemDto)
items: CreateRequestItemDto[];
@ApiPropertyOptional() @ApiPropertyOptional()
@IsOptional() @IsOptional()
@@ -53,23 +71,3 @@ export class CreateRequestItemDto {
@Type(() => AttachmentDto) @Type(() => AttachmentDto)
attachments?: IAttachment[]; attachments?: IAttachment[];
} }
export class CreateRequestDto {
@IsArray()
@ApiProperty({
isArray: true,
type: [CreateRequestItemDto],
example: [
{
productId: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
attributes: [{ fieldId: 'field_01', value: 'blue' }],
attachments: [{ type: 'image', url: 'https://example.com/photo.jpg' }],
description: 'توضیحات',
},
],
})
@IsNotEmpty()
@ArrayMinSize(1, { message: 'At least one item is required' })
@Type(() => CreateRequestItemDto)
items: CreateRequestItemDto[];
}
@@ -2,7 +2,7 @@ import { Entity, Index, ManyToOne, OptionalProps, Property } from '@mikro-orm/co
import { Product } from 'src/modules/product/entities/product.entity'; import { Product } from 'src/modules/product/entities/product.entity';
import { BaseEntity } from 'src/common/entities/base.entity'; import { BaseEntity } from 'src/common/entities/base.entity';
import { Request } from './request.entity'; import { Request } from './request.entity';
import { IAttachment, IField } from '../interface/request.interface'; import { IField } from '../interface/request.interface';
@Entity({ tableName: 'request_items' }) @Entity({ tableName: 'request_items' })
@Index({ properties: ['request'] }) @Index({ properties: ['request'] })
@@ -17,11 +17,4 @@ export class RequestItem extends BaseEntity {
@ManyToOne(() => Request) @ManyToOne(() => Request)
request!: Request; request!: Request;
@Property({ type: 'text', nullable: true })
description?: string;
@Property({ type: 'json', nullable: true })
attachments?: IAttachment[] // user attachments like voice and photos
} }
+24 -9
View File
@@ -27,7 +27,7 @@ export class RequestService {
) { } ) { }
async create(createRequestDto: CreateRequestDto, userId: string) { async create(createRequestDto: CreateRequestDto, userId: string) {
const { items } = createRequestDto; const { items, description, attachments } = createRequestDto;
const user = await this.userService.findOrFail(userId); const user = await this.userService.findOrFail(userId);
@@ -43,12 +43,17 @@ export class RequestService {
request, request,
product, product,
attributes: item.attributes, attributes: item.attributes,
description: item.description,
attachments: item.attachments,
}); });
request.items.add(requestItem); request.items.add(requestItem);
} }
this.chatService.createChatInTransaction(
em,
request.id,
{ content: description ?? '', attachments },
user,
);
await em.flush(); await em.flush();
return request; return request;
}); });
@@ -134,7 +139,7 @@ export class RequestService {
throw new NotFoundException('Request not found'); throw new NotFoundException('Request not found');
} }
const { items } = updateRequestDto; const { items, description, attachments } = updateRequestDto;
if (items?.length) { if (items?.length) {
return this.em.transactional(async (em) => { return this.em.transactional(async (em) => {
request.items.removeAll(); request.items.removeAll();
@@ -146,12 +151,17 @@ export class RequestService {
request, request,
product, product,
attributes: item.attributes, attributes: item.attributes,
description: item.description,
attachments: item.attachments,
}); });
request.items.add(requestItem); request.items.add(requestItem);
} }
this.chatService.createChatInTransaction(
em,
request.id,
{ content: description ?? '', attachments },
request.user,
);
await em.flush(); await em.flush();
return request; return request;
}); });
@@ -169,7 +179,7 @@ export class RequestService {
throw new NotFoundException('Request not found'); throw new NotFoundException('Request not found');
} }
const { items } = updateRequestDto; const { items, description, attachments } = updateRequestDto;
if (items?.length) { if (items?.length) {
return this.em.transactional(async (em) => { return this.em.transactional(async (em) => {
request.items.removeAll(); request.items.removeAll();
@@ -181,12 +191,17 @@ export class RequestService {
request, request,
product, product,
attributes: item.attributes, attributes: item.attributes,
description: item.description,
attachments: item.attachments,
}); });
request.items.add(requestItem); request.items.add(requestItem);
} }
this.chatService.createChatInTransaction(
em,
request.id,
{ content: description ?? '', attachments },
request.user,
);
await em.flush(); await em.flush();
return request; return request;
}); });