* 验证评论数据 * @param comment 评论数据 * @param path 路径(用于错误信息) * @returns 错误列表
(comment: unknown, path: string)
| 134 | * @returns 错误列表 |
| 135 | */ |
| 136 | static validateComment(comment: unknown, path: string): string[] { |
| 137 | const errors: string[] = []; |
| 138 | |
| 139 | if (!this.isRecord(comment)) { |
| 140 | errors.push(`${path}: 评论数据必须是对象`); |
| 141 | return errors; |
| 142 | } |
| 143 | |
| 144 | if (!comment.id || typeof comment.id !== 'string') { |
| 145 | errors.push(`${path}: 缺少有效的id字段`); |
| 146 | } |
| 147 | |
| 148 | if (!comment.content || typeof comment.content !== 'string') { |
| 149 | errors.push(`${path}: 缺少有效的content字段`); |
| 150 | } |
| 151 | |
| 152 | if (typeof comment.created !== 'number') { |
| 153 | errors.push(`${path}: created必须是数字`); |
| 154 | } |
| 155 | |
| 156 | if (typeof comment.updated !== 'number') { |
| 157 | errors.push(`${path}: updated必须是数字`); |
| 158 | } |
| 159 | |
| 160 | return errors; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * 验证闪卡数据结构 |
no test coverage detected