|
|
|
import * as TypeORM from "typeorm";
|
|
|
|
import Model from "./common";
|
|
|
|
import User from "./user";
|
|
|
|
import Article from "./article";
|
|
|
|
declare var syzoj: any;
|
|
|
|
|
|
|
|
@TypeORM.Entity()
|
|
|
|
export default class NewReply extends Model {
|
|
|
|
static cache = false;
|
|
|
|
|
|
|
|
@TypeORM.PrimaryGeneratedColumn()
|
|
|
|
id: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "mediumtext" })
|
|
|
|
content: string;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
article_id: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
from_user_id: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
to_user_id: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
parent_id: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "boolean", default: true })
|
|
|
|
is_show: boolean;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
public_time: number;
|
|
|
|
|
|
|
|
@TypeORM.Column({ nullable: true, type: "integer" })
|
|
|
|
update_time: number;
|
|
|
|
|
|
|
|
user?: User;
|
|
|
|
article?: Article;
|
|
|
|
|
|
|
|
async loadRelationships() {
|
|
|
|
this.user = await User.findById(this.from_user_id);
|
|
|
|
this.article = await Article.findById(this.article_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
async isAllowedEditBy(user) {
|
|
|
|
await this.loadRelationships();
|
|
|
|
return user && (user.is_admin || this.from_user_id === user.id || user.id === this.article.user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|