Skip to content

Commit

Permalink
core: limit tags to 5 on basic plan
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Aug 16, 2024
1 parent 53a367b commit e7be9b3
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/core/src/collections/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ICollection } from "./collection";
import { SQLCollection } from "../database/sql-collection";
import { isFalse } from "../database";
import { sql } from "kysely";
import { CHECK_IDS, checkIsUserPremium } from "../common";

export class Tags implements ICollection {
name = "tags";
Expand Down Expand Up @@ -53,7 +54,6 @@ export class Tags implements ICollection {
async add(item: Partial<Tag> & { title: string }) {
item.title = Tags.sanitize(item.title);

const id = item.id || getId();
const oldTag = item.id ? await this.tag(item.id) : undefined;

if (oldTag && item.title === oldTag.title) return oldTag.id;
Expand All @@ -63,15 +63,22 @@ export class Tags implements ICollection {

if (oldTag) {
await this.collection.update([oldTag.id], item);
} else {
await this.collection.upsert({
id,
dateCreated: item.dateCreated || Date.now(),
dateModified: item.dateModified || Date.now(),
title: item.title,
type: "tag"
});
return oldTag.id;
}
if (
(await this.all.count()) >= 5 &&
!(await checkIsUserPremium(CHECK_IDS.noteTag))
)
return;

const id = item.id || getId();
await this.collection.upsert({
id,
dateCreated: item.dateCreated || Date.now(),
dateModified: item.dateModified || Date.now(),
title: item.title,
type: "tag"
});
return id;
}

Expand Down

0 comments on commit e7be9b3

Please sign in to comment.