Skip to content

Commit

Permalink
fixed notebooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgul committed May 22, 2024
1 parent 4a94dbb commit 7e420bf
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/client/components/notes/addEditModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
//------------------------------------------------------------------------------------------------------------------
const innerPage = ref<Omit<NotebookPage, 'notebookID'>>({
id: '',
id: null,
title: '',
content: ''
});
Expand All @@ -120,13 +120,13 @@
{
if(page)
{
innerPage.value.id = page?.id ?? '';
innerPage.value.id = page?.id ?? null;
innerPage.value.title = page?.title ?? '';
innerPage.value.content = page?.content ?? '';
}
else
{
innerPage.value.id = '';
innerPage.value.id = null;
innerPage.value.title = '';
innerPage.value.content = '';
}
Expand Down
9 changes: 9 additions & 0 deletions src/client/lib/resource-access/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@ class NotesResourceAccess

async addPage(noteID : string, page : NotebookPage) : Promise<NotebookPage>
{
// If we're adding a page, the id is always undefined.
page.id = undefined;

// Also, we always need to set the notebookID.
page.notebookID = noteID;

const { data } = await $http.post(`/api/notebook/${ noteID }/pages`, page);
return data;
}

async updatePage(noteID : string, page : NotebookPage) : Promise<NotebookPage>
{
// We always need to set the notebookID.
page.notebookID = noteID;

const { data } = await $http.patch(`/api/notebook/${ noteID }/pages/${ page.id }`, page);
return data;
}
Expand Down
10 changes: 5 additions & 5 deletions src/server/resource-access/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export async function get(notebookID : string) : Promise<Notebook>
const db = await getDB();
const pages = await db('note_page as np')
.select(
'page_id as id',
'n.note_id as notebookID',
'page_id',
'n.note_id',
'content',
'title'
)
Expand Down Expand Up @@ -76,13 +76,13 @@ export async function getPage(pageID : string | number) : Promise<NotebookPage>
const db = await getDB();
const pages = await db('note_page as np')
.select(
'page_id as id',
'n.note_id as notebookID',
'page_id',
'n.note_id',
'content',
'title'
)
.join('note as n', 'n.note_id', '=', 'np.note_id')
.where({ id: pageID });
.where({ page_id: pageID });

if(pages.length > 1)
{
Expand Down
6 changes: 3 additions & 3 deletions src/server/resource-access/transforms/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Notebook, NotebookPage } from '../../../common/interfaces/models/notebo

export interface NotePageDBRecord
{
page_id : string;
page_id : number;
note_id : string;
title : string;
content : string;
Expand All @@ -25,7 +25,7 @@ export interface NotebookDBRecord
export function pageFromDB(record : NotePageDBRecord) : NotebookPage
{
return {
id: record.page_id,
id: `${ record.page_id }`,
notebookID: record.note_id,
title: record.title,
content: record.content
Expand All @@ -43,7 +43,7 @@ export function fromDB(record : NotebookDBRecord) : Notebook
export function pageToDB(page : NotebookPage) : NotePageDBRecord
{
return {
page_id: page.id,
page_id: parseInt(page.id),
note_id: page.notebookID,
title: page.title,
content: page.content
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ router.patch(
ensureAuthenticated,
async(req, resp) =>
{
// Update the note
// Update the note
const newPage = await noteMan.updatePage(req.params.pageID, req.body);
resp.json(newPage);
}
Expand Down

0 comments on commit 7e420bf

Please sign in to comment.