mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-09 03:38:17 +00:00
add dispute functionality for contract duty and implement collection dates
This commit is contained in:
@@ -104,13 +104,66 @@ export class FilesService {
|
||||
});
|
||||
}
|
||||
|
||||
/** Replace existing file row for the same resource + code (e.g. contract PDF). */
|
||||
async upsertByCode(input: CreateFileInput): Promise<FileRecord> {
|
||||
/**
|
||||
* Replace the file stored under a resource + code (e.g. contract PDF). The
|
||||
* previous version is retired, not destroyed — pass `replacedBy` to record who
|
||||
* swapped it and why, which is what the version history shows.
|
||||
*/
|
||||
async upsertByCode(
|
||||
input: CreateFileInput,
|
||||
replacedBy?: { userId?: string | null; reason?: string | null },
|
||||
): Promise<FileRecord> {
|
||||
const { resourceId, resource, code } = input;
|
||||
await this.filesRepository.deleteByCode(resourceId, resource, code);
|
||||
await this.filesRepository.deleteByCode(
|
||||
resourceId,
|
||||
resource,
|
||||
code,
|
||||
replacedBy,
|
||||
);
|
||||
return this.upload(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every stored version of one document, newest first. `isCurrent` marks the
|
||||
* live row; the rest are superseded uploads kept for audit.
|
||||
*/
|
||||
async versionHistory(
|
||||
resourceId: string,
|
||||
resource: string,
|
||||
code: string,
|
||||
): Promise<
|
||||
Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
size: number;
|
||||
mimeType: string;
|
||||
uploadedAt: string;
|
||||
isCurrent: boolean;
|
||||
replacedAt: string | null;
|
||||
replacedByUserId: string | null;
|
||||
replaceReason: string | null;
|
||||
}>
|
||||
> {
|
||||
const rows = await this.filesRepository.findVersionHistory(
|
||||
resourceId,
|
||||
resource,
|
||||
code,
|
||||
);
|
||||
return rows.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
url: row.url,
|
||||
size: row.size,
|
||||
mimeType: row.mimeType,
|
||||
uploadedAt: row.createdAt.toISOString(),
|
||||
isCurrent: row.deletedAt == null,
|
||||
replacedAt: row.deletedAt ? row.deletedAt.toISOString() : null,
|
||||
replacedByUserId: row.replacedByUserId,
|
||||
replaceReason: row.replaceReason,
|
||||
}));
|
||||
}
|
||||
|
||||
async deleteByCode(
|
||||
resourceId: string,
|
||||
resource: string,
|
||||
|
||||
Reference in New Issue
Block a user