|
|
@@ -114,4 +114,31 @@ export class PalmOilService {
|
|
|
async getRecordByArchiveId(archiveId: string): Promise<History | null> {
|
|
|
return this.historyRepository.findOne({ where: { archive_id: archiveId } });
|
|
|
}
|
|
|
+
|
|
|
+ async deleteRecord(archiveId: string): Promise<{ deleted: boolean }> {
|
|
|
+ const record = await this.historyRepository.findOne({ where: { archive_id: archiveId } });
|
|
|
+ if (!record) return { deleted: false };
|
|
|
+
|
|
|
+ // Remove archived image from disk
|
|
|
+ if (record.image_path && fs.existsSync(record.image_path)) {
|
|
|
+ fs.unlinkSync(record.image_path);
|
|
|
+ }
|
|
|
+
|
|
|
+ await this.historyRepository.delete({ archive_id: archiveId });
|
|
|
+ return { deleted: true };
|
|
|
+ }
|
|
|
+
|
|
|
+ async clearAllHistory(): Promise<{ deleted: number }> {
|
|
|
+ const records = await this.historyRepository.find();
|
|
|
+
|
|
|
+ // Remove every archived image from disk
|
|
|
+ for (const record of records) {
|
|
|
+ if (record.image_path && fs.existsSync(record.image_path)) {
|
|
|
+ fs.unlinkSync(record.image_path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await this.historyRepository.clear();
|
|
|
+ return { deleted: records.length };
|
|
|
+ }
|
|
|
}
|