Bug Fixing overall

This commit is contained in:
2024-05-06 20:13:09 +02:00
parent bb5a408cdc
commit 6b61c19bd7
52 changed files with 1926 additions and 1048 deletions

View File

@@ -1,15 +1,13 @@
import { Body, Controller, Get, Param, Post } from '@nestjs/common';
import { Body, Controller, Post } from '@nestjs/common';
import { User } from 'src/models/db.model.js';
import { MailInfo } from 'src/models/main.model.js';
import { MailService } from './mail.service.js';
import { KeycloakUser, MailInfo } from 'src/models/main.model.js';
@Controller('mail')
export class MailController {
constructor(private mailService:MailService){
}
@Post()
sendEMail(@Body() mailInfo: MailInfo): Promise< KeycloakUser> {
return this.mailService.sendInquiry(mailInfo);
}
constructor(private mailService: MailService) {}
@Post()
sendEMail(@Body() mailInfo: MailInfo): Promise<User> {
return this.mailService.sendInquiry(mailInfo);
}
}

View File

@@ -1,22 +1,27 @@
import { Module } from '@nestjs/common';
import { MailService } from './mail.service.js';
import { MailController } from './mail.controller.js';
import { MailerModule } from '@nestjs-modules/mailer';
import path, { join } from 'path';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter.js';
import { Module } from '@nestjs/common';
import path, { join } from 'path';
import { fileURLToPath } from 'url';
import { AuthModule } from '../auth/auth.module.js';
import { DrizzleModule } from '../drizzle/drizzle.module.js';
import { FileService } from '../file/file.service.js';
import { UserModule } from '../user/user.module.js';
import { UserService } from '../user/user.service.js';
import { MailController } from './mail.controller.js';
import { MailService } from './mail.service.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@Module({
imports: [AuthModule,
imports: [
DrizzleModule,
UserModule,
MailerModule.forRoot({
// transport: 'smtps://user@example.com:topsecret@smtp.example.com',
// or
transport: {
host: 'email-smtp.us-east-2.amazonaws.com',
secure: false,
port:587,
port: 587,
// auth: {
// user: 'andreas.knuth@gmail.com',
// pass: 'ksnh xjae dqbv xana',
@@ -38,7 +43,7 @@ const __dirname = path.dirname(__filename);
},
}),
],
providers: [MailService],
controllers: [MailController]
providers: [MailService, UserService, FileService],
controllers: [MailController],
})
export class MailModule {}

View File

@@ -1,26 +1,41 @@
import { MailerService } from '@nestjs-modules/mailer';
import { Injectable } from '@nestjs/common';
import { AuthService } from '../auth/auth.service.js';
import { KeycloakUser, MailInfo } from '../models/main.model.js';
import path, { join } from 'path';
import { fileURLToPath } from 'url';
import { User } from '../models/db.model.js';
import { MailInfo } from '../models/main.model.js';
import { UserService } from '../user/user.service.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@Injectable()
export class MailService {
constructor(private mailerService: MailerService, private authService:AuthService) {}
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,
inquiry:mailInfo.sender.comments
},
});
return user
}
constructor(
private mailerService: MailerService,
private userService: UserService,
) {}
async sendInquiry(mailInfo: MailInfo): Promise<User> {
//const user = await this.authService.getUser(mailInfo.userId) as KeycloakUser;
const user = await this.userService.getUserByMail(mailInfo.email);
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
template: join(__dirname, '../..', 'mail/templates/inquiry.hbs'),
context: {
// ✏️ filling curly brackets with content
name: user.firstname,
inquiry: mailInfo.sender.comments,
internalListingNumber: mailInfo.listing.internalListingNumber,
title: mailInfo.listing.title,
iname: mailInfo.sender.name,
phone: mailInfo.sender.phoneNumber,
email: mailInfo.sender.email,
},
});
return user;
}
}