reading-note.schema.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import type {
  2. AuditRecordDTO,
  3. AuditRecordVO,
  4. } from '#/request/schema/audit-record';
  5. import { z } from '#/adapter/form';
  6. import { decodeList } from '#/request/schema';
  7. import { decodeAuditRecord } from '#/request/schema/audit-record';
  8. // ---------------------------------------------------------------------------
  9. // DTO
  10. // ---------------------------------------------------------------------------
  11. export interface ReadingNoteDTO extends AuditRecordDTO {
  12. id?: number | string;
  13. personalStudioId?: number | string;
  14. insightTitle?: string;
  15. bookName?: string;
  16. authorName?: string;
  17. noteDate?: string;
  18. noteContent?: string;
  19. agreeCount?: number;
  20. }
  21. export interface ReadingNoteQueryDTO {
  22. mixture?: string;
  23. personalStudioId?: number | string;
  24. pageNum?: number;
  25. pageSize?: number;
  26. }
  27. // ---------------------------------------------------------------------------
  28. // VO
  29. // ---------------------------------------------------------------------------
  30. export interface ReadingNoteVO extends AuditRecordVO {
  31. id?: string;
  32. workroomId: string;
  33. title: string;
  34. bookName: string;
  35. author: string;
  36. noteDate: string;
  37. content: string;
  38. likeCount?: number;
  39. }
  40. export type ReadingNoteSubmitVO = ReadingNoteVO;
  41. export interface ReadingNoteQueryVO {
  42. keyword?: string;
  43. workroomId?: string;
  44. }
  45. // ---------------------------------------------------------------------------
  46. // Schema
  47. // ---------------------------------------------------------------------------
  48. export const ReadingNoteVOSchema = z.object({
  49. id: z.string().optional(),
  50. workroomId: z.string().min(1, '工作室不能为空'),
  51. title: z.string().min(1, '请输入心得标题'),
  52. bookName: z.string().min(1, '请输入书名'),
  53. author: z.string().min(1, '请输入心得作者'),
  54. noteDate: z.string().min(1, '请选择日期'),
  55. content: z.string().min(1, '请输入心得'),
  56. });
  57. // ---------------------------------------------------------------------------
  58. // 编解码
  59. // ---------------------------------------------------------------------------
  60. export function decodeReadingNote(dto: ReadingNoteDTO): ReadingNoteVO {
  61. return {
  62. ...decodeAuditRecord(dto),
  63. id: dto.id?.toString(),
  64. workroomId: dto.personalStudioId?.toString() ?? '',
  65. title: dto.insightTitle ?? '',
  66. bookName: dto.bookName ?? '',
  67. author: dto.authorName ?? '',
  68. noteDate: dto.noteDate ?? '',
  69. content: dto.noteContent ?? '',
  70. likeCount: dto.agreeCount ?? 0,
  71. };
  72. }
  73. export function encodeReadingNoteQuery(
  74. query: Partial<ReadingNoteQueryVO>,
  75. ): ReadingNoteQueryDTO {
  76. return {
  77. mixture: query.keyword,
  78. personalStudioId: query.workroomId,
  79. };
  80. }
  81. export function encodeReadingNote(vo: ReadingNoteSubmitVO): ReadingNoteDTO {
  82. return {
  83. id: vo.id,
  84. personalStudioId: vo.workroomId,
  85. insightTitle: vo.title,
  86. bookName: vo.bookName,
  87. authorName: vo.author,
  88. noteDate: vo.noteDate,
  89. noteContent: vo.content,
  90. };
  91. }
  92. export function decodeReadingNoteList(dto: ReadingNoteDTO[]) {
  93. return decodeList(dto, decodeReadingNote);
  94. }