1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

convert data models to jslib

This commit is contained in:
Kyle Spearrin
2018-01-08 15:12:09 -05:00
parent a78b8ec79c
commit 5d39030e05
22 changed files with 58 additions and 330 deletions

View File

@@ -1,12 +1,10 @@
import { CipherString } from '../models/domain/cipherString';
import { FolderData } from '../models/data/folderData';
import ApiService from './api.service';
import CryptoService from './crypto.service';
import UserService from './user.service';
import { Abstractions, Domain, Request, Response } from '@bitwarden/jslib';
import { Abstractions, Data, Domain, Request, Response } from '@bitwarden/jslib';
const Keys = {
foldersPrefix: 'folders_',
@@ -33,7 +31,7 @@ export default class FolderService {
async get(id: string): Promise<Domain.Folder> {
const userId = await this.userService.getUserId();
const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
Keys.foldersPrefix + userId);
if (folders == null || !folders.hasOwnProperty(id)) {
return null;
@@ -44,7 +42,7 @@ export default class FolderService {
async getAll(): Promise<Domain.Folder[]> {
const userId = await this.userService.getUserId();
const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
Keys.foldersPrefix + userId);
const response: Domain.Folder[] = [];
for (const id in folders) {
@@ -95,23 +93,23 @@ export default class FolderService {
}
const userId = await this.userService.getUserId();
const data = new FolderData(response, userId);
const data = new Data.Folder(response, userId);
await this.upsert(data);
}
async upsert(folder: FolderData | FolderData[]): Promise<any> {
async upsert(folder: Data.Folder | Data.Folder[]): Promise<any> {
const userId = await this.userService.getUserId();
let folders = await this.storageService.get<{ [id: string]: FolderData; }>(
let folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
Keys.foldersPrefix + userId);
if (folders == null) {
folders = {};
}
if (folder instanceof FolderData) {
const f = folder as FolderData;
if (folder instanceof Data.Folder) {
const f = folder as Data.Folder;
folders[f.id] = f;
} else {
(folder as FolderData[]).forEach((f) => {
(folder as Data.Folder[]).forEach((f) => {
folders[f.id] = f;
});
}
@@ -120,7 +118,7 @@ export default class FolderService {
this.decryptedFolderCache = null;
}
async replace(folders: { [id: string]: FolderData; }): Promise<any> {
async replace(folders: { [id: string]: Data.Folder; }): Promise<any> {
const userId = await this.userService.getUserId();
await this.storageService.save(Keys.foldersPrefix + userId, folders);
this.decryptedFolderCache = null;
@@ -133,7 +131,7 @@ export default class FolderService {
async delete(id: string | string[]): Promise<any> {
const userId = await this.userService.getUserId();
const folders = await this.storageService.get<{ [id: string]: FolderData; }>(
const folders = await this.storageService.get<{ [id: string]: Data.Folder; }>(
Keys.foldersPrefix + userId);
if (folders == null) {
return;