-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathentry-service.ts
More file actions
54 lines (47 loc) · 2.15 KB
/
Copy pathentry-service.ts
File metadata and controls
54 lines (47 loc) · 2.15 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
import { logger } from '@papi/backend';
import type { IEntry, IEntryQuery, IEntryService, ISense, PartialEntry } from 'lexicon';
import { FwLiteApi } from '../utils/fw-lite-api';
import { ProjectManager } from '../utils/project-manager';
export class EntryService implements IEntryService {
private fwLiteApi: FwLiteApi;
constructor(baseUrl: string, lexiconCode?: string) {
this.fwLiteApi = new FwLiteApi(baseUrl, lexiconCode);
}
async getEntries(projectId: string, query: IEntryQuery): Promise<IEntry[] | undefined> {
const { semanticDomain, surfaceForm } = query;
if (!semanticDomain && !surfaceForm) {
logger.debug('No query!');
return;
}
const lexiconCode = await ProjectManager.getLexiconCode(projectId);
if (!lexiconCode) return;
logger.info(
`Fetching entries for '${surfaceForm}' (semantic domain '${semanticDomain}') in '${lexiconCode}'`,
);
return this.fwLiteApi.getEntries(surfaceForm, semanticDomain, lexiconCode);
}
async getEntry(projectId: string, id: string): Promise<IEntry | undefined> {
const lexiconCode = await ProjectManager.getLexiconCode(projectId);
if (!lexiconCode) return;
return this.fwLiteApi.getEntry(id, lexiconCode);
}
async getSense(projectId: string, id: string): Promise<ISense | undefined> {
const lexiconCode = await ProjectManager.getLexiconCode(projectId);
if (!lexiconCode) return;
return this.fwLiteApi.getSense(id, lexiconCode);
}
async addEntry(projectId: string, entry: PartialEntry): Promise<IEntry | undefined> {
const lexiconCode = await ProjectManager.getLexiconCode(projectId);
if (!lexiconCode) return;
return await this.fwLiteApi.postNewEntry(entry, lexiconCode);
}
// eslint-disable-next-line @typescript-eslint/class-methods-use-this, @typescript-eslint/no-unused-vars
updateEntry(_projectId: string, _reference: IEntry): Promise<void> {
throw new Error('Method not implemented.');
}
async deleteEntry(projectId: string, id: string): Promise<undefined> {
const lexiconCode = await ProjectManager.getLexiconCode(projectId);
if (!lexiconCode) return;
await this.fwLiteApi.deleteEntry(id, lexiconCode);
}
}