chore: update referral logic

This commit is contained in:
mahyargdz
2025-04-15 15:50:31 +03:30
parent bd4d9dbf0d
commit fb8f16deb4
19 changed files with 234 additions and 262 deletions
@@ -1,26 +1,33 @@
import { ApiProperty } from "@nestjs/swagger";
import { IsEmail, IsNotEmpty, IsString } from "class-validator";
import { IsEmail, IsMobilePhone, IsNotEmpty, IsString, Length } from "class-validator";
import { ContactUsMessage } from "../../../common/enums/message.enum";
import { AuthMessage, 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: "متین جمشیدی" })
@ApiProperty({ description: "Full name of the person creating the contact request", example: "mahyar gdz" })
fullName: string;
@IsNotEmpty({ message: ContactUsMessage.FULLNAME_STRING })
@IsEmail()
@ApiProperty({ description: "email of person need to contact us", example: "matin@gmail.com" })
@IsNotEmpty({ message: AuthMessage.EMAIL_NOT_EMPTY })
@IsEmail({}, { message: AuthMessage.INVALID_EMAIL_FORMAT })
@ApiProperty({ description: "Email address", example: "ma@gmail.com" })
email: string;
@IsNotEmpty({ message: ContactUsMessage.TITLE_IS_REQUIRED })
@IsString({ message: ContactUsMessage.TITLE_STRING })
@ApiProperty({ description: "title of contact us", example: "عنوان پیام" })
title: string;
@IsNotEmpty({ message: AuthMessage.PHONE_NOT_EMPTY })
@IsMobilePhone("fa-IR", {}, { message: AuthMessage.INVALID_PHONE_FORMAT })
@Length(11, 11, { message: AuthMessage.PHONE_SHOULD_BE_11_DIGIT })
@ApiProperty({ description: "Phone number", default: "09922320740" })
phone: string;
@IsNotEmpty({ message: ContactUsMessage.BUSINESS_NAME_IS_REQUIRED })
@IsString({ message: ContactUsMessage.BUSINESS_NAME_STRING })
@Length(2, 100, { message: ContactUsMessage.BUSINESS_NAME_LENGTH })
@ApiProperty({ description: "Business name", example: "Tech Corp" })
businessName: string;
@IsNotEmpty({ message: ContactUsMessage.CONTENT_IS_REQUIRED })
@IsString({ message: ContactUsMessage.CONTENT_STRING })
@ApiProperty({ description: "content of contact us", example: "متن پیام" })
@ApiProperty({ description: "Content of the contact request", example: "متن پیام" })
content: string;
}
@@ -1,20 +1,23 @@
import { Body, Controller, Get, Param, Post, Query } from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { ApiOperation } from "@nestjs/swagger";
import { CreateContactUsDto } from "./DTO/create-contact-us.dto";
import { SearchContactUsQueryDto } from "./DTO/search-contact-us-query.dto";
import { ContactUsService } from "./providers/contact-us.service";
import { AdminRoute } from "../../common/decorators/admin.decorator";
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
import { PermissionsDec } from "../../common/decorators/permission.decorator";
import { SkipAuth } from "../../common/decorators/skip-auth.decorator";
import { ParamDto } from "../../common/DTO/param.dto";
import { PermissionEnum } from "../users/enums/permission.enum";
@Controller("contact-us")
@ApiTags("ContactUs")
@AuthGuards()
export class ContactUsController {
constructor(private readonly contactUsService: ContactUsService) {}
@ApiOperation({ summary: "Create a new contact us" })
@SkipAuth()
@Post()
createContactUs(@Body() createContactUsDto: CreateContactUsDto) {
return this.contactUsService.createContactUs(createContactUsDto);
@@ -22,9 +25,9 @@ export class ContactUsController {
//******************** */
@AuthGuards()
@PermissionsDec(PermissionEnum.CONTACTS_US)
@ApiOperation({ summary: "Get all contact us ===> login as admin" })
@AdminRoute()
@ApiOperation({ summary: "Get all contact us (admin route)" })
@Get()
getAllContactUs(@Query() queryDto: SearchContactUsQueryDto) {
return this.contactUsService.getAllContactUs(queryDto);
@@ -32,9 +35,9 @@ export class ContactUsController {
//******************** */
@AuthGuards()
@AdminRoute()
@PermissionsDec(PermissionEnum.CONTACTS_US)
@ApiOperation({ summary: "Get one contact us with id ===> login as admin" })
@ApiOperation({ summary: "Get one contact us with id (admin route)" })
@Get(":id")
getOneContactUs(@Param() paramDto: ParamDto) {
return this.contactUsService.getOneContactUs(paramDto.id);
@@ -7,18 +7,18 @@ export class ContactUs extends BaseEntity {
@Column({ type: "int", generated: "identity", insert: false })
numericId: number;
@Column({ type: "varchar", length: 150, nullable: false })
title: string;
@Column({ type: "varchar", length: 150 })
businessName: string;
@Column({ type: "varchar", length: 350 })
@Column({ type: "varchar", length: 250 })
fullName: string;
@Column({ type: "varchar", length: 11 })
phone: string;
@Column({ type: "varchar", length: 150 })
email: string;
@Column({ type: "text", nullable: false })
content: string;
@Column({ type: "boolean", default: false })
isRead: boolean;
}
@@ -13,9 +13,7 @@ export class ContactUsService {
//****************************** */
async createContactUs(createContactUsDto: CreateContactUsDto) {
const contactUs = this.contactUsRepository.create({
...createContactUsDto,
});
const contactUs = this.contactUsRepository.create({ ...createContactUsDto });
await this.contactUsRepository.save(contactUs);
return {
@@ -56,15 +54,10 @@ export class ContactUsService {
//****************************** */
async getOneContactUs(id: string) {
const contactUs = await this.contactUsRepository.findOneBy({
id,
});
const contactUs = await this.contactUsRepository.findOneBy({ id });
if (!contactUs) throw new BadRequestException(ContactUsMessage.NOT_FOUND);
contactUs.isRead = true;
await this.contactUsRepository.save(contactUs);
return { contactUs };
}
}