@@ -4,31 +4,39 @@ import { BotMailDto } from '@/dtos/bot-mail.dto'
44import { SendMailQueue } from '@/queues/mail.queue'
55import { eq } from 'drizzle-orm'
66import { Service } from 'typedi'
7+ import { ChannelService } from './channels.service'
78
89@Service ( )
910export class BotMailService {
10- constructor ( private readonly sendMailQueue : SendMailQueue ) { }
11+ constructor (
12+ private readonly sendMailQueue : SendMailQueue ,
13+ private readonly channelService : ChannelService ,
14+ ) { }
1115
1216 async sendMail ( fields : BotMailDto ) {
13- const { from, subject, template, to, variables } = fields
17+ const { from, subject, template, to, contactId } = fields
1418
15- const userId = '1'
19+ const channel = await this . channelService . findOneByContactId ( contactId )
1620
17- const [ user ] = await db
21+ if ( ! channel ) {
22+ return
23+ }
24+
25+ const [ userSetting ] = await db
1826 . select ( )
1927 . from ( settings )
20- . where ( eq ( settings . userId , userId ) )
28+ . where ( eq ( settings . userId , channel . userId ) )
2129
22- if ( ! user ) {
30+ if ( ! userSetting ) {
2331 return
2432 }
2533
26- const { email, password } = user . email
34+ const { email, password } = userSetting . email
2735
2836 await this . sendMailQueue . addJob ( {
2937 from,
3038 to,
31- props : variables as any ,
39+ props : { } as any ,
3240 subject,
3341 template : template as any ,
3442 pass : password ,
0 commit comments