Skip to content

Commit 7054e31

Browse files
committed
feat: use email service in ticket service
1 parent 4060878 commit 7054e31

1 file changed

Lines changed: 43 additions & 1 deletion

File tree

src/modules/ticket/ticket.service.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import { Injectable, InternalServerErrorException } from "@nestjs/common";
2+
import { EmailService } from "src/core/email/email.service";
3+
import { LoggerService } from "src/core/logger/logger.service";
24
import { PrismaService } from "src/core/prisma/prisma.service";
35
import { CreateTicketDto, StaffSolveTicketDto } from "./dto/ticket.dto";
46

57
@Injectable()
68
export class TicketService {
7-
constructor(private readonly prisma: PrismaService) {}
9+
constructor(
10+
private readonly prisma: PrismaService,
11+
private readonly emailService: EmailService,
12+
private readonly logger: LoggerService,
13+
) {}
814

915
async createTicket(userId: string, createTicketDto: CreateTicketDto) {
1016
try {
@@ -19,8 +25,25 @@ export class TicketService {
1925
},
2026
});
2127

28+
const userInfo = await this.prisma.user.findUnique({
29+
where: {
30+
id: userId,
31+
},
32+
include: {
33+
std_application: {
34+
include: {
35+
std_info: true,
36+
},
37+
},
38+
},
39+
});
40+
41+
if (userInfo) {
42+
await this.emailService.sendTicketCreated(userInfo.email, userInfo.std_application[0]?.std_info?.std_info_nick_name || "", createTicket.ticket_id, "", createTicket.ticket_user_message || "-");
43+
}
2244
return createTicket;
2345
} catch (e) {
46+
this.logger.error(e);
2447
throw new InternalServerErrorException();
2548
}
2649
}
@@ -35,6 +58,7 @@ export class TicketService {
3558
});
3659
return getAll;
3760
} catch (e) {
61+
this.logger.error(e);
3862
throw new InternalServerErrorException();
3963
}
4064
}
@@ -56,8 +80,26 @@ export class TicketService {
5680
},
5781
});
5882

83+
const userInfo = await this.prisma.user.findUnique({
84+
where: {
85+
id: ticketSolved.std_user_id,
86+
},
87+
include: {
88+
std_application: {
89+
include: {
90+
std_info: true,
91+
},
92+
},
93+
},
94+
});
95+
96+
if (userInfo) {
97+
await this.emailService.sendTicketSolved(userInfo.email, userInfo.std_application[0]?.std_info?.std_info_nick_name || "", ticketSolved.ticket_id, ticketSolved.ticket_user_message || "-", ticketSolved.stf_solve_message || "-");
98+
}
99+
59100
return ticketSolved;
60101
} catch (e) {
102+
this.logger.error(e);
61103
throw new InternalServerErrorException();
62104
}
63105
}

0 commit comments

Comments
 (0)