Add reports for post
- Add reports field on posts - add reportPost mutation - add getReports query - add createReportReason mutation - Add Report type and model - Add ReportReason type and model Closes #62pull/4/head
parent
26ecb3b0cf
commit
4014f77a4c
@ -0,0 +1,10 @@
|
|||||||
|
import {BaseError} from "./BaseError";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error that is thrown when a user tries to report the same post twice
|
||||||
|
*/
|
||||||
|
export class ReportAlreadyExistsError extends BaseError {
|
||||||
|
constructor() {
|
||||||
|
super("You've already reported this post for that reason.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import {BaseError} from "./BaseError";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error that is thrown when one tries to create a request with a name that already exists.
|
||||||
|
*/
|
||||||
|
export class ReportReasonNameAlreadyExistsError extends BaseError {
|
||||||
|
constructor(name: string) {
|
||||||
|
super(`A report reason with the name '${name}' already exists!`);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
import * as httpStatus from "http-status";
|
||||||
|
import {BaseError} from "./BaseError";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An error that is thrown when a report reason could not be found
|
||||||
|
*/
|
||||||
|
export class ReportReasonNotFoundError extends BaseError {
|
||||||
|
|
||||||
|
public readonly statusCode = httpStatus.NOT_FOUND;
|
||||||
|
|
||||||
|
constructor(reasonId: number) {
|
||||||
|
super(`A reason with the id '${reasonId}' could not be found`);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
import {BelongsTo, Column, ForeignKey, Model, NotNull, Table} from "sequelize-typescript";
|
||||||
|
import {Post, User} from "./index";
|
||||||
|
import {ReportReason} from "./ReportReason";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A report on a post
|
||||||
|
*/
|
||||||
|
@Table({underscored: true})
|
||||||
|
export class Report extends Model<Report> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the post that was reported
|
||||||
|
*/
|
||||||
|
@ForeignKey(() => Post)
|
||||||
|
@NotNull
|
||||||
|
@Column({allowNull: false, onDelete: "cascade", unique: "compositeIndex"})
|
||||||
|
public postId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The id of the user who issued the report
|
||||||
|
*/
|
||||||
|
@ForeignKey(() => User)
|
||||||
|
@NotNull
|
||||||
|
@Column({allowNull: false, onDelete: "cascade", unique: "compositeIndex"})
|
||||||
|
public userId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reason for which the post was reported
|
||||||
|
*/
|
||||||
|
@ForeignKey(() => ReportReason)
|
||||||
|
@NotNull
|
||||||
|
@Column({allowNull: false, onDelete: "cascade", unique: "compositeIndex"})
|
||||||
|
public reasonId: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user that reported the post
|
||||||
|
*/
|
||||||
|
@BelongsTo(() => User, "userId")
|
||||||
|
public rUser: User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The post that was reported
|
||||||
|
*/
|
||||||
|
@BelongsTo(() => Post, "postId")
|
||||||
|
public rPost: Post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The reason why the post was reported
|
||||||
|
*/
|
||||||
|
@BelongsTo(() => ReportReason, "reasonId")
|
||||||
|
public rReason: ReportReason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the user that reported the post
|
||||||
|
*/
|
||||||
|
public async user(): Promise<User> {
|
||||||
|
return await this.$get("rUser") as User;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the post that was reported
|
||||||
|
*/
|
||||||
|
public async post(): Promise<Post> {
|
||||||
|
return await this.$get("rPost") as Post;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the reason why the post was reported
|
||||||
|
*/
|
||||||
|
public async reason(): Promise<ReportReason> {
|
||||||
|
return await this.$get("rReason") as ReportReason;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
import * as sqz from "sequelize";
|
||||||
|
import {Column, Model, NotNull, Table, Unique} from "sequelize-typescript";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reason for why a post was reported
|
||||||
|
*/
|
||||||
|
@Table({underscored: true})
|
||||||
|
export class ReportReason extends Model<ReportReason> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the reason (short and precise)
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@Unique
|
||||||
|
@Column({unique: true, allowNull: false, type: sqz.STRING(64)})
|
||||||
|
public name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A longer descripion of the reason
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
@Column({allowNull: false, type: sqz.STRING(512)})
|
||||||
|
public description: string;
|
||||||
|
}
|
Loading…
Reference in New Issue