-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from cuappdev/kidus/reportmodel
Start a report model
- Loading branch information
Showing
19 changed files
with
822 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Body, CurrentUser, JsonController, Get, Post, Delete, Params} from "routing-controllers"; | ||
import { UserModel } from "../../models/UserModel"; | ||
import { ReportService } from "../../services/ReportService"; | ||
import { ReportPostRequest, ReportProfileRequest, ReportMessageRequest } from "../../types/ApiRequests"; | ||
import { GetReportResponse, GetReportsResponse } from "../../types/ApiResponses"; | ||
import { ReportModel } from "../../models/ReportModel"; | ||
import { report } from "process"; | ||
import { UuidParam } from "../validators/GenericRequests"; | ||
|
||
@JsonController("report/") | ||
export class ReportController { | ||
private reportService: ReportService; | ||
|
||
constructor(reportService: ReportService) { | ||
this.reportService = reportService; | ||
} | ||
|
||
@Get("admin/all/") | ||
async getAllReports(@CurrentUser() user: UserModel): Promise<GetReportsResponse> { | ||
return { reports: await this.reportService.getAllReports(user) }; | ||
} | ||
|
||
@Get("admin/post/") | ||
async getAllPostReports(@CurrentUser() user: UserModel): Promise<GetReportsResponse> { | ||
return { reports: await this.reportService.getAllPostReports(user) }; | ||
} | ||
|
||
@Get("admin/profile/") | ||
async getAllProfileReports(@CurrentUser() user: UserModel): Promise<GetReportsResponse> { | ||
return { reports: await this.reportService.getAllProfileReports(user) }; | ||
} | ||
|
||
@Get("admin/message/") | ||
async getAllMessageReports(@CurrentUser() user: UserModel): Promise<GetReportsResponse> { | ||
return { reports: await this.reportService.getAllMessageReports(user) }; | ||
} | ||
|
||
@Get("id/:id/") | ||
async getReportById(@CurrentUser() user: UserModel, @Params() params: UuidParam): Promise<GetReportResponse> { | ||
return { report: await this.reportService.getReportById(user, params) }; | ||
} | ||
|
||
@Get("reporter/id/:id/") | ||
async getReportsByReporter(@CurrentUser() user: UserModel, @Params() params: UuidParam): Promise<GetReportsResponse> { | ||
return { reports: await this.reportService.getReportsByReporter(user, params) }; | ||
} | ||
|
||
@Post("post/") | ||
async reportPost(@Body() reportPostRequest: ReportPostRequest, @CurrentUser() user: UserModel): Promise<ReportModel> { | ||
return this.reportService.reportPost(user, reportPostRequest); | ||
} | ||
|
||
@Post("profile/") | ||
async reportProfile(@Body() reportProfileRequest: ReportProfileRequest, @CurrentUser() user: UserModel): Promise<ReportModel> { | ||
return this.reportService.reportProfile(user,reportProfileRequest); | ||
} | ||
|
||
@Post("message/") | ||
async reportMessage(@Body() reportMessageRequest: ReportMessageRequest, @CurrentUser() user: UserModel): Promise<ReportModel> { | ||
return this.reportService.reportMessage(user, reportMessageRequest); | ||
} | ||
|
||
@Post("resolve/reportId/:id/") | ||
async resolveReport(@CurrentUser() user: UserModel,@Params() params: UuidParam): Promise<ReportModel> { | ||
return this.reportService.resolveReport(user, params); | ||
} | ||
|
||
@Delete("delete/:id/") | ||
async deleteReport(@CurrentUser() user: UserModel, @Params() params: UuidParam): Promise<ReportModel> { | ||
return this.reportService.deleteReport(user, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class addreports1713308449994 implements MigrationInterface { | ||
name = 'addreports1713308449994' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`CREATE TABLE "Message" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "content" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "sender" uuid, "receiver" uuid, CONSTRAINT "PK_7dd6398f0d1dcaf73df342fa325" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`CREATE TABLE "Report" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "reason" character varying NOT NULL, "type" character varying NOT NULL, "resolved" boolean NOT NULL, "created" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "reporter_id" uuid, "reported_id" uuid, "post_id" uuid, "message_id" uuid, CONSTRAINT "PK_9dbb4c593be9832c28a5793e258" PRIMARY KEY ("id"))`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD CONSTRAINT "FK_e2dae4735204f29947d6c42a615" FOREIGN KEY ("sender") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD CONSTRAINT "FK_8cc2e2f4ee9cdf7e5d9c70c5809" FOREIGN KEY ("receiver") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_6c3af08f1d45614f3b2f7e1b407" FOREIGN KEY ("reporter_id") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_0dd9a57f65a4b09cdae63735b13" FOREIGN KEY ("reported_id") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_244bde34d749985aa27e551c110" FOREIGN KEY ("post_id") REFERENCES "Post"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c" FOREIGN KEY ("message_id") REFERENCES "Message"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c"`); | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_244bde34d749985aa27e551c110"`); | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_0dd9a57f65a4b09cdae63735b13"`); | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_6c3af08f1d45614f3b2f7e1b407"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP CONSTRAINT "FK_8cc2e2f4ee9cdf7e5d9c70c5809"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP CONSTRAINT "FK_e2dae4735204f29947d6c42a615"`); | ||
await queryRunner.query(`DROP TABLE "Report"`); | ||
await queryRunner.query(`DROP TABLE "Message"`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class UpdateMessageModel1713320015776 implements MigrationInterface { | ||
name = 'UpdateMessageModel1713320015776' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "Message" DROP CONSTRAINT "FK_e2dae4735204f29947d6c42a615"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP CONSTRAINT "FK_8cc2e2f4ee9cdf7e5d9c70c5809"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP COLUMN "timestamp"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP COLUMN "sender"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP COLUMN "receiver"`); | ||
await queryRunner.query(`ALTER TABLE "Message" DROP COLUMN "content"`); | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c"`); | ||
await queryRunner.query(`ALTER TABLE "Message" ALTER COLUMN "id" DROP DEFAULT`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c" FOREIGN KEY ("message_id") REFERENCES "Message"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "Report" DROP CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c"`); | ||
await queryRunner.query(`ALTER TABLE "Message" ALTER COLUMN "id" SET DEFAULT uuid_generate_v4()`); | ||
await queryRunner.query(`ALTER TABLE "Report" ADD CONSTRAINT "FK_b0ecf30cfa1f4908dec8d19547c" FOREIGN KEY ("message_id") REFERENCES "Message"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD "content" character varying NOT NULL`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD "receiver" uuid NOT NULL`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD "sender" uuid NOT NULL`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD CONSTRAINT "FK_8cc2e2f4ee9cdf7e5d9c70c5809" FOREIGN KEY ("receiver") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
await queryRunner.query(`ALTER TABLE "Message" ADD CONSTRAINT "FK_e2dae4735204f29947d6c42a615" FOREIGN KEY ("sender") REFERENCES "User"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
Column, | ||
CreateDateColumn, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
OneToMany, | ||
PrimaryGeneratedColumn, | ||
PrimaryColumn | ||
} from "typeorm"; | ||
import { Uuid } from "../types"; | ||
import { UserModel } from "./UserModel"; | ||
import { ReportModel } from "./ReportModel"; | ||
|
||
@Entity("Message") | ||
export class MessageModel { | ||
@PrimaryColumn("uuid") | ||
id: Uuid; | ||
|
||
@OneToMany(() => ReportModel, (report) => report.message) | ||
reports: ReportModel[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; | ||
import { Uuid } from "../types"; | ||
import { UserModel } from "./UserModel"; | ||
import { PostModel } from "./PostModel"; | ||
import { MessageModel } from "./MessageModel"; | ||
import { Report } from "../types"; | ||
|
||
@Entity("Report") | ||
export class ReportModel { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: Uuid; | ||
|
||
@ManyToOne(() => UserModel, (user) => user.reports) | ||
reporter: UserModel; | ||
|
||
@ManyToOne(() => UserModel, (user) => user.reportedBy) | ||
reported: UserModel; | ||
|
||
@ManyToOne(() => PostModel, (post) => post.reports, { nullable: true }) | ||
post?: PostModel; | ||
|
||
@ManyToOne(() => MessageModel, (message) => message.reports, { | ||
nullable: true, | ||
}) | ||
message?: MessageModel; | ||
|
||
@Column({nullable: false}) | ||
reason: string; | ||
|
||
@Column({nullable: false}) | ||
type: "post" | "profile" | "message"; | ||
|
||
@Column() | ||
resolved: boolean; | ||
|
||
@CreateDateColumn({ type: "timestamptz" }) | ||
created: Date; | ||
|
||
public getReportInfo(): Report { | ||
return { | ||
id: this.id, | ||
reporter: this.reporter, | ||
reported: this.reported, | ||
post: this.post, | ||
message: this.message, | ||
reason: this.reason, | ||
type: this.type, | ||
resolved: this.resolved, | ||
created: this.created, | ||
}; | ||
} | ||
} |
Oops, something went wrong.