-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(note): Add tools to GET /note/id and GET /note/resolve-hostname/…
…hostname (#248) * Add tools to GET /note/id * Add tools to GET note/resolve-hostname/:hostname * Remove only * Update src/domain/entities/note.ts Co-authored-by: Peter Savchenko <[email protected]> * Lint --------- Co-authored-by: Peter Savchenko <[email protected]>
- Loading branch information
1 parent
50c0330
commit 51ac441
Showing
9 changed files
with
168 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,20 @@ describe('Note API', () => { | |
accessRights: { | ||
canEdit: false, | ||
}, | ||
tools: [ | ||
{ | ||
name: 'header', | ||
source: { | ||
cdn: 'https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/header.umd.min.js', | ||
}, | ||
}, | ||
{ | ||
name: 'paragraph', | ||
source: { | ||
cdn: 'https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/paragraph.umd.min.js', | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
|
@@ -151,6 +165,20 @@ describe('Note API', () => { | |
'accessRights': { | ||
'canEdit': canEdit, | ||
}, | ||
tools: [ | ||
{ | ||
name: 'header', | ||
source: { | ||
cdn: 'https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/header.umd.min.js', | ||
}, | ||
}, | ||
{ | ||
name: 'paragraph', | ||
source: { | ||
cdn: 'https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/paragraph.umd.min.js', | ||
}, | ||
}, | ||
], | ||
}); | ||
} else { | ||
expect(response?.json()).toStrictEqual({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,29 @@ import type EditorTool from '@domain/entities/editorTools.ts'; | |
import type NoteVisit from '@domain/entities/noteVisit.js'; | ||
import { nanoid } from 'nanoid'; | ||
|
||
/** | ||
* Note content mock inserted if no content passed | ||
*/ | ||
const DEFAULT_NOTE_CONTENT = { | ||
blocks: [ | ||
{ | ||
id: 'mJDq8YbvqO', | ||
type: 'paragraph', | ||
data: { | ||
text: 'text', | ||
}, | ||
}, | ||
{ | ||
id: 'DeL0QehzGe', | ||
type: 'header', | ||
data: { | ||
text: 'fdgsfdgfdsg', | ||
level: 2, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
/** | ||
* default type for note mock creation attributes | ||
*/ | ||
|
@@ -109,11 +132,11 @@ export default class DatabaseHelpers { | |
* If publicId is not passed, it's value in database would be created via `createPublicId()` method | ||
*/ | ||
public async insertNote(note: NoteMockCreationAttributes): Promise<Note> { | ||
const content = note.content ?? '{}'; | ||
const content = note.content ?? DEFAULT_NOTE_CONTENT; | ||
const publicId = note.publicId ?? createPublicId(); | ||
|
||
const [results, _] = await this.orm.connection.query(`INSERT INTO public.notes ("content", "creator_id", "created_at", "updated_at", "public_id") | ||
VALUES ('${content}', ${note.creatorId}, CURRENT_DATE, CURRENT_DATE, '${publicId}') | ||
VALUES ('${JSON.stringify(content)}', ${note.creatorId}, CURRENT_DATE, CURRENT_DATE, '${publicId}') | ||
RETURNING "id", "content", "creator_id" AS "creatorId", "public_id" AS "publicId", "created_at" AS "createdAt", "updated_at" AS "updatedAt"`, | ||
{ | ||
type: QueryTypes.INSERT, | ||
|
@@ -265,8 +288,8 @@ export default class DatabaseHelpers { | |
/** | ||
* Truncates all tables and restarts all autoincrement sequences | ||
*/ | ||
public async truncateTables(): Promise<unknown> { | ||
return await this.orm.connection.query(`DO $$ | ||
public async truncateTables(): Promise<void> { | ||
await this.orm.connection.query(`DO $$ | ||
DECLARE | ||
-- table iterator | ||
tbl RECORD; | ||
|
@@ -292,5 +315,22 @@ export default class DatabaseHelpers { | |
EXECUTE format('ALTER sequence %s RESTART WITH 1', seq.sequence_name); | ||
END LOOP; | ||
END $$ LANGUAGE plpgsql;`); | ||
|
||
|
||
/** Insert default tools */ | ||
await this.orm.connection.query(` | ||
INSERT INTO public.editor_tools (name, title, export_name, source, is_default) | ||
VALUES ('header', 'Heading', 'Header', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/header.umd.min.js"}'::json, true); | ||
`); | ||
|
||
await this.orm.connection.query(` | ||
INSERT INTO public.editor_tools (name, title, export_name, source, is_default) | ||
VALUES ('paragraph', 'Paragraph', 'Paragraph', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/paragraph.umd.min.js"}'::json, true); | ||
`); | ||
|
||
await this.orm.connection.query(` | ||
INSERT INTO public.editor_tools (name, title, export_name, source, is_default) | ||
VALUES ('list', 'List', 'List', '{"cdn": "https://cdn.jsdelivr.net/npm/@editorjs/[email protected]/dist/list.umd.min.js"}'::json, true); | ||
`); | ||
} | ||
}; |