mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
server(theme): update theme's install count immediately on install
This commit is contained in:
@@ -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: publicProcedure
|
||||
|
||||
@@ -16,7 +16,7 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user