update
This commit is contained in:
@@ -5,15 +5,19 @@ import { OrderCreatedEvent } from '../events/order.events';
|
|||||||
import { Permission } from 'src/common/enums/permission.enum';
|
import { Permission } from 'src/common/enums/permission.enum';
|
||||||
import { NotifTitleEnum } from 'src/modules/notifications/interfaces/notification.interface';
|
import { NotifTitleEnum } from 'src/modules/notifications/interfaces/notification.interface';
|
||||||
import { NotificationService } from 'src/modules/notifications/services/notification.service';
|
import { NotificationService } from 'src/modules/notifications/services/notification.service';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OrderListeners {
|
export class OrderListeners {
|
||||||
private readonly logger = new Logger(OrderListeners.name);
|
private readonly logger = new Logger(OrderListeners.name);
|
||||||
|
private orderCreatedSmsTemplateId: string;
|
||||||
constructor(
|
constructor(
|
||||||
private readonly adminService: AdminRepository,
|
private readonly adminService: AdminRepository,
|
||||||
private readonly notificationService: NotificationService,
|
private readonly notificationService: NotificationService,
|
||||||
) {}
|
private readonly configService: ConfigService,
|
||||||
|
) {
|
||||||
|
this.orderCreatedSmsTemplateId = this.configService.get<string>('ORDER_CREATED_SMS_TEMPLATE_ID') ?? '123';
|
||||||
|
}
|
||||||
|
|
||||||
@OnEvent(OrderCreatedEvent.name)
|
@OnEvent(OrderCreatedEvent.name)
|
||||||
async handleOrderCreated(event: OrderCreatedEvent) {
|
async handleOrderCreated(event: OrderCreatedEvent) {
|
||||||
@@ -21,7 +25,7 @@ export class OrderListeners {
|
|||||||
this.logger.log(
|
this.logger.log(
|
||||||
`Order created event received: ${event.orderId} for restaurant: ${event.restaurantId} and order number: ${event.orderNumber}`,
|
`Order created event received: ${event.orderId} for restaurant: ${event.restaurantId} and order number: ${event.orderNumber}`,
|
||||||
);
|
);
|
||||||
// get admnin os restuaraant that have pager permissuins
|
// get admnin os restuaraant that have order permissuins
|
||||||
const admins = await this.adminService.findAdminsWithPermission(event.restaurantId, Permission.MANAGE_ORDERS);
|
const admins = await this.adminService.findAdminsWithPermission(event.restaurantId, Permission.MANAGE_ORDERS);
|
||||||
const recipients = admins.map(admin => ({
|
const recipients = admins.map(admin => ({
|
||||||
adminId: admin.id,
|
adminId: admin.id,
|
||||||
@@ -32,7 +36,7 @@ export class OrderListeners {
|
|||||||
title: NotifTitleEnum.ORDER_CREATED,
|
title: NotifTitleEnum.ORDER_CREATED,
|
||||||
content: `Order ${event.orderNumber} has been created successfully`,
|
content: `Order ${event.orderNumber} has been created successfully`,
|
||||||
sms: {
|
sms: {
|
||||||
templateId: '1234567890',
|
templateId: this.orderCreatedSmsTemplateId,
|
||||||
parameters: {
|
parameters: {
|
||||||
orderNumber: event.orderNumber,
|
orderNumber: event.orderNumber,
|
||||||
},
|
},
|
||||||
@@ -54,7 +58,7 @@ export class OrderListeners {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error(
|
this.logger.error(
|
||||||
`Failed to send notification for pager created event: ${event.restaurantId}`,
|
`Failed to send notification for order created event: ${event.restaurantId}`,
|
||||||
error instanceof Error ? error.stack : String(error),
|
error instanceof Error ? error.stack : String(error),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
||||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
/**
|
|
||||||
* DTO for updating user profile.
|
|
||||||
* Mirrors fields defined on the User entity and keeps everything optional
|
|
||||||
* to allow partial updates.
|
|
||||||
*/
|
|
||||||
export class UpdateUserDto {
|
export class UpdateUserDto {
|
||||||
@ApiPropertyOptional({ description: "User's first name", example: 'John' })
|
@ApiPropertyOptional({ description: "User's first name", example: 'John' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@@ -32,4 +27,9 @@ export class UpdateUserDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
gender?: boolean;
|
gender?: boolean;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'Avatar URL' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
avatarUrl?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,11 +42,8 @@ export class User extends BaseEntity {
|
|||||||
@Property({ default: true })
|
@Property({ default: true })
|
||||||
gender?: boolean;
|
gender?: boolean;
|
||||||
|
|
||||||
// @Property({ default: 0, type: 'int' })
|
@Property({ nullable: true })
|
||||||
// wallet: number = 0;
|
avatarUrl?: string;
|
||||||
|
|
||||||
// @Property({ default: 0, type: 'int' })
|
|
||||||
// points: number = 0;
|
|
||||||
|
|
||||||
@OneToMany(() => UserAddress, address => address.user, {
|
@OneToMany(() => UserAddress, address => address.user, {
|
||||||
cascade: [Cascade.ALL],
|
cascade: [Cascade.ALL],
|
||||||
|
|||||||
Reference in New Issue
Block a user