| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import type {
- AuditRecordDTO,
- AuditRecordVO,
- } from '#/request/schema/audit-record';
- import { z } from '#/adapter/form';
- import { decodeList } from '#/request/schema';
- import { decodeAuditRecord } from '#/request/schema/audit-record';
- // ---------------------------------------------------------------------------
- // DTO
- // ---------------------------------------------------------------------------
- export interface ReadingNoteDTO extends AuditRecordDTO {
- id?: number | string;
- personalStudioId?: number | string;
- insightTitle?: string;
- bookName?: string;
- authorName?: string;
- noteDate?: string;
- noteContent?: string;
- agreeCount?: number;
- }
- export interface ReadingNoteQueryDTO {
- mixture?: string;
- personalStudioId?: number | string;
- pageNum?: number;
- pageSize?: number;
- }
- // ---------------------------------------------------------------------------
- // VO
- // ---------------------------------------------------------------------------
- export interface ReadingNoteVO extends AuditRecordVO {
- id?: string;
- workroomId: string;
- title: string;
- bookName: string;
- author: string;
- noteDate: string;
- content: string;
- likeCount?: number;
- }
- export type ReadingNoteSubmitVO = ReadingNoteVO;
- export interface ReadingNoteQueryVO {
- keyword?: string;
- workroomId?: string;
- }
- // ---------------------------------------------------------------------------
- // Schema
- // ---------------------------------------------------------------------------
- export const ReadingNoteVOSchema = z.object({
- id: z.string().optional(),
- workroomId: z.string().min(1, '工作室不能为空'),
- title: z.string().min(1, '请输入心得标题'),
- bookName: z.string().min(1, '请输入书名'),
- author: z.string().min(1, '请输入心得作者'),
- noteDate: z.string().min(1, '请选择日期'),
- content: z.string().min(1, '请输入心得'),
- });
- // ---------------------------------------------------------------------------
- // 编解码
- // ---------------------------------------------------------------------------
- export function decodeReadingNote(dto: ReadingNoteDTO): ReadingNoteVO {
- return {
- ...decodeAuditRecord(dto),
- id: dto.id?.toString(),
- workroomId: dto.personalStudioId?.toString() ?? '',
- title: dto.insightTitle ?? '',
- bookName: dto.bookName ?? '',
- author: dto.authorName ?? '',
- noteDate: dto.noteDate ?? '',
- content: dto.noteContent ?? '',
- likeCount: dto.agreeCount ?? 0,
- };
- }
- export function encodeReadingNoteQuery(
- query: Partial<ReadingNoteQueryVO>,
- ): ReadingNoteQueryDTO {
- return {
- mixture: query.keyword,
- personalStudioId: query.workroomId,
- };
- }
- export function encodeReadingNote(vo: ReadingNoteSubmitVO): ReadingNoteDTO {
- return {
- id: vo.id,
- personalStudioId: vo.workroomId,
- insightTitle: vo.title,
- bookName: vo.bookName,
- authorName: vo.author,
- noteDate: vo.noteDate,
- noteContent: vo.content,
- };
- }
- export function decodeReadingNoteList(dto: ReadingNoteDTO[]) {
- return decodeList(dto, decodeReadingNote);
- }
|