forked from jobbykingz/Verinode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversionController.ts
More file actions
54 lines (46 loc) · 2.14 KB
/
versionController.ts
File metadata and controls
54 lines (46 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Request, Response } from 'express';
import { VersioningService } from '../services/versioningService';
import { AuditService } from '../services/auditService';
export class VersionController {
static async createVersion(req: Request, res: Response) {
try {
const { proofId } = req.params;
const { eventData, hash, author, message, branch, previousVersionId } = req.body;
const prevVersionId = previousVersionId ? parseInt(previousVersionId) : undefined;
const version = await VersioningService.createVersion(parseInt(proofId), { eventData, hash }, author, message, branch, prevVersionId);
await AuditService.logChange(parseInt(proofId), version.id, 'UPDATE', author, message);
res.status(201).json(version);
} catch (error: any) {
res.status(500).json({ error: error.message });
}
}
static async getHistory(req: Request, res: Response) {
try {
const { proofId } = req.params;
const history = await VersioningService.getHistory(parseInt(proofId));
res.json(history);
} catch (error: any) {
res.status(500).json({ error: error.message });
}
}
static async rollback(req: Request, res: Response) {
try {
const { proofId, version } = req.params;
const { author } = req.body;
const newVersion = await VersioningService.rollback(parseInt(proofId), parseInt(version), author);
await AuditService.logChange(parseInt(proofId), newVersion.id, 'ROLLBACK', author, `Rolled back to version ${version}`);
res.json(newVersion);
} catch (error: any) {
res.status(500).json({ error: error.message });
}
}
static async getAuditTrail(req: Request, res: Response) {
try {
const { proofId } = req.params;
const trail = await AuditService.getAuditTrail(parseInt(proofId));
res.json(trail);
} catch (error: any) {
res.status(500).json({ error: error.message });
}
}
}