implement phase 4
This commit is contained in:
parent
25c2ce53cd
commit
f4b1c3e14b
27 changed files with 6929 additions and 48 deletions
53
addin/src/models/versionRecord.ts
Normal file
53
addin/src/models/versionRecord.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Type ตรงกับ response ของ backend (`Models/VersionDtos.cs` — ASP.NET Core serialize camelCase)
|
||||
*/
|
||||
|
||||
/** response ของ POST /api/documents/{documentId}/versions และ POST /api/documents/generate */
|
||||
export interface UploadVersionResult {
|
||||
versionId: string;
|
||||
versionNumber: number;
|
||||
}
|
||||
|
||||
/** field เดียวใน snapshot ของ version (เอกสารที่ผูก template) */
|
||||
export interface FieldSnapshotEntry {
|
||||
value: string;
|
||||
missing: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* snapshot fields ต่อ version — backend เก็บ 2 รูปแบบ:
|
||||
* - เอกสารผูก template: `{ [fieldKey]: { value, missing } }`
|
||||
* - เอกสารไม่ผูก template (track เองจาก add-in): map ดิบ `{ [tag]: text }`
|
||||
* UI ต้อง handle ได้ทั้งคู่ (ใช้ readSnapshotField ช่วยอ่าน)
|
||||
*/
|
||||
export type FieldsSnapshot = Record<string, FieldSnapshotEntry> | Record<string, string>;
|
||||
|
||||
/** item ของ GET /api/documents/{documentId}/versions */
|
||||
export interface VersionRecord {
|
||||
versionId: string;
|
||||
versionNumber: number;
|
||||
/** ISO-8601 */
|
||||
createdAt: string;
|
||||
createdByUserId: string;
|
||||
/** SHA256 hex */
|
||||
contentHash: string;
|
||||
fields: FieldsSnapshot | null;
|
||||
}
|
||||
|
||||
/** อ่านค่า + สถานะ missing ของ field หนึ่งจาก snapshot ไม่ว่าจะเก็บรูปแบบไหน — ไม่มี field นี้คืน null */
|
||||
export function readSnapshotField(
|
||||
snapshot: FieldsSnapshot | null,
|
||||
key: string
|
||||
): FieldSnapshotEntry | null {
|
||||
if (!snapshot) {
|
||||
return null;
|
||||
}
|
||||
const raw = snapshot[key];
|
||||
if (raw === undefined) {
|
||||
return null;
|
||||
}
|
||||
if (typeof raw === "string") {
|
||||
return { value: raw, missing: false };
|
||||
}
|
||||
return { value: raw.value, missing: raw.missing };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue