11import { Injectable , InternalServerErrorException } from "@nestjs/common" ;
2+ import { EmailService } from "src/core/email/email.service" ;
3+ import { LoggerService } from "src/core/logger/logger.service" ;
24import { PrismaService } from "src/core/prisma/prisma.service" ;
35import { CreateTicketDto , StaffSolveTicketDto } from "./dto/ticket.dto" ;
46
57@Injectable ( )
68export 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