-
Notifications
You must be signed in to change notification settings - Fork 1
/
editorTools.repository.ts
60 lines (50 loc) · 1.58 KB
/
editorTools.repository.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
57
58
59
60
import type EditorToolsStorage from '@repository/storage/editorTools.storage.js';
import type EditorTool from '@domain/entities/editorTools.js';
import type { EditorToolCreationAttributes } from '@domain/entities/editorTools.js';
/**
* Repository allows accessing data from business-logic (domain) level
*/
export default class EditorToolsRepository {
public storage: EditorToolsStorage;
/**
* @param storage - repository storage
*/
constructor(storage: EditorToolsStorage) {
this.storage = storage;
}
/**
* @param editorTool - all editor tool data
*/
public async addTool(editorTool: EditorToolCreationAttributes): Promise<EditorTool> {
const createdEditorTool = await this.storage.addTool(editorTool);
return createdEditorTool;
}
/**
* Get tool by it's identifier
* @param editorToolId - unique tool identifier
*/
public async getToolById(editorToolId: EditorTool['id']): Promise<EditorTool | null> {
return await this.storage.getToolById(editorToolId);
}
/**
* Get bunch of tools by their ids
* @param editorToolIds - unique tool ids
*/
public async getToolsByIds(editorToolIds: EditorTool['id'][]): Promise<EditorTool[]> {
const tools = await this.storage.getToolsByIds(editorToolIds);
return tools;
}
/**
* Get all default tools
*/
public async getDefaultTools(): Promise<EditorTool[]> {
return await this.storage.getDefaultTools();
}
/**
* Get all editor tools
*/
public async getTools(): Promise<EditorTool[]> {
const editorTools = await this.storage.getTools();
return editorTools;
}
}