chore: annoucement module with user-group

This commit is contained in:
Matin
2025-01-26 10:57:20 +03:30
parent 6da4b5114c
commit c8c98be6ee
13 changed files with 239 additions and 5 deletions
@@ -0,0 +1,45 @@
import { ApiProperty } from "@nestjs/swagger";
import { ArrayMinSize, IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString, IsUUID, MinLength } from "class-validator";
export class CreateAnnouncementDto {
@IsNotEmpty({ message: "عنوان نمی‌تواند خالی باشد" })
@IsString({ message: "عنوان باید رشته باشد" })
@ApiProperty({
type: String,
description: "Title of the announcement",
example: "اطلاعیه جدید",
})
title: string;
@IsNotEmpty({ message: "متن اطلاعیه نمی‌تواند خالی باشد" })
@IsString({ message: "متن اطلاعیه باید رشته باشد" })
@MinLength(10, { message: "متن اطلاعیه باید حداقل ۱۰ کاراکتر باشد" })
@ApiProperty({
type: String,
description: "Content of the announcement",
example: "اطلاعیه جدید برای کاربران",
})
content: string;
@IsBoolean()
@ApiProperty({
type: Boolean,
description: "Is this announcement important?",
example: false,
})
isPublic: boolean;
@IsOptional()
@IsArray()
@ArrayMinSize(1, { message: "حداقل یک گروه باید انتخاب شود" })
@IsUUID("4", {
each: true,
message: "شناسه هر گروه باید یک UUID معتبر نسخه ۴ باشد",
})
@ApiProperty({
type: [String],
description: "Array of group ids",
example: ["f7b1b3b1-1b1b-4b1b-8b1b-1b1b1b1b1b1b"],
})
groupIds: string[];
}
@@ -0,0 +1,8 @@
import { Controller } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";
@ApiTags("Announcements")
@Controller("announcements")
export class AnnouncementController {
constructor() {}
}
@@ -0,0 +1,14 @@
import { Module } from "@nestjs/common";
import { TypeOrmModule } from "@nestjs/typeorm";
import { AnnouncementController } from "./announcement.controller";
import { AnnouncementService } from "./announcement.service";
import { Announcement } from "./entities/announcement.entity";
@Module({
imports: [TypeOrmModule.forFeature([Announcement])],
providers: [AnnouncementService],
controllers: [AnnouncementController],
exports: [TypeOrmModule],
})
export class AnnoucementsModule {}
@@ -0,0 +1,6 @@
import { Injectable } from "@nestjs/common";
@Injectable()
export class AnnouncementService {
constructor() {}
}
@@ -0,0 +1,33 @@
import { Column, Entity, Index, ManyToMany } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { UserGroup } from "../../users/entities/user-group.entity";
@Entity()
@Index(["isPublic", "createdAt"])
export class Announcement extends BaseEntity {
@Column({ type: "varchar", length: 100 })
title: string;
@Column({ type: "text" })
content: string;
@Column({ type: "timestamp", default: null, nullable: true })
publishAt: Date;
//TODO: Add service here
//TODO: Add customer here
@Column({ type: "boolean", default: false })
isImportant: boolean;
@ManyToMany(() => UserGroup, (group) => group.announcements)
targetGroups: UserGroup[];
@Column({ default: false })
isPublic: boolean;
isPublicAnnouncement(): boolean {
return this.isPublic;
}
}