From e19dcbd981d8f8e489041907c52586a50119f265 Mon Sep 17 00:00:00 2001 From: qridwan <404ridwan@gmail.com> Date: Sun, 29 Sep 2024 12:28:41 +0600 Subject: [PATCH] :bug: => fix notebook edit --- .DS_Store | Bin 6148 -> 6148 bytes .vscode/settings.json | 36 +++++++++++++++---------------- dist/index.js | 2 +- dist/index.js.map | 2 +- dist/notebook/domain/repo.js | 6 +++++- dist/notebook/domain/repo.js.map | 2 +- src/index.ts | 2 +- src/notebook/domain/repo.ts | 9 ++++---- 8 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.DS_Store b/.DS_Store index 4b2fd49b028b2f43def07644c5bfa7e5710909ad..54e5363d6bbe2199925a6347aa001ea5cc11d167 100644 GIT binary patch delta 74 zcmZoMXfc@J&nUbxU^g?P@Ma#CRgCOQJ@>Pjj0gGT4asU7T delta 56 zcmZoMXfc@J&nUDpU^g?P&}JT%RgCQAygTYHPdGYxFRLbuz4 { +app.get("/api/db-ping", (req, res) => { knex_1.default .select("*") .from("notes") diff --git a/dist/index.js.map b/dist/index.js.map index e22d28a..be2126f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,sDAA8B;AAC9B,+CAA4C;AAC5C,2DAAqC;AACrC,qEAA4C;AAC5C,sEAA8C;AAC9C,qEAA4C;AAC5C,yEAAsD;AACtD,yEAAqD;AACrD,sEAA8C;AAC9C,gDAAwB;AAExB,iBAAiB;AACjB,OAAO,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;AAE3B,oBAAoB;AACpB,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AAEtB,wBAAwB;AACxB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACxB,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,GAAE,CAAC,CAAC;AAEhB,0BAA0B;AAC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cAAc,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACnC,cAAM;SACH,MAAM,CAAC,GAAG,CAAC;SACX,IAAI,CAAC,OAAO,CAAC;SACb,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE;QACX,GAAG;aACA,MAAM,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,sCAAsC,IAAG,EAAE,aAAF,EAAE,uBAAF,EAAE,CAAE,MAAM,CAAA,CAAC,CAAC;IAC/D,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEnB,GAAG,CAAC,IAAI,CAAC,oDAAoD,GAAG,KAAK,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,gCAAgC;AAChC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,GAAG,EAAE;IACxC,OAAO,CAAC,GAAG,CAAC,0BAA0B,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/notebook/domain/repo.js b/dist/notebook/domain/repo.js index 0fe3b0f..6b2efb8 100644 --- a/dist/notebook/domain/repo.js +++ b/dist/notebook/domain/repo.js @@ -30,7 +30,11 @@ const mynotebooks = (user_id) => __awaiter(void 0, void 0, void 0, function* () */ const deletenotebook = (notebook_id) => __awaiter(void 0, void 0, void 0, function* () { const res = yield knex_1.default.raw("delete from notebooks where id = ?", notebook_id); - return res[0]; + //delete all notes related to this notebook + yield knex_1.default.raw("delete from notes where notebook_id = ?", notebook_id); + //delete all trash related to this notebook + yield knex_1.default.raw("delete from trash where notebook_id = ?", notebook_id); + return { message: "notebook deleted", res: res[0] }; }); /** * @description This function adds an user to the database diff --git a/dist/notebook/domain/repo.js.map b/dist/notebook/domain/repo.js.map index 7375c5d..a763601 100644 --- a/dist/notebook/domain/repo.js.map +++ b/dist/notebook/domain/repo.js.map @@ -1 +1 @@ -{"version":3,"file":"repo.js","sourceRoot":"","sources":["../../../src/notebook/domain/repo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAAyC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAO,OAAe,EAAE,EAAE;IAC5C,MAAM,GAAG,GAAG,MAAM,cAAM,CAAC,GAAG,CAC1B,qEAAqE,EACrE,OAAO,CACR,CAAC;IACF,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC,CAAA,CAAC;AACF;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAO,WAAmB,EAAE,EAAE;IACnD,MAAM,GAAG,GAAG,MAAM,cAAM,CAAC,GAAG,CAC1B,oCAAoC,EACpC,WAAW,CACZ,CAAC;IACF,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC,CAAA,CAAC;AAEF;;;;GAIG;AAEH,MAAM,MAAM,GAAG,CAAO,QAAsB,EAAE,EAAE;IAC9C,qEAAqE;IACrE,MAAM,gBAAgB,GAAG,MAAM,cAAM,CAAC,GAAG,CACvC,mEAAmE,EACnE,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAClC,CAAC;IACF,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QAClC,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;KAC5C;IAED,MAAM,cAAM,CAAC,GAAG,CACd,+DAA+D,EAC/D,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CACjD,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,cAAM,CAAC,GAAG,CAAC,2CAA2C,EAAE;QACzE,QAAQ,CAAC,OAAO;KACjB,CAAC,CAAC;IACH,OAAO,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC,CAAA,CAAC;AAEF,MAAM,IAAI,GAAG,CAAO,QAAsB,EAAE,EAAE;IAC5C,MAAM,UAAU,GAAG,QAAQ,CAAC,EAAE,CAAC;IAE/B,oDAAoD;IACpD,MAAM,gBAAgB,GAAG,MAAM,cAAM,CAAC,GAAG,CACvC,iDAAiD,EACjD,UAAU,CACX,CAAC;IAEF,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IAED,yCAAyC;IACzC,MAAM,cAAM,CAAC,GAAG,CAAC,0DAA0D,EAAE;QAC3E,QAAQ,CAAC,IAAI;QACb,QAAQ,CAAC,OAAO;QAChB,UAAU;KACX,CAAC,CAAC;IAEH,yCAAyC;IACzC,MAAM,eAAe,GAAG,MAAM,cAAM,CAAC,GAAG,CACtC,sCAAsC,EACtC,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAA,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAChC,WAAW;IACX,MAAM;IACN,IAAI;IACJ,cAAc;CACf,CAAC"} \ No newline at end of file +{"version":3,"file":"repo.js","sourceRoot":"","sources":["../../../src/notebook/domain/repo.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAAyC;AAEzC;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAO,OAAe,EAAE,EAAE;IAC5C,MAAM,GAAG,GAAG,MAAM,cAAM,CAAC,GAAG,CAC1B,qEAAqE,EACrE,OAAO,CACR,CAAC;IACF,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;AAChB,CAAC,CAAA,CAAC;AACF;;;;GAIG;AACH,MAAM,cAAc,GAAG,CAAO,WAAmB,EAAE,EAAE;IACnD,MAAM,GAAG,GAAG,MAAM,cAAM,CAA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,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACpC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;KACvC;IAED,yCAAyC;IACzC,MAAM,cAAM,CAAC,GAAG,CAAC,0DAA0D,EAAE;QAC3E,QAAQ,CAAC,IAAI;QACb,QAAQ,CAAC,OAAO;QAChB,UAAU;KACX,CAAC,CAAC;IAEH,yCAAyC;IACzC,MAAM,eAAe,GAAG,MAAM,cAAM,CAAC,GAAG,CACtC,sCAAsC,EACtC,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC,CAAA,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAChC,WAAW;IACX,MAAM;IACN,IAAI;IACJ,cAAc;CACf,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 0f3eb06..c7bc642 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ app.use("/api/tags/", Middlewares.validateJWT, tags); //Tags app.use("/api/category/", Middlewares.validateJWT, categories); //Categories app.use("/api/notebooks/", Middlewares.validateJWT, notebooks); //Notebooks / Folder app.use("/api/trash/", Middlewares.validateJWT, trash); //Trash box -app.get("/db-ping", (req, res) => { +app.get("/api/db-ping", (req, res) => { client .select("*") .from("notes") diff --git a/src/notebook/domain/repo.ts b/src/notebook/domain/repo.ts index 73ee94b..e0c2e84 100644 --- a/src/notebook/domain/repo.ts +++ b/src/notebook/domain/repo.ts @@ -70,11 +70,10 @@ const edit = async (notebook: notebookType) => { } // Update the notebook with the new data. - await client.raw("update notebooks set name = ?, user_id = ? where id = ?", [ - notebook.name, - notebook.user_id, - notebookId, - ]); + await client.raw( + "update notebooks set name = ?, user_id = ?, icon = ? where id = ?", + [notebook.name, notebook.user_id, notebook.icon, notebookId] + ); // Fetch and return the updated notebook. const updatednotebook = await client.raw(