-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheditorTools.ts
More file actions
75 lines (67 loc) · 2.24 KB
/
editorTools.ts
File metadata and controls
75 lines (67 loc) · 2.24 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type EditorToolsRepository from '@repository/editorTools.repository.js';
import type EditorTool from '@domain/entities/editorTools.js';
import type EditorToolsServiceSharedMethods from './shared/editorTools.js';
import type User from '@domain/entities/user.js';
import type { EditorToolCreationAttributes } from '@domain/entities/editorTools.js';
/**
* Editor tools service
*/
export default class EditorToolsService implements EditorToolsServiceSharedMethods {
/**
* User repository instance
*/
private readonly repository: EditorToolsRepository;
/**
* Editor tools service constructor
* @param repository - user repository instance
*/
constructor(repository: EditorToolsRepository) {
this.repository = repository;
}
/**
* @returns all available editor tools
*/
public async getTools(): Promise<EditorTool[] | null> {
return await this.repository.getTools();
}
/**
* Get bunch of editor tools by their ids
* @param editorToolIds - tool ids
*/
public async getToolsByIds(editorToolIds: EditorTool['id'][]): Promise<EditorTool[]> {
return await this.repository.getToolsByIds(editorToolIds);
}
/**
* Get tool by it's identifier
* @param editorToolId - unique tool identifier
*/
public async getToolById(editorToolId: EditorTool['id']): Promise<EditorTool | null> {
return await this.repository.getToolById(editorToolId);
}
/**
* Return tools that are available at Editor by default
*/
public async getDefaultTools(): Promise<EditorTool[]> {
return await this.repository.getDefaultTools();
}
/**
* Adding custom editor tool
* @param editorTool - all data about the editor plugin
* @param userId - user identifier
* @returns editor tool data
*/
public async addTool(editorTool: Omit<EditorToolCreationAttributes, 'userId'>, userId: User['id']): Promise<EditorTool> {
return await this.repository.addTool({
userId,
...editorTool,
});
}
/**
* Update tool cover s3 key
* @param editorToolId - tool identifier
* @param cover - new cover key
*/
public async updateToolCover(editorToolId: EditorTool['id'], cover: EditorTool['cover']): Promise<void> {
return await this.repository.updateToolCover(editorToolId, cover);
}
}