Skip to content

Commit

Permalink
Contact (#105)
Browse files Browse the repository at this point in the history
* KYC save data

* KYC save his data

* Module to check KYC field

* Module to check KYC field

* Add Waiting List module

* Module for waiting

* fix tests

* Finished Waiting list

* Finished contact form

---------

Co-authored-by: Abhishek Shandilya <[email protected]>
  • Loading branch information
Frdrcpeter007 and abhishandilya authored Oct 31, 2023
1 parent d40b205 commit fd1b50f
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SMSModule } from './modules/sms/sms.module';
import { SavingModule } from './modules/saving/saving.module';
import { OperationModule } from './modules/operation-saving/operation.module';
import { WaitingModule } from './modules/waiting-list/waiting.module';
import { ContactModule } from './modules/contact/contact.module';

@Module({
imports: [
Expand All @@ -39,6 +40,7 @@ import { WaitingModule } from './modules/waiting-list/waiting.module';
CachingModule,
MailModule,
WaitingModule,
ContactModule,
AuthModule,
SessionModule,
AdministrationSvcModule,
Expand Down
25 changes: 25 additions & 0 deletions src/modules/contact/contact.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
Body,
Controller,
Post
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { _403, _404, _409 } from '../../common/constants/errors';
import { ContactService } from './contact.service';
import { Public } from 'src/common/decorators/public.decorator';
import { CreateContactDto } from './dto/contact.dto';

@ApiTags('Contacts')
@Controller('contacts')
export class ContactController {
constructor(private readonly contactService: ContactService) {}

@Post()
@Public()
@ApiOperation({ summary: 'Save contact information' })
async add(@Body() contactDto: CreateContactDto) {
return await this.contactService.add(contactDto);
}

}

17 changes: 17 additions & 0 deletions src/modules/contact/contact.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Contact } from './entities/contact.entity';
import { ContactController } from './contact.controller';
import { ContactService } from './contact.service';
import { MailModule } from '../mail/mail.module';

@Module({
imports: [
TypeOrmModule.forFeature([Contact]),
MailModule,
],
controllers: [ContactController],
providers: [ContactService],
exports: [ContactService],
})
export class ContactModule {}
39 changes: 39 additions & 0 deletions src/modules/contact/contact.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { _404 } from '../../common/constants/errors';
import { Contact } from './entities/contact.entity';
import { CreateContactDto } from './dto/contact.dto';
import { MailService } from '../mail/mail.service';

@Injectable()
export class ContactService {
constructor(
@InjectRepository(Contact)
private contactRepository: Repository<Contact>,
private readonly mailService: MailService,

) {}

async add(contact: CreateContactDto): Promise<Contact> {

const newWaiting = this.contactRepository.create({
fullname: contact.fullname,
email: contact.email,
object: contact.object,
message: contact.message
});

const contactSave = this.contactRepository.save(newWaiting);

await this.mailService.receiveMailToWiiqare(
contact.email,
contact.fullname,
contact.object,
contact.message
);

return contactSave
}

}
26 changes: 26 additions & 0 deletions src/modules/contact/dto/contact.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Transform } from 'class-transformer';
import {
IsEmail,
IsNotEmpty,
IsString
} from 'class-validator';

export class CreateContactDto {

@IsNotEmpty()
@IsString()
fullname: string;

@IsNotEmpty()
@IsString()
@IsEmail()
email: string;

@IsNotEmpty()
@IsString()
object: string;

@IsNotEmpty()
@IsString()
message: string;
}
19 changes: 19 additions & 0 deletions src/modules/contact/entities/contact.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BaseEntity } from '../../../db/base-entity';
import { Entity, Column } from 'typeorm';

@Entity()
export class Contact extends BaseEntity {

@Column({nullable: false})
fullname: string;

@Column({nullable: false})
email: string;

@Column({nullable: false})
object: string;

@Column({nullable: false})
message: string;

}
19 changes: 19 additions & 0 deletions src/modules/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,23 @@ export class MailService {
},
});
}

async receiveMailToWiiqare(
email: string,
name: string,
object: string,
message: string
): Promise<void> {
await this.mailerService.sendMail({
to: "[email protected]",
subject: object,
template: './contact',
context: {
name: name.toUpperCase(),
email,
message,
year: ${new Date().getFullYear()}`,
},
});
}
}
2 changes: 1 addition & 1 deletion src/modules/waiting-list/waiting.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import { MailModule } from '../mail/mail.module';
],
controllers: [WaitingController],
providers: [WaitingService],
exports: [WaitingService],
exports: [WaitingService],
})
export class WaitingModule {}
Loading

0 comments on commit fd1b50f

Please sign in to comment.