A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
server(theme): update theme's install count immediately on install
Abdullah Atta603b7da9e603
diff --git a/servers/themes/src/api.ts b/servers/themes/src/api.tsindex bd64fcc5b..3fb03f8ea 100644--- a/servers/themes/src/api.ts+++ b/servers/themes/src/api.ts@@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { z } from "zod";import { InstallsCounter } from "./constants";-import { findTheme, getThemes } from "./orama";+import { findTheme, getThemes, updateTotalInstalls } from "./orama";import { syncThemes } from "./sync";import { publicProcedure, router } from "./trpc";import { THEME_COMPATIBILITY_VERSION } from "@notesnook/theme";@@ -41,7 +41,12 @@ export const ThemesAPI = router({const theme = await findTheme(id, compatibilityVersion);if (!theme) return;- if (userId) await InstallsCounter.increment(theme.id, userId);+ if (userId) {+ updateTotalInstalls(+ theme,+ await InstallsCounter.increment(theme.id, userId)+ );+ }return theme;}),updateTheme: publicProcedurediff --git a/servers/themes/src/orama.ts b/servers/themes/src/orama.tsindex d07b35da3..8f970c97f 100644--- a/servers/themes/src/orama.ts+++ b/servers/themes/src/orama.ts@@ -16,7 +16,7 @@ GNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { Orama, SearchParams, create, search } from "@orama/orama";+import { Orama, SearchParams, create, search, update } from "@orama/orama";import { CompiledThemeDefinition, ThemeMetadata } from "./sync";import { ThemeQuerySchema } from "./schemas";@@ -54,6 +54,14 @@ export async function findTheme(return results.hits[0].document as CompiledThemeDefinition;}+export async function updateTotalInstalls(+ theme: CompiledThemeDefinition,+ totalInstalls: number+) {+ if (!ThemesDatabase) await initializeDatabase();+ await update(ThemesDatabase!, theme.id, { ...theme, totalInstalls });+}+export async function getThemes(query: (typeof ThemeQuerySchema)["_type"]) {if (!ThemesDatabase) await initializeDatabase();