blob: 13e16e5686fc29d9d9db606bd1fc20cb56b9ee66 (
plain)
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
|
import AbstractConverter from './AbstractConverter';
import ObjectClone from '../Utility/ObjectClone';
export default class PasswordConverter extends AbstractConverter {
/**
* @param {BasicPasswordsClient} api
*/
constructor(api) {
super(api, 'password');
/** @type {CustomFieldConverter} **/
this._customFieldConverter = this._api.getInstance('converter.field');
this._hashService = /** @type {HashService} **/ this._api.getInstance('service.hash');
}
/**
* @param {Object} object
* @return {AbstractRevisionModel}
*/
fromObject(object) {
let clone = ObjectClone.clone(object);
if(typeof clone.customFields === 'string') {
clone.customFields = this._customFieldConverter.fromJSON(clone.customFields);
} else {
clone.customFields = this._customFieldConverter.fromArray([]);
}
if(clone.hasOwnProperty('created') && !(clone.created instanceof Date)) {
clone.created = new Date(clone.created * 1e3);
}
if(clone.hasOwnProperty('updated') && !(clone.updated instanceof Date)) {
clone.updated = new Date(clone.updated * 1e3);
}
if(clone.hasOwnProperty('edited') && !(clone.edited instanceof Date)) {
clone.edited = new Date(clone.edited * 1e3);
}
return this._api.getClass(`model.${this._type}`, clone, this._api);
}
/**
*
* @param {(Password|AbstractRevisionModel)} model
* @returns {Promise<void>}
*/
async toObject(model) {
let data = super.toObject(model);
data.customFields = this._customFieldConverter.toJSON(model.getCustomFields());
data.hash = await this._hashService.getHash(model.getPassword(), this._hashService.HASH_SHA_1);
return data;
}
}
|