Auth korrigiert & mail based on SES
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
|
||||
import { MailService } from './mail.service.js';
|
||||
import { MailInfo } from '../models/server.model.js';
|
||||
import { KeycloakUser, MailInfo } from 'src/models/main.model.js';
|
||||
|
||||
|
||||
@Controller('mail')
|
||||
export class MailController {
|
||||
constructor(private mailService:MailService){
|
||||
|
||||
}
|
||||
@Post(':id')
|
||||
sendEMail(@Param('id') id:string,@Body() mailInfo: MailInfo): any {
|
||||
return this.mailService.sendInquiry(id,mailInfo);
|
||||
@Post()
|
||||
sendEMail(@Body() mailInfo: MailInfo): Promise< KeycloakUser> {
|
||||
return this.mailService.sendInquiry(mailInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import { MailerService } from '@nestjs-modules/mailer';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { AuthService } from '../auth/auth.service.js';
|
||||
import { MailInfo } from '../models/server.model.js';
|
||||
import { User } from 'src/models/main.model.js';
|
||||
import { KeycloakUser, MailInfo, User } from '../models/main.model.js';
|
||||
|
||||
@Injectable()
|
||||
export class MailService {
|
||||
constructor(private mailerService: MailerService, private authService:AuthService) {}
|
||||
|
||||
async sendInquiry(userId:string,mailInfo: MailInfo) {
|
||||
const user = await this.authService.getUser(userId) as User;
|
||||
async sendInquiry(mailInfo: MailInfo):Promise<KeycloakUser> {
|
||||
const user = await this.authService.getUser(mailInfo.userId) as KeycloakUser;
|
||||
console.log(JSON.stringify(user));
|
||||
await this.mailerService.sendMail({
|
||||
to: user.email,
|
||||
from: '"Bizmatch Team" <info@bizmatch.net>', // override default from
|
||||
subject: `Inquiry from ${mailInfo.sender.name}`,
|
||||
template: './inquiry', // `.hbs` extension is appended automatically
|
||||
context: { // ✏️ filling curly brackets with content
|
||||
name: user.firstname,
|
||||
name: user.firstName,
|
||||
inquiry:mailInfo.sender.comments
|
||||
},
|
||||
});
|
||||
return user
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
import { Entity } from "redis-om";
|
||||
import { UserBase } from "./main.model.js";
|
||||
|
||||
export interface MailInfo {
|
||||
sender: Sender;
|
||||
userId: string;
|
||||
}
|
||||
export interface Sender {
|
||||
name: string;
|
||||
email: string;
|
||||
phoneNumber: string;
|
||||
state: string;
|
||||
comments: string;
|
||||
}
|
||||
|
||||
export interface Geo {
|
||||
id: number;
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user