2021-01-22 17:41:11 +00:00
|
|
|
import BaseModel from '../BaseModel';
|
|
|
|
|
import { MasterKeyEntity } from '../services/database/types';
|
2021-06-26 18:18:10 +01:00
|
|
|
import { masterKeyAll, masterKeyById, saveMasterKey } from '../services/synchronizer/syncTargetInfoUtils';
|
2021-01-22 17:41:11 +00:00
|
|
|
import BaseItem from './BaseItem';
|
2017-12-12 18:41:02 +00:00
|
|
|
|
2021-01-22 17:41:11 +00:00
|
|
|
export default class MasterKey extends BaseItem {
|
2017-12-12 18:41:02 +00:00
|
|
|
static tableName() {
|
|
|
|
|
return 'master_keys';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static modelType() {
|
|
|
|
|
return BaseModel.TYPE_MASTER_KEY;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-13 18:57:40 +00:00
|
|
|
static encryptionSupported() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 19:39:13 +00:00
|
|
|
static latest() {
|
2021-06-26 18:18:10 +01:00
|
|
|
throw new Error('Not implemented');
|
|
|
|
|
// return this.modelSelectOne('SELECT * FROM master_keys WHERE created_time >= (SELECT max(created_time) FROM master_keys)');
|
2017-12-14 19:39:13 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-22 17:41:11 +00:00
|
|
|
static allWithoutEncryptionMethod(masterKeys: MasterKeyEntity[], method: number) {
|
2020-05-21 09:14:33 +01:00
|
|
|
return masterKeys.filter(m => m.encryption_method !== method);
|
2020-03-13 17:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-26 18:18:10 +01:00
|
|
|
public static async load(id: string): Promise<MasterKeyEntity> {
|
|
|
|
|
return masterKeyById(id);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 17:25:27 +01:00
|
|
|
public static async allIds(): Promise<string[]> {
|
|
|
|
|
return masterKeyAll().map(k => k.id);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 18:18:10 +01:00
|
|
|
public static async all(): Promise<MasterKeyEntity[]> {
|
|
|
|
|
return masterKeyAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async save(o: MasterKeyEntity): Promise<MasterKeyEntity> {
|
|
|
|
|
const newMasterKey = saveMasterKey(o);
|
|
|
|
|
|
2021-07-02 17:25:27 +01:00
|
|
|
// this.dispatch({
|
|
|
|
|
// type: 'MASTERKEY_UPDATE_ONE',
|
|
|
|
|
// item: newMasterKey,
|
|
|
|
|
// });
|
2021-06-26 18:18:10 +01:00
|
|
|
|
|
|
|
|
return newMasterKey;
|
2017-12-14 19:39:13 +00:00
|
|
|
}
|
2017-12-12 18:41:02 +00:00
|
|
|
}
|