feat(data): add method that checks if data item has been saved

This commit is contained in:
Jovan Krunić
2019-02-12 14:06:54 +01:00
parent 7caaa18b7e
commit 017fc67765
2 changed files with 15 additions and 0 deletions

View File

@@ -220,4 +220,10 @@ describe('DataProvider', () => {
const result = await storageProvider.getAll();
expect(Array.from(result.keys())).toEqual(['some-uid']);
});
it('should properly check if a data item has already been saved', async () => {
expect(await dataProvider.isSaved(sampleThing.uid)).toBeFalsy();
await dataProvider.put(sampleThing);
expect(await dataProvider.isSaved(sampleThing.uid)).toBeTruthy();
});
});

View File

@@ -147,4 +147,13 @@ export class DataProvider {
async search(query: SCSearchQuery): Promise<SCSearchResponse> {
return (await this.client.search(query));
}
/**
* Provides information if something with an UID is saved as a data item
*
* @param uid Unique identifier of the saved data item
*/
async isSaved(uid: string): Promise<boolean> {
return this.storageProvider.has(this.getDataKey(uid));
}
}