-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCAttachedResource.model.ts
56 lines (52 loc) · 1.47 KB
/
RCAttachedResource.model.ts
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
55
56
import { Resource } from './resource.model';
import { epochDateTime } from './epoch';
/**
* A Resource Center's resource attached to other Objects.
*/
export class RCAttachedResource extends Resource {
/**
* The id of the resource.
*/
resourceId: string;
/**
* The folder of the resource.
*/
folderId: string;
/**
* The name of the resource. This can be changed when attaching to the entity.
*/
name: string;
/**
* The original name of the file.
*/
originalName: string;
/**
* The format of the resource. (e.g. 'jpg', 'pdf').
*/
format: string;
/**
* Timestamp of the latest version of the resource at the time it was attached to the entity.
*/
version: epochDateTime;
load(x: any): void {
super.load(x);
this.resourceId = this.clean(x.resourceId, String);
this.folderId = this.clean(x.folderId, String);
this.name = this.clean(x.name, String);
this.originalName = this.clean(x.originalName, String, this.name);
this.format = this.clean(x.format, String);
this.version = this.clean(x.version, a => new Date(a).getTime(), Date.now());
}
safeLoad(newData: any, safeData: any): void {
super.safeLoad(newData, safeData);
this.resourceId = safeData.resourceId;
this.folderId = safeData.folderId;
this.originalName = safeData.originalName;
this.format = safeData.format;
}
validate(): string[] {
const e = super.validate();
if (this.iE(this.name)) e.push('name');
return e;
}
}