chore: contact us module
This commit is contained in:
@@ -1,9 +1,19 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsString } from "class-validator";
|
||||
import { IsEmail, IsNotEmpty, IsString } from "class-validator";
|
||||
|
||||
import { ContactUsMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
export class CreateContactUsDto {
|
||||
@IsNotEmpty({ message: ContactUsMessage.FULLNAME_IS_REQUIRED })
|
||||
@IsString({ message: ContactUsMessage.FULLNAME_STRING })
|
||||
@ApiProperty({ description: "full name of person need to create contact us", example: "متین جمشیدی" })
|
||||
fullName: string;
|
||||
|
||||
@IsNotEmpty({ message: ContactUsMessage.FULLNAME_STRING })
|
||||
@IsEmail()
|
||||
@ApiProperty({ description: "email of person need to contact us", example: "matin@gmail.com" })
|
||||
email: string;
|
||||
|
||||
@IsNotEmpty({ message: ContactUsMessage.TITLE_IS_REQUIRED })
|
||||
@IsString({ message: ContactUsMessage.TITLE_STRING })
|
||||
@ApiProperty({ description: "title of contact us", example: "عنوان پیام" })
|
||||
|
||||
@@ -6,9 +6,7 @@ import { SearchContactUsQueryDto } from "./DTO/search-contact-us-query.dto";
|
||||
import { ContactUsService } from "./providers/contact-us.service";
|
||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||
import { Roles } from "../../common/decorators/roles.decorator";
|
||||
import { UserDec } from "../../common/decorators/user.decorator";
|
||||
import { ParamDto } from "../../common/DTO/param.dto";
|
||||
import { User } from "../users/entities/user.entity";
|
||||
import { RoleEnum } from "../users/enums/role.enum";
|
||||
|
||||
@Controller("contact-us")
|
||||
@@ -16,11 +14,10 @@ import { RoleEnum } from "../users/enums/role.enum";
|
||||
export class ContactUsController {
|
||||
constructor(private readonly contactUsService: ContactUsService) {}
|
||||
|
||||
@AuthGuards()
|
||||
@ApiOperation({ summary: "Create a new contact us" })
|
||||
@Post()
|
||||
createContactUs(@UserDec() user: User, @Body() createContactUsDto: CreateContactUsDto) {
|
||||
return this.contactUsService.createContactUs(user.id, createContactUsDto);
|
||||
createContactUs(@Body() createContactUsDto: CreateContactUsDto) {
|
||||
return this.contactUsService.createContactUs(createContactUsDto);
|
||||
}
|
||||
|
||||
//******************** */
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Column, Entity, ManyToOne } from "typeorm";
|
||||
import { Column, Entity } from "typeorm";
|
||||
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { User } from "../../users/entities/user.entity";
|
||||
|
||||
@Entity()
|
||||
export class ContactUs extends BaseEntity {
|
||||
@@ -11,12 +10,15 @@ export class ContactUs extends BaseEntity {
|
||||
@Column({ type: "varchar", length: 150, nullable: false })
|
||||
title: string;
|
||||
|
||||
@Column({ type: "varchar", length: 350 })
|
||||
fullName: string;
|
||||
|
||||
@Column({ type: "varchar", length: 150 })
|
||||
email: string;
|
||||
|
||||
@Column({ type: "text", nullable: false })
|
||||
content: string;
|
||||
|
||||
@ManyToOne(() => User, (user) => user.contactUs, { nullable: false, onDelete: "CASCADE" })
|
||||
user: User;
|
||||
|
||||
@Column({ type: "boolean", default: false })
|
||||
isRead: boolean;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
|
||||
import { CommonMessage, ContactUsMessage } from "../../../common/enums/message.enum";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||
import { CreateContactUsDto } from "../DTO/create-contact-us.dto";
|
||||
import { SearchContactUsQueryDto } from "../DTO/search-contact-us-query.dto";
|
||||
@@ -9,19 +8,13 @@ import { ContactUsRepository } from "../repositories/contact-us.repository";
|
||||
|
||||
@Injectable()
|
||||
export class ContactUsService {
|
||||
constructor(
|
||||
private readonly contactUsRepository: ContactUsRepository,
|
||||
private readonly usersService: UsersService,
|
||||
) {}
|
||||
constructor(private readonly contactUsRepository: ContactUsRepository) {}
|
||||
|
||||
//****************************** */
|
||||
|
||||
async createContactUs(userId: string, createContactUsDto: CreateContactUsDto) {
|
||||
const { user } = await this.usersService.findOneById(userId);
|
||||
|
||||
async createContactUs(createContactUsDto: CreateContactUsDto) {
|
||||
const contactUs = this.contactUsRepository.create({
|
||||
...createContactUsDto,
|
||||
user,
|
||||
});
|
||||
await this.contactUsRepository.save(contactUs);
|
||||
|
||||
@@ -36,21 +29,7 @@ export class ContactUsService {
|
||||
async getAllContactUs(queryDto: SearchContactUsQueryDto) {
|
||||
const { limit, skip } = PaginationUtils(queryDto);
|
||||
|
||||
const queryBuilder = this.contactUsRepository
|
||||
.createQueryBuilder("contactus")
|
||||
.leftJoinAndSelect("contactus.user", "user")
|
||||
.select([
|
||||
"contactus.id",
|
||||
"contactus.numericId",
|
||||
"contactus.title",
|
||||
"contactus.content",
|
||||
"contactus.isRead",
|
||||
"contactus.createdAt",
|
||||
"user.id",
|
||||
"user.email",
|
||||
"user.firstName",
|
||||
"user.lastName",
|
||||
]);
|
||||
const queryBuilder = this.contactUsRepository.createQueryBuilder("contactus");
|
||||
|
||||
if (queryDto.since) {
|
||||
queryBuilder.andWhere("contactus.createdAt >= :since", { since: queryDto.since });
|
||||
@@ -58,7 +37,7 @@ export class ContactUsService {
|
||||
|
||||
if (queryDto.q) {
|
||||
queryBuilder.andWhere(
|
||||
"(contactus.title LIKE :q OR contactus.content LIKE :q OR user.email LIKE :q OR user.firstName LIKE :q OR user.lastName LIKE :q)",
|
||||
"(contactus.title LIKE :q OR contactus.content LIKE :q OR contactus.email LIKE :q OR contactus.fullName LIKE :q)",
|
||||
{
|
||||
q: `%${queryDto.q}%`,
|
||||
},
|
||||
@@ -77,7 +56,9 @@ export class ContactUsService {
|
||||
//****************************** */
|
||||
|
||||
async getOneContactUs(id: string) {
|
||||
const contactUs = await this.contactUsRepository.getOneContactUs(id);
|
||||
const contactUs = await this.contactUsRepository.findOneBy({
|
||||
id,
|
||||
});
|
||||
|
||||
if (!contactUs) throw new BadRequestException(ContactUsMessage.NOT_FOUND);
|
||||
|
||||
|
||||
@@ -9,27 +9,4 @@ export class ContactUsRepository extends Repository<ContactUs> {
|
||||
constructor(@InjectRepository(ContactUs) contactUsRepository: Repository<ContactUs>) {
|
||||
super(contactUsRepository.target, contactUsRepository.manager, contactUsRepository.queryRunner);
|
||||
}
|
||||
|
||||
async getOneContactUs(id: string) {
|
||||
return await this.findOne({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
relations: ["user"],
|
||||
select: {
|
||||
id: true,
|
||||
numericId: true,
|
||||
title: true,
|
||||
content: true,
|
||||
isRead: true,
|
||||
createdAt: true,
|
||||
user: {
|
||||
id: true,
|
||||
email: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Column, Entity } from "typeorm";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
|
||||
@Entity()
|
||||
export class Notification extends BaseEntity {
|
||||
@Column({ type: "" })
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import { Role } from "./role.entity";
|
||||
import { UserGroup } from "./user-group.entity";
|
||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||
import { UserAnnouncement } from "../../announcements/entities/user-announcement.entity";
|
||||
import { ContactUs } from "../../contact-us/entities/contact-us.entity";
|
||||
import { Criticism } from "../../criticisms/entities/criticism.entity";
|
||||
import { DanakService } from "../../danak-services/entities/danak-service.entity";
|
||||
import { UserSetting } from "../../settings/entities/user-setting.entity";
|
||||
@@ -54,9 +53,6 @@ export class User extends BaseEntity {
|
||||
@OneToMany(() => Criticism, (criticism) => criticism.user)
|
||||
criticisms: Criticism[];
|
||||
|
||||
@OneToMany(() => ContactUs, (contactUs) => contactUs.user)
|
||||
contactUs: ContactUs[];
|
||||
|
||||
@ManyToMany(() => DanakService, (danakService) => danakService.users)
|
||||
@JoinTable()
|
||||
danakServices: DanakService[];
|
||||
|
||||
Reference in New Issue
Block a user