* 清理和标准化评论数据 * @param comment 原始评论数据 * @returns 清理后的评论数据
(comment: unknown)
| 303 | * @returns 清理后的评论数据 |
| 304 | */ |
| 305 | static sanitizeComment(comment: unknown): SanitizedComment { |
| 306 | const sanitized: SanitizedComment = {}; |
| 307 | |
| 308 | if (!this.isRecord(comment)) { |
| 309 | return sanitized; |
| 310 | } |
| 311 | |
| 312 | if (comment.id && typeof comment.id === 'string') { |
| 313 | sanitized.id = comment.id; |
| 314 | } |
| 315 | |
| 316 | if (comment.content && typeof comment.content === 'string') { |
| 317 | sanitized.content = comment.content; |
| 318 | } |
| 319 | |
| 320 | if (typeof comment.created === 'number') { |
| 321 | sanitized.created = comment.created; |
| 322 | } else if (typeof comment.createdAt === 'number') { |
| 323 | sanitized.created = comment.createdAt; |
| 324 | } |
| 325 | |
| 326 | if (typeof comment.updated === 'number') { |
| 327 | sanitized.updated = comment.updated; |
| 328 | } else if (typeof comment.updatedAt === 'number') { |
| 329 | sanitized.updated = comment.updatedAt; |
| 330 | } |
| 331 | |
| 332 | return sanitized; |
| 333 | } |
| 334 | } |
no test coverage detected