zoukankan      html  css  js  c++  java
  • CodingSouls团队项目冲刺(10)-个人概况

    团队冲刺第十天:

      讨论区后端开发:后端讨论区,将评论与回复分开实现。

     1 import * as TypeORM from "typeorm";
     2 import Model from "./common";
     3 
     4 import User from "./user";
     5 import Problem from "./problem";
     6 import ArticleComment from "./article-comment";
     7 
     8 declare var syzoj: any;
     9 
    10 @TypeORM.Entity()
    11 export default class Article extends Model {
    12   static cache = false;
    13 
    14   @TypeORM.PrimaryGeneratedColumn()
    15   id: number;
    16 
    17   @TypeORM.Column({ nullable: true, type: "varchar", length: 80 })
    18   title: string;
    19 
    20   @TypeORM.Column({ nullable: true, type: "mediumtext" })
    21   content: string;
    22 
    23   @TypeORM.Index()
    24   @TypeORM.Column({ nullable: true, type: "integer" })
    25   user_id: number;
    26 
    27   @TypeORM.Index()
    28   @TypeORM.Column({ nullable: true, type: "integer" })
    29   problem_id: number;
    30 
    31   @TypeORM.Column({ nullable: true, type: "integer" })
    32   public_time: number;
    33 
    34   @TypeORM.Column({ nullable: true, type: "integer" })
    35   update_time: number;
    36 
    37   @TypeORM.Index()
    38   @TypeORM.Column({ nullable: true, type: "integer" })
    39   sort_time: number;
    40 
    41   @TypeORM.Column({ default: 0, type: "integer" })
    42   comments_num: number;
    43 
    44   @TypeORM.Column({ default: true, type: "boolean" })
    45   allow_comment: boolean;
    46 
    47   @TypeORM.Index()
    48   @TypeORM.Column({ nullable: true, type: "boolean" })
    49   is_notice: boolean;
    50 
    51   user?: User;
    52   problem?: Problem;
    53 
    54   async loadRelationships() {
    55     this.user = await User.findById(this.user_id);
    56   }
    57 
    58   async isAllowedEditBy(user) {
    59     return user && (user.is_admin || this.user_id === user.id);
    60   }
    61 
    62   async isAllowedCommentBy(user) {
    63     return user && (this.allow_comment || user.is_admin || this.user_id === user.id);
    64   }
    65 
    66   async resetReplyCountAndTime() {
    67     await syzoj.utils.lock(['Article::resetReplyCountAndTime', this.id], async () => {
    68       this.comments_num = await ArticleComment.count({ article_id: this.id });
    69       if (this.comments_num === 0) {
    70         this.sort_time = this.public_time;
    71       } else {
    72         this.sort_time = (await ArticleComment.findOne({
    73           where: { article_id: this.id },
    74           order: { public_time: "DESC" }
    75         })).public_time;
    76       }
    77       await this.save();
    78     });
    79   }
    80 };
    讨论
     1 import * as TypeORM from "typeorm";
     2 import Model from "./common";
     3 
     4 import User from "./user";
     5 import Article from "./article";
     6 
     7 @TypeORM.Entity()
     8 export default class ArticleComment extends Model {
     9   @TypeORM.PrimaryGeneratedColumn()
    10   id: number;
    11 
    12   @TypeORM.Column({ nullable: true, type: "text" })
    13   content: string;
    14 
    15   @TypeORM.Index()
    16   @TypeORM.Column({ nullable: true, type: "integer" })
    17   article_id: number;
    18 
    19   @TypeORM.Index()
    20   @TypeORM.Column({ nullable: true, type: "integer" })
    21   user_id: number;
    22 
    23   @TypeORM.Column({ nullable: true, type: "integer" })
    24   public_time: number;
    25 
    26   user?: User;
    27   article?: Article;
    28 
    29   async loadRelationships() {
    30     this.user = await User.findById(this.user_id);
    31     this.article = await Article.findById(this.article_id);
    32   }
    33 
    34   async isAllowedEditBy(user) {
    35     await this.loadRelationships();
    36     return user && (user.is_admin || this.user_id === user.id || user.id === this.article.user_id);
    37   }
    38 };
    回复

     

  • 相关阅读:
    爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离
    网络爬虫基础练习
    Mysql 使用 select into outfile
    Mysql 使用CMD 登陆
    使用Clean() 去掉由函数自动生成的字符串中的双引号
    Get Resultset from Oracle Stored procedure
    获取引用某个主键的所有外键的表
    Entity Framework 丢失数据链接的绑定,在已绑好的EDMX中提示“Choose Your Data Connection”
    添加MySql Metat Database 信息
    at System.Data.EntityClient.EntityConnection.GetFactory(String providerString)
  • 原文地址:https://www.cnblogs.com/125418a/p/12781815.html
Copyright © 2011-2022 走看看