core: allow free users to assign same 5 tags without limits

This commit is contained in:
Abdullah Atta
2022-10-12 15:38:35 +05:00
committed by Abdullah Atta
parent 74bcd1b27d
commit b5ab8e5d3e
2 changed files with 8 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ import { makeId } from "../utils/id";
import { deleteItems, hasItem } from "../utils/array";
import setManipulator from "../utils/set";
import { Mutex } from "async-mutex";
import { checkIsUserPremium, CHECK_IDS } from "../common";
export default class Tags extends Collection {
constructor(db, name, cached) {
@@ -50,6 +51,13 @@ export default class Tags extends Collection {
if (tag && !noteIds.length)
throw new Error("A tag with this id already exists.");
if (
!tag &&
this.all.length >= 5 &&
!(await checkIsUserPremium(CHECK_IDS.noteTag))
)
return;
tag = tag || {
title: tagId
};

View File

@@ -160,12 +160,6 @@ export default class Note {
}
async tag(tag) {
if (
this._db.tags.all.length >= 5 &&
!(await checkIsUserPremium(CHECK_IDS.noteTag))
)
return;
let tagItem = await this._db.tags.add(tag, this._note.id);
if (addItem(this._note.tags, tagItem.title))
await this._db.notes.add(this._note);