Skip to content

Commit

Permalink
feature/EF-201 [Booking]Send email when booking is created
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhhTien authored and nghiavohuynhdai committed Mar 18, 2024
1 parent 14830ef commit 3916651
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 12 deletions.
17 changes: 15 additions & 2 deletions src/consultant-booking/services/booking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import { CreateConsultantBookingDto } from '@consultant-booking/dto/booking.dto'
import { StaffRepository } from '@staff/repositories/staff.repository'
import { PaginationParams } from '@common/decorators/pagination.decorator'
import { FilterQuery } from 'mongoose'
import { MailerService } from '@nestjs-modules/mailer'
import * as moment from 'moment'

@Injectable()
export class ConsultantBookingService {
constructor(
private readonly consultantBookingRepository: ConsultantBookingRepository,
private readonly staffRepository: StaffRepository,
private readonly categoryRepository: CategoryRepository
private readonly categoryRepository: CategoryRepository,
private readonly mailerService: MailerService
) {}

public async createBooking(createConsultantBookingDto: CreateConsultantBookingDto) {
Expand Down Expand Up @@ -55,6 +58,16 @@ export class ConsultantBookingService {
})

// 4. Send email/notification to customer
await this.mailerService.sendMail({
to: booking.customer.email,
subject: `[Furnique] Xác nhận đặt lịch tư vấn viên`,
template: 'consultant-booking-created',
context: {
...booking.toJSON(),
bookingDate: moment(booking.bookingDate).format('YYYY-MM-DD HH:mm'),
notes: booking.notes ?? 'Không'
}
})
// 5. Send notification to staff

return new IDResponse(booking._id)
Expand All @@ -80,7 +93,7 @@ export class ConsultantBookingService {
status: {
$ne: BookingStatus.DELETED
}
},
}
})
if (!booking) throw new AppException(Errors.CONSULTANT_BOOKING_NOT_FOUND)

Expand Down
4 changes: 2 additions & 2 deletions src/order/services/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ export class OrderService {

// 7. Send email/notification to customer
this.logger.log(`7. Send email/notification to customer`)
this.mailerService.sendMail({
await this.mailerService.sendMail({
to: order.customer.email,
subject: `[Furnique] Thông báo hủy đơn hàng #${order.orderId}`,
template: 'order-canceled',
context: {
...order,
...order.toJSON(),
_id: order._id,
orderId: order.orderId,
customer: order.customer,
Expand Down
4 changes: 2 additions & 2 deletions src/payment/services/payment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ export class PaymentService {
}
)
// 9. Send email/notification to customer
this.mailerService.sendMail({
await this.mailerService.sendMail({
to: order.customer.email,
subject: `[Furnique] Đã nhận đơn hàng #${order.orderId}`,
template: 'order-created',
context: {
...order,
...order.toJSON(),
_id: order._id,
orderId: order.orderId,
customer: order.customer,
Expand Down
2 changes: 1 addition & 1 deletion src/task/services/task.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class TaskService {
const order = await this.orderService.completeOrder(orderId, userId, UserRole.DELIVERY_STAFF, session)

// 3. Send email/notification to customer
this.mailerService.sendMail({
await this.mailerService.sendMail({
to: order.customer.email,
subject: `[Furnique] Đơn hàng #${order.orderId} đã được giao thành công`,
template: 'order-completed',
Expand Down
16 changes: 16 additions & 0 deletions src/templates/consultant-booking-created.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<pre style="font-family: Helvetica, sans-serif; font-size: 1.5em;">
<h2>Xác nhận đặt lịch tư vấn viên</h2>
Thân gửi <b><%= customer.firstName %> <%= customer.lastName %></b>,

Chúng tôi xác nhận rằng bạn đã đặt lịch hẹn với tư vấn viên về nội thất của chúng tôi.

<b>Thông tin chi tiết:</b>
Tên: <%= customer.firstName %> <%= customer.lastName %>
Số điện thoại: <%= customer.phone %>
Thời gian: <%= bookingDate %>
<b>Tư vấn viên: <%= consultant.firstName %> <%= consultant.lastName %></b>
Ghi chú: <%= notes %>

Nếu bạn có bất kỳ câu hỏi hoặc cần thay đổi lịch hẹn, vui lòng liên hệ với chúng tôi qua thông tin dưới đây:
</pre>
<%- include('web-footer') -%>
4 changes: 2 additions & 2 deletions src/templates/management-footer.ejs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<pre style="font-family: Arial, Helvetica, sans-serif; font-size: 1.5em;">
□□□───────────────────────────────
Trân trọng,
Trân trọng,
Furnique

Email: furnique.contact@gmail.com
Email: contact@furnique.tech
Website: <a href="https://management.furnique.tech">https://management.furnique.tech</a>
────────────────────────────────□□□
</pre>
16 changes: 16 additions & 0 deletions src/templates/visit-showroom-booking-created.ejs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<pre style="font-family: Helvetica, sans-serif; font-size: 1.5em;">
<h2>Xác nhận hẹn tham quan showroom</h2>
Thân gửi <b><%= customer.firstName %> <%= customer.lastName %>,</b>

Chúng tôi xác nhận rằng bạn đã đặt lịch hẹn tham quan showroom của chúng tôi.

<b>Thông tin chi tiết:</b>
Tên: <%= customer.firstName %> <%= customer.lastName %>
Số điện thoại: <%= customer.phone %>
Thời gian: <%= bookingDate %>
Địa điểm: Lô E2a-7, Đường D1, Long Thạnh Mỹ, Thành Phố Thủ Đức, Thành phố Hồ Chí Minh
Ghi chú: <%= notes %>

Nếu bạn có bất kỳ câu hỏi hoặc cần thay đổi lịch hẹn, vui lòng liên hệ với chúng tôi qua thông tin dưới đây:
</pre>
<%- include('web-footer') -%>
4 changes: 2 additions & 2 deletions src/templates/web-footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Cảm ơn bạn đã sử dụng dịch vụ của chúng tôi!

Trân trọng,
Furnique
Furnique

Email: furnique.contact@gmail.com
Email: contact@furnique.tech
Website: <a href="https://www.furnique.tech">https://www.furnique.tech</a>

────────────────────────────────□□□
Expand Down
15 changes: 14 additions & 1 deletion src/visit-showroom-booking/services/booking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { CategoryRepository } from '@category/repositories/category.repository'
import { VisitShowroomBookingRepository } from '@visit-showroom-booking/repositories/booking.repository'
import { BookingHistoryDto } from '@visit-showroom-booking/schemas/booking.schema'
import { CustomerRepository } from '@customer/repositories/customer.repository'
import { MailerService } from '@nestjs-modules/mailer'
import * as moment from 'moment'

@Injectable()
export class VisitShowroomBookingService {
constructor(
private readonly visitShowroomBookingRepository: VisitShowroomBookingRepository,
private readonly customerRepository: CustomerRepository,
private readonly categoryRepository: CategoryRepository
private readonly categoryRepository: CategoryRepository,
private readonly mailerService: MailerService
) {}

public async createBooking(createVisitShowroomBookingDto: CreateVisitShowroomBookingDto) {
Expand Down Expand Up @@ -54,6 +57,16 @@ export class VisitShowroomBookingService {
})

// 4. Send email/notification to customer
await this.mailerService.sendMail({
to: booking.customer.email,
subject: `[Furnique] Xác nhận hẹn tham quan showroom`,
template: 'visit-showroom-booking-created',
context: {
...booking.toJSON(),
bookingDate: moment(booking.bookingDate).format('YYYY-MM-DD HH:mm'),
notes: booking.notes ?? 'Không'
}
})
// 5. Send notification to staff

return new IDResponse(booking._id)
Expand Down

0 comments on commit 3916651

Please sign in to comment.